preparations to regain ability of per-inset undo.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7911 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-10-13 13:27:45 +00:00
parent 45a8d5a93a
commit b79331e005
3 changed files with 24 additions and 4 deletions

View File

@ -15,12 +15,14 @@
#include "paragraph.h" #include "paragraph.h"
Undo::Undo(undo_kind kind_arg, int inset, Undo::Undo(undo_kind kind_arg, int inset,
int plist_arg,
int first, int last, int first, int last,
int cursor, int cursor_pos_arg, int cursor, int cursor_pos_arg,
ParagraphList const & par) ParagraphList const & par)
: :
kind(kind_arg), kind(kind_arg),
inset_id(inset), inset_id(inset),
plist(plist_arg),
first_par_offset(first), first_par_offset(first),
last_par_offset(last), last_par_offset(last),
cursor_par_offset(cursor), cursor_par_offset(cursor),

View File

@ -45,6 +45,7 @@ public:
}; };
/// ///
Undo(undo_kind kind, int inset_id, Undo(undo_kind kind, int inset_id,
int plist,
int first, int last, int first, int last,
int cursor, int cursor_pos, int cursor, int cursor_pos,
ParagraphList const & par_arg); ParagraphList const & par_arg);
@ -52,6 +53,9 @@ public:
/// Which kind of operation are we recording for? /// Which kind of operation are we recording for?
undo_kind kind; undo_kind kind;
/// to what paragraph list do we belong?
int plist;
/** /**
* ID of hosting inset if the cursor is in one. * ID of hosting inset if the cursor is in one.
* if -1, then the cursor is not in an inset. * if -1, then the cursor is not in an inset.

View File

@ -57,9 +57,16 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
LyXText * text = inset ? inset->getLyXText(bv) : bv->text; LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
int const inset_id = inset ? inset->id() : -1; int const inset_id = inset ? inset->id() : -1;
// We simply record the entire outer paragraphs // Try to find the appropriate list by counting the,
ParIterator null = buf->par_iterator_end(); ParIterator null = buf->par_iterator_end();
int pcount = 0;
for (ParIterator it = buf->par_iterator_begin(); it != null; ++it, ++pcount)
if (&it.plist() == &plist)
break;
//lyxerr << "This is plist #" << pcount << ' ' << &plist << endl;
// We simply record the entire outer paragraphs
// First, identify the outer paragraphs // First, identify the outer paragraphs
for (ParIterator it = buf->par_iterator_begin(); it != null; ++it) { for (ParIterator it = buf->par_iterator_begin(); it != null; ++it) {
if (it->id() == first->id()) if (it->id() == first->id())
@ -93,11 +100,11 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
// Make and push the Undo entry // Make and push the Undo entry
stack.push(Undo(kind, inset_id, stack.push(Undo(kind, inset_id,
pcount,
first_offset, last_offset, first_offset, last_offset,
cursor_offset, text->cursor.pos(), cursor_offset, text->cursor.pos(),
ParagraphList())); ParagraphList()));
lyxerr << "G" << endl;
// Record the relevant paragraphs // Record the relevant paragraphs
ParagraphList & undo_pars = stack.top().pars; ParagraphList & undo_pars = stack.top().pars;
@ -119,6 +126,13 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
Buffer * buf = bv->buffer(); Buffer * buf = bv->buffer();
ParagraphList & plist = buf->paragraphs(); ParagraphList & plist = buf->paragraphs();
ParIterator null = buf->par_iterator_end();
ParIterator plit = buf->par_iterator_begin();
int n = undo.plist;
for ( ; n && plit != null; ++plit, --n)
;
//lyxerr << "undo: using plist #" << undo.plist << " " << &plit.plist() << endl;
// Remove new stuff between first and last // Remove new stuff between first and last
{ {
ParagraphList::iterator first = plist.begin(); ParagraphList::iterator first = plist.begin();
@ -152,10 +166,10 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo)
LyXText * text = inset ? inset->getLyXText(bv) : bv->text; LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos); text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos);
lyxerr << "undo, inset: " << inset << endl; //lyxerr << "undo, inset: " << inset << endl;
if (inset) { if (inset) {
lyxerr << "undo, inset owner: " << inset->owner() << endl; //lyxerr << "undo, inset owner: " << inset->owner() << endl;
// Magic needed to update inset internal state // Magic needed to update inset internal state
FuncRequest cmd(bv, LFUN_INSET_EDIT, "left"); FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");