mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
some more 'global cursor' stuff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7999 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b0eb70e869
commit
2292145ba3
44
src/cursor.C
44
src/cursor.C
@ -22,12 +22,25 @@
|
||||
#include "insets/updatableinset.h"
|
||||
|
||||
using std::vector;
|
||||
using std::endl;
|
||||
|
||||
|
||||
DispatchResult Cursor::dispatch(FuncRequest const &)
|
||||
DispatchResult Cursor::dispatch(FuncRequest const & cmd)
|
||||
{
|
||||
for (int i = data_.size() - 1; i >= 0; --i) {
|
||||
lyxerr << "trying to dispatch to " << data_[i].text_ << std::endl;
|
||||
lyxerr << "trying to dispatch to inset" << data_[i].inset_ << endl;
|
||||
DispatchResult res = data_[i].inset_->dispatch(cmd);
|
||||
lyxerr << " result: " << result << endl;
|
||||
|
||||
if (res == DISPATCHED) {
|
||||
update();
|
||||
return DISPATCHED;
|
||||
}
|
||||
|
||||
if (res == DISPATCHED_NOUPDATE)
|
||||
return DISPATCHED;
|
||||
|
||||
lyxerr << "# unhandled result: " << res << endl;
|
||||
}
|
||||
return UNDISPATCHED;
|
||||
}
|
||||
@ -36,7 +49,7 @@ DispatchResult Cursor::dispatch(FuncRequest const &)
|
||||
void buildCursor(Cursor & cursor, BufferView & bv)
|
||||
{
|
||||
UpdatableInset * inset = bv.theLockingInset();
|
||||
lyxerr << "\nbuildCursor: " << inset << std::endl;
|
||||
lyxerr << "\nbuildCursor: " << inset << endl;
|
||||
if (!inset)
|
||||
return;
|
||||
|
||||
@ -54,26 +67,17 @@ void buildCursor(Cursor & cursor, BufferView & bv)
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
lyxerr << " tli not found! inset: " << inset << std::endl;
|
||||
lyxerr << " tli not found! inset: " << inset << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
vector<ParagraphList::iterator> pits;
|
||||
vector<ParagraphList const *> plists;
|
||||
vector<LyXText *> texts;
|
||||
/*
|
||||
pit.getPits(pits, plists, texts);
|
||||
|
||||
cursor.data_.resize(pits.size());
|
||||
for (size_t i = 0, n = pits.size(); i != n; ++i) {
|
||||
cursor.data_[i].text_ = texts[i];
|
||||
cursor.data_[i].pit_ = pits[i];
|
||||
//cursor.data_[i].pos_ = texts[i]->cursor.pos();
|
||||
cursor.data_[i].pos_ = 0;
|
||||
lyxerr << " text: " << cursor.data_[i].text_
|
||||
<< " pit: " << cursor.data_[i].pit_->id()
|
||||
pit.asCursor(cursor);
|
||||
for (size_t i = 0, n = cursor.data_.size(); i != n; ++i) {
|
||||
lyxerr << " inset: " << cursor.data_[i].inset_
|
||||
<< " idx: " << cursor.data_[i].idx_
|
||||
<< " text: " << cursor.data_[i].text_
|
||||
<< " par: " << cursor.data_[i].par_
|
||||
<< " pos: " << cursor.data_[i].pos_
|
||||
<< std::endl;
|
||||
<< endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
10
src/cursor.h
10
src/cursor.h
@ -12,7 +12,6 @@
|
||||
#ifndef CURSOR_H
|
||||
#define CURSOR_H
|
||||
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "textcursor.h"
|
||||
|
||||
#include "support/types.h"
|
||||
@ -20,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
class BufferView;
|
||||
class InsetOld;
|
||||
class DispatchResult;
|
||||
class FuncRequest;
|
||||
class LyXText;
|
||||
@ -32,12 +32,16 @@ class LyXText;
|
||||
class CursorItem : public TextCursor {
|
||||
public:
|
||||
///
|
||||
CursorItem() : text_(0) {}
|
||||
CursorItem() : inset_(0), text_(0), idx_(0), par_(0), pos_(0) {}
|
||||
public:
|
||||
///
|
||||
InsetOld * inset_;
|
||||
///
|
||||
LyXText * text_;
|
||||
///
|
||||
ParagraphList::iterator pit_;
|
||||
int idx_;
|
||||
///
|
||||
int par_;
|
||||
///
|
||||
int pos_;
|
||||
};
|
||||
|
@ -13,16 +13,13 @@
|
||||
|
||||
#include "iterators.h"
|
||||
#include "paragraph.h"
|
||||
#include "debug.h"
|
||||
#include "cursor.h"
|
||||
|
||||
#include "insets/inset.h"
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
// it's conceptionally a stack, but undo needs random access...
|
||||
//#include <stack>
|
||||
|
||||
using boost::next;
|
||||
using boost::optional;
|
||||
using std::vector;
|
||||
@ -178,6 +175,22 @@ int ParIterator::index() const
|
||||
}
|
||||
|
||||
|
||||
void ParIterator::asCursor(Cursor & cursor) const
|
||||
{
|
||||
cursor.data_.clear();
|
||||
for (size_t i = 1, n = size(); i < n; ++i) {
|
||||
ParPosition const & pos = pimpl_->positions[i - 1];
|
||||
CursorItem item;
|
||||
item.inset_ = (*pos.it)->inset;
|
||||
item.idx_ = (*pos.index);
|
||||
item.text_ = (*pos.it)->inset->getText(*pos.index);
|
||||
item.par_ = 0;
|
||||
item.pos_ = 0;
|
||||
cursor.data_.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Paragraph & ParIterator::operator*() const
|
||||
{
|
||||
return *pimpl_->positions.back().pit;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
class LyXText;
|
||||
class InsetOld;
|
||||
class Cursor;
|
||||
|
||||
class ParIterator {
|
||||
public:
|
||||
@ -51,6 +52,8 @@ public:
|
||||
///
|
||||
size_t size() const;
|
||||
///
|
||||
void asCursor(Cursor & cursor) const;
|
||||
///
|
||||
friend
|
||||
bool operator==(ParIterator const & iter1, ParIterator const & iter2);
|
||||
private:
|
||||
|
@ -447,11 +447,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
disable = true;
|
||||
}
|
||||
} else {
|
||||
static InsetTabular inset(*owner->buffer(), 1, 1);
|
||||
FuncStatus ret;
|
||||
|
||||
static InsetTabular inset(*buf, 1, 1);
|
||||
disable = true;
|
||||
ret = inset.getStatus(ev.argument);
|
||||
FuncStatus ret = inset.getStatus(ev.argument);
|
||||
if (ret.onoff(true) || ret.onoff(false))
|
||||
flag.setOnOff(false);
|
||||
}
|
||||
@ -474,9 +472,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
disable = buf->isUnnamed() || buf->isClean();
|
||||
break;
|
||||
case LFUN_BOOKMARK_GOTO:
|
||||
disable = !view()->
|
||||
disable = !view()->
|
||||
isSavedPosition(strToUnsignedInt(ev.argument));
|
||||
break;
|
||||
|
||||
case LFUN_MERGE_CHANGES:
|
||||
case LFUN_ACCEPT_CHANGE:
|
||||
case LFUN_REJECT_CHANGE:
|
||||
@ -484,6 +483,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
case LFUN_REJECT_ALL_CHANGES:
|
||||
disable = !buf->params().tracking_changes;
|
||||
break;
|
||||
|
||||
case LFUN_INSET_TOGGLE: {
|
||||
LyXText * lt = view()->getLyXText();
|
||||
disable = !(isEditableInset(lt->getInset())
|
||||
@ -710,19 +710,18 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
|
||||
code = InsetOld::SPACE_CODE;
|
||||
break;
|
||||
case LFUN_INSET_DIALOG_SHOW: {
|
||||
LyXText * lt = view()->getLyXText();
|
||||
InsetOld * inset = lt->getInset();
|
||||
disable = !inset;
|
||||
if (!disable) {
|
||||
code = inset->lyxCode();
|
||||
if (!(code == InsetOld::INCLUDE_CODE
|
||||
|| code == InsetOld::BIBTEX_CODE
|
||||
|| code == InsetOld::FLOAT_LIST_CODE
|
||||
|| code == InsetOld::TOC_CODE))
|
||||
disable = true;
|
||||
}
|
||||
InsetOld * inset = view()->getLyXText()->getInset();
|
||||
disable = !inset;
|
||||
if (!disable) {
|
||||
code = inset->lyxCode();
|
||||
if (!(code == InsetOld::INCLUDE_CODE
|
||||
|| code == InsetOld::BIBTEX_CODE
|
||||
|| code == InsetOld::FLOAT_LIST_CODE
|
||||
|| code == InsetOld::TOC_CODE))
|
||||
disable = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -882,7 +881,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
if (view()->available())
|
||||
view()->hideCursor();
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
{
|
||||
Cursor cursor;
|
||||
buildCursor(cursor, *view());
|
||||
@ -890,6 +889,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
lyxerr << "dispatched by Cursor::dispatch()\n";
|
||||
goto exit_with_message;
|
||||
}
|
||||
lyxerr << "### NOT DISPATCHED BY Cursor::dispatch() ###\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -905,10 +905,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
int dummy_y;
|
||||
inset->getCursorPos(view(), inset_x, dummy_y);
|
||||
#endif
|
||||
if (action == LFUN_UNKNOWN_ACTION
|
||||
&& argument.empty()) {
|
||||
if (action == LFUN_UNKNOWN_ACTION && argument.empty())
|
||||
argument = encoded_last_key;
|
||||
}
|
||||
|
||||
// the insets can't try to handle this,
|
||||
// a table cell in the dummy position will
|
||||
@ -1198,8 +1196,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
QuitLyX();
|
||||
break;
|
||||
|
||||
case LFUN_TOCVIEW:
|
||||
{
|
||||
case LFUN_TOCVIEW: {
|
||||
InsetCommandParams p("tableofcontents");
|
||||
string const data = InsetCommandMailer::params2string("toc", p);
|
||||
owner->getDialogs().show("toc", data, 0);
|
||||
@ -1246,8 +1243,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
|
||||
//#warning Find another implementation here (or another lyxfunc)!
|
||||
#endif
|
||||
#endif
|
||||
case LFUN_HELP_OPEN:
|
||||
{
|
||||
|
||||
case LFUN_HELP_OPEN: {
|
||||
string const arg = argument;
|
||||
if (arg.empty()) {
|
||||
setErrorMessage(N_("Missing argument"));
|
||||
|
@ -1195,16 +1195,16 @@ string const Paragraph::asString(Buffer const & buffer, bool label) const
|
||||
s += c;
|
||||
else if (c == META_INSET &&
|
||||
getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
|
||||
ostringstream ost;
|
||||
getInset(i)->ascii(buffer, ost);
|
||||
s += subst(STRCONV(ost.str()),'\n',' ');
|
||||
ostringstream os;
|
||||
getInset(i)->ascii(buffer, os);
|
||||
s += subst(STRCONV(os.str()),'\n',' ');
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
#else
|
||||
// This should really be done by the caller and not here.
|
||||
string ret(asString(buffer, 0, size(), label));
|
||||
string ret = asString(buffer, 0, size(), label);
|
||||
return subst(ret, '\n', ' ');
|
||||
#endif
|
||||
}
|
||||
@ -1327,7 +1327,8 @@ Paragraph::value_type Paragraph::getChar(pos_type pos) const
|
||||
// This is in the critical path!
|
||||
pos_type const siz = text_.size();
|
||||
|
||||
BOOST_ASSERT(0 <= pos && pos <= siz);
|
||||
BOOST_ASSERT(0 <= pos);
|
||||
BOOST_ASSERT(pos <= siz);
|
||||
|
||||
if (pos == siz) {
|
||||
lyxerr << "getChar() on pos " << pos << " in par id "
|
||||
@ -1347,12 +1348,6 @@ int Paragraph::id() const
|
||||
}
|
||||
|
||||
|
||||
void Paragraph::id(int i)
|
||||
{
|
||||
pimpl_->id_ = i;
|
||||
}
|
||||
|
||||
|
||||
LyXLayout_ptr const & Paragraph::layout() const
|
||||
{
|
||||
/*
|
||||
|
@ -71,8 +71,6 @@ public:
|
||||
|
||||
///
|
||||
int id() const;
|
||||
///
|
||||
void id(int i);
|
||||
|
||||
///
|
||||
Language const * getParLanguage(BufferParams const &) const;
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace lyx
|
||||
{
|
||||
namespace lyx {
|
||||
|
||||
/// a type for positions used in paragraphs
|
||||
// needs to be signed for a while to hold the special value -1 that is
|
||||
// used there...
|
||||
@ -88,6 +88,6 @@ namespace lyx
|
||||
NEXT_WORD
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace lyx
|
||||
|
||||
#endif // LYX_TYPES_H
|
||||
|
28
src/text.C
28
src/text.C
@ -1084,18 +1084,10 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
||||
// is it block, flushleft or flushright?
|
||||
// set x how you need it
|
||||
int align;
|
||||
if (pit->params().align() == LYX_ALIGN_LAYOUT) {
|
||||
if (pit->params().align() == LYX_ALIGN_LAYOUT)
|
||||
align = layout->align;
|
||||
} else {
|
||||
else
|
||||
align = pit->params().align();
|
||||
}
|
||||
// ERT insets should always be LEFT ALIGNED on screen
|
||||
InsetOld * inset = pit->inInset();
|
||||
if (inset && inset->owner() &&
|
||||
inset->owner()->lyxCode() == InsetOld::ERT_CODE)
|
||||
{
|
||||
align = LYX_ALIGN_LEFT;
|
||||
}
|
||||
|
||||
// Display-style insets should always be on a centred row
|
||||
// The test on pit->size() is to catch zero-size pars, which
|
||||
@ -1485,27 +1477,11 @@ void LyXText::changeCase(LyXText::TextCase action)
|
||||
void LyXText::Delete()
|
||||
{
|
||||
// this is a very easy implementation
|
||||
|
||||
LyXCursor old_cursor = cursor;
|
||||
int const old_cur_par_id = cursorPar()->id();
|
||||
int const old_cur_par_prev_id =
|
||||
old_cursor.par() ? getPar(old_cursor.par() - 1)->id() : -1;
|
||||
|
||||
// just move to the right
|
||||
cursorRight(bv());
|
||||
|
||||
// CHECK Look at the comment here.
|
||||
// This check is not very good...
|
||||
// The cursorRightIntern calls DeleteEmptyParagraphMechanism
|
||||
// and that can very well delete the par or par->previous in
|
||||
// old_cursor. Will a solution where we compare paragraph id's
|
||||
//work better?
|
||||
int iid = cursor.par() ? getPar(cursor.par() - 1)->id() : -1;
|
||||
if (iid == old_cur_par_prev_id && cursorPar()->id() != old_cur_par_id) {
|
||||
// delete-empty-paragraph-mechanism has done it
|
||||
return;
|
||||
}
|
||||
|
||||
// if you had success make a backspace
|
||||
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
|
||||
recordUndo(Undo::DELETE, this, old_cursor.par());
|
||||
|
@ -147,12 +147,9 @@ void recordUndo(Undo::undo_kind kind,
|
||||
ParagraphList::iterator last = plist.begin();
|
||||
advance(last, last_par);
|
||||
|
||||
for (ParagraphList::iterator it = first; it != last; ++it) {
|
||||
for (ParagraphList::iterator it = first; it != last; ++it)
|
||||
undo_pars.push_back(*it);
|
||||
undo_pars.back().id(it->id());
|
||||
}
|
||||
undo_pars.push_back(*last);
|
||||
undo_pars.back().id(last->id());
|
||||
|
||||
// and make sure that next time, we should be combining if possible
|
||||
undo_finished = false;
|
||||
|
Loading…
Reference in New Issue
Block a user