setUndo2 interface change

access to topmost plist item (as reference...)


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7022 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-05-23 10:33:40 +00:00
parent a20a3cf798
commit 983d23f87d
13 changed files with 136 additions and 131 deletions

View File

@ -604,9 +604,7 @@ void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
return; // shouldn't happen return; // shouldn't happen
if (kind == Undo::EDIT) // in this case insets would not be stored! if (kind == Undo::EDIT) // in this case insets would not be stored!
kind = Undo::FINISH; kind = Undo::FINISH;
setUndo(this, kind, setUndo(this, kind, text->cursor.par());
text->cursor.par(),
boost::next(text->cursor.par()));
} }

View File

@ -1,3 +1,13 @@
2003-05-23 André Pönitz <poenitz@gmx.net>
* BufferView.C:
* BufferView_pimpl.C:
* buffer.C:
* buffer.h:
* lyxfunc.C:
* undo_funcs.C: setUndo reworked
* iterators.[Ch]: add access to topmost ParagraphList
2003-05-23 Alfredo Braunstein <abraunst@libero.it> 2003-05-23 Alfredo Braunstein <abraunst@libero.it>

View File

@ -2203,8 +2203,8 @@ Inset * Buffer::getInsetFromID(int id_arg) const
ParIterator Buffer::getParFromID(int id) const ParIterator Buffer::getParFromID(int id) const
{ {
#warning FIXME: const correctness! (Andre) #warning FIXME: const correctness! (Andre)
ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin()); ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
ParIterator end(const_cast<Buffer*>(this)->par_iterator_end()); ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
#warning FIXME, perhaps this func should return a ParIterator? (Lgb) #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
if (id < 0) { if (id < 0) {

View File

@ -1038,9 +1038,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
break; break;
// no break here! // no break here!
case LFUN_DELETE: case LFUN_DELETE:
setUndo(bv, Undo::DELETE, setUndo(bv, Undo::DELETE, bv->text->cursor.par());
bv->text->cursor.par(),
boost::next(bv->text->cursor.par()));
cutSelection(bv->buffer()->params); cutSelection(bv->buffer()->params);
updateLocal(bv, INIT); updateLocal(bv, INIT);
break; break;
@ -1123,9 +1121,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
} }
case LFUN_PASTE: case LFUN_PASTE:
if (hasPasteBuffer()) { if (hasPasteBuffer()) {
setUndo(bv, Undo::INSERT, setUndo(bv, Undo::INSERT, bv->text->cursor.par());
bv->text->cursor.par(),
boost::next(bv->text->cursor.par()));
pasteSelection(bv); pasteSelection(bv);
updateLocal(bv, INIT); updateLocal(bv, INIT);
break; break;
@ -1619,9 +1615,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
setSelection(0, tabular->GetNumberOfCells() - 1); setSelection(0, tabular->GetNumberOfCells() - 1);
} }
if (hasSelection()) { if (hasSelection()) {
setUndo(bv, Undo::EDIT, setUndo(bv, Undo::EDIT, bv->text->cursor.par());
bv->text->cursor.par(),
boost::next(bv->text->cursor.par()));
bool const frozen = undo_frozen; bool const frozen = undo_frozen;
if (!frozen) if (!frozen)
freezeUndo(); freezeUndo();
@ -1743,9 +1737,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
sel_col_start = sel_col_end = tabular->column_of_cell(actcell); sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
sel_row_start = sel_row_end = tabular->row_of_cell(actcell); sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
} }
setUndo(bv, Undo::FINISH, setUndo(bv, Undo::FINISH, bv->text->cursor.par());
bv->text->cursor.par(),
boost::next(bv->text->cursor.par()));
int row = tabular->row_of_cell(actcell); int row = tabular->row_of_cell(actcell);
int column = tabular->column_of_cell(actcell); int column = tabular->column_of_cell(actcell);

View File

@ -1134,8 +1134,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
* true (on). */ * true (on). */
#if 0 #if 0
// This should not be needed here and is also WRONG! // This should not be needed here and is also WRONG!
setUndo(bv, Undo::INSERT, setUndo(bv, Undo::INSERT, lt->cursor.par());
lt->cursor.par(), boost::next(lt->cursor.par()));
#endif #endif
bv->switchKeyMap(); bv->switchKeyMap();
if (lyxrc.auto_region_delete) { if (lyxrc.auto_region_delete) {
@ -1853,7 +1852,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
clear = true; clear = true;
} }
if (lt->selection.set()) { if (lt->selection.set()) {
setUndo(bv, Undo::EDIT, lt->cursor.par(), boost::next(lt->cursor.par())); setUndo(bv, Undo::EDIT, lt->cursor.par());
} }
if (selectall) if (selectall)
selectAll(bv); selectAll(bv);

View File

@ -161,6 +161,12 @@ size_t ParIterator::size() const
} }
ParagraphList & ParIterator::plist() const
{
return *const_cast<ParagraphList*>(pimpl_->positions.top().plist);
}
bool operator==(ParIterator const & iter1, ParIterator const & iter2) bool operator==(ParIterator const & iter1, ParIterator const & iter2)
{ {
return iter1.pimpl_->positions == iter2.pimpl_->positions; return iter1.pimpl_->positions == iter2.pimpl_->positions;

View File

@ -33,6 +33,8 @@ public:
/// ///
ParagraphList::iterator operator->() const; ParagraphList::iterator operator->() const;
/// ///
ParagraphList & plist() const;
///
size_t size() const; size_t size() const;
/// ///
friend friend

View File

@ -1465,7 +1465,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
&& !layout->keepempty) && !layout->keepempty)
return; return;
setUndo(bv(), Undo::FINISH, cursor.par(), boost::next(cursor.par())); setUndo(bv(), Undo::FINISH, cursor.par());
// Always break behind a space // Always break behind a space
// //
@ -1570,7 +1570,7 @@ void LyXText::redoParagraph()
// same Paragraph one to the right and make a rebreak // same Paragraph one to the right and make a rebreak
void LyXText::insertChar(char c) void LyXText::insertChar(char c)
{ {
setUndo(bv(), Undo::INSERT, cursor.par(), boost::next(cursor.par())); setUndo(bv(), Undo::INSERT, cursor.par());
// When the free-spacing option is set for the current layout, // When the free-spacing option is set for the current layout,
// disable the double-space checking // disable the double-space checking
@ -2120,7 +2120,7 @@ void LyXText::acceptChange()
if (selection.start.par() == selection.end.par()) { if (selection.start.par() == selection.end.par()) {
LyXCursor & startc = selection.start; LyXCursor & startc = selection.start;
LyXCursor & endc = selection.end; LyXCursor & endc = selection.end;
setUndo(bv(), Undo::INSERT, startc.par(), boost::next(startc.par())); setUndo(bv(), Undo::INSERT, startc.par());
startc.par()->acceptChange(startc.pos(), endc.pos()); startc.par()->acceptChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
clearSelection(); clearSelection();
@ -2139,8 +2139,7 @@ void LyXText::rejectChange()
if (selection.start.par() == selection.end.par()) { if (selection.start.par() == selection.end.par()) {
LyXCursor & startc = selection.start; LyXCursor & startc = selection.start;
LyXCursor & endc = selection.end; LyXCursor & endc = selection.end;
setUndo(bv(), Undo::INSERT, startc.par(), setUndo(bv(), Undo::INSERT, startc.par());
boost::next(startc.par()));
startc.par()->rejectChange(startc.pos(), endc.pos()); startc.par()->rejectChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
clearSelection(); clearSelection();
@ -2357,7 +2356,7 @@ void LyXText::changeCase(LyXText::TextCase action)
lyx::Assert(from <= to); lyx::Assert(from <= to);
setUndo(bv(), Undo::FINISH, from.par(), boost::next(to.par())); setUndo(bv(), Undo::FINISH, from.par(), to.par());
pos_type pos = from.pos(); pos_type pos = from.pos();
ParagraphList::iterator pit = from.par(); ParagraphList::iterator pit = from.par();
@ -2427,8 +2426,7 @@ void LyXText::Delete()
LyXCursor tmpcursor = cursor; LyXCursor tmpcursor = cursor;
// to make sure undo gets the right cursor position // to make sure undo gets the right cursor position
cursor = old_cursor; cursor = old_cursor;
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE, cursor.par());
cursor.par(), boost::next(cursor.par()));
cursor = tmpcursor; cursor = tmpcursor;
backspace(); backspace();
} }
@ -2487,7 +2485,7 @@ void LyXText::backspace()
if (cursor.par() != ownerParagraphs().begin()) { if (cursor.par() != ownerParagraphs().begin()) {
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE,
boost::prior(cursor.par()), boost::prior(cursor.par()),
boost::next(cursor.par())); cursor.par());
} }
ParagraphList::iterator tmppit = cursor.par(); ParagraphList::iterator tmppit = cursor.par();
@ -2553,8 +2551,7 @@ void LyXText::backspace()
} else { } else {
// this is the code for a normal backspace, not pasting // this is the code for a normal backspace, not pasting
// any paragraphs // any paragraphs
setUndo(bv(), Undo::DELETE, setUndo(bv(), Undo::DELETE, cursor.par());
cursor.par(), boost::next(cursor.par()));
// We used to do cursorLeftIntern() here, but it is // We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete // not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite, // mechanism. So we do a cursorLeftIntern()-lite,

View File

@ -393,7 +393,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
++endpit; ++endpit;
} }
setUndo(bv(), Undo::EDIT, sstart_cur.par(), undoendpit); setUndo(bv(), Undo::EDIT, sstart_cur.par(), boost::prior(undoendpit));
// ok we have a selection. This is always between sstart_cur // ok we have a selection. This is always between sstart_cur
// and sel_end cursor // and sel_end cursor
@ -486,7 +486,7 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
ParagraphList::iterator pastend = boost::next(end); ParagraphList::iterator pastend = boost::next(end);
if (!test_only) if (!test_only)
setUndo(bv(), Undo::EDIT, start, pastend); setUndo(bv(), Undo::EDIT, start, end);
bool changed = false; bool changed = false;
@ -588,8 +588,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
// ok we have a selection. This is always between sel_start_cursor // ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor // and sel_end cursor
setUndo(bv(), Undo::EDIT, setUndo(bv(), Undo::EDIT, selection.start.par(), selection.end.par());
selection.start.par(), boost::next(selection.end.par()));
freezeUndo(); freezeUndo();
cursor = selection.start; cursor = selection.start;
while (cursor.par() != selection.end.par() || while (cursor.par() != selection.end.par() ||
@ -991,7 +990,8 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
++endpit; ++endpit;
} }
setUndo(bv(), Undo::EDIT, selection.start.par(), undoendpit); setUndo(bv(), Undo::EDIT, selection.start.par(),
boost::prior(undoendpit));
ParagraphList::iterator tmppit = selection.end.par(); ParagraphList::iterator tmppit = selection.end.par();
@ -1276,8 +1276,7 @@ void LyXText::insertInset(Inset * inset)
{ {
if (!cursor.par()->insetAllowed(inset->lyxCode())) if (!cursor.par()->insetAllowed(inset->lyxCode()))
return; return;
setUndo(bv(), Undo::FINISH, cursor.par(), setUndo(bv(), Undo::FINISH, cursor.par());
boost::next(cursor.par()));
freezeUndo(); freezeUndo();
cursor.par()->insertInset(cursor.pos(), inset); cursor.par()->insertInset(cursor.pos(), inset);
// Just to rebreak and refresh correctly. // Just to rebreak and refresh correctly.
@ -1329,7 +1328,8 @@ void LyXText::cutSelection(bool doclear, bool realcut)
++endpit; ++endpit;
} }
setUndo(bv(), Undo::DELETE, selection.start.par(), undoendpit); setUndo(bv(), Undo::DELETE, selection.start.par(),
boost::prior(undoendpit));
endpit = selection.end.par(); endpit = selection.end.par();
@ -1401,8 +1401,7 @@ void LyXText::pasteSelection()
if (!CutAndPaste::checkPastePossible()) if (!CutAndPaste::checkPastePossible())
return; return;
setUndo(bv(), Undo::INSERT, setUndo(bv(), Undo::INSERT, cursor.par());
cursor.par(), boost::next(cursor.par()));
ParagraphList::iterator endpit; ParagraphList::iterator endpit;
PitPosPair ppp; PitPosPair ppp;
@ -2264,7 +2263,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
++endpit; ++endpit;
} }
setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit); setUndo(bv(), Undo::DELETE, old_cursor.par(),
boost::prior(endpit));
cursor = tmpcursor; cursor = tmpcursor;
// delete old row // delete old row
@ -2295,7 +2295,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
++endpit; ++endpit;
} }
setUndo(bv(), Undo::DELETE, old_cursor.par(), endpit); setUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
cursor = tmpcursor; cursor = tmpcursor;
// delete old row // delete old row

View File

@ -418,7 +418,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
for (; tmp != end; ++tmp) { for (; tmp != end; ++tmp) {
if (tmp->params().startOfAppendix()) { if (tmp->params().startOfAppendix()) {
setUndo(bv, Undo::EDIT, tmp, boost::next(tmp)); setUndo(bv, Undo::EDIT, tmp);
tmp->params().startOfAppendix(false); tmp->params().startOfAppendix(false);
int tmpy; int tmpy;
setHeightOfRow(getRow(tmp, 0, tmpy)); setHeightOfRow(getRow(tmp, 0, tmpy));
@ -426,7 +426,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
} }
} }
setUndo(bv, Undo::EDIT, pit, boost::next(pit)); setUndo(bv, Undo::EDIT, pit);
pit->params().startOfAppendix(start); pit->params().startOfAppendix(start);
// we can set the refreshing parameters now // we can set the refreshing parameters now

View File

@ -27,7 +27,7 @@ void transposeChars(LyXText & text, LyXCursor const & cursor)
{ {
ParagraphList::iterator tmppit = cursor.par(); ParagraphList::iterator tmppit = cursor.par();
setUndo(text.bv(), Undo::FINISH, tmppit, boost::next(tmppit)); setUndo(text.bv(), Undo::FINISH, tmppit);
pos_type tmppos = cursor.pos(); pos_type tmppos = cursor.pos();

View File

@ -47,15 +47,15 @@ LyXCursor const & undoCursor(BufferView * bv)
* we are so it will return the first paragraph of the buffer or the * we are so it will return the first paragraph of the buffer or the
* first paragraph of the textinset we're in. * first paragraph of the textinset we're in.
*/ */
ParagraphList undoParagraphs(BufferView * bv, int inset_id) ParagraphList * undoParagraphs(BufferView * bv, int inset_id)
{ {
Inset * inset = bv->buffer()->getInsetFromID(inset_id); Inset * inset = bv->buffer()->getInsetFromID(inset_id);
if (inset) { if (inset) {
ParagraphList * result = inset->getParagraphs(0); ParagraphList * result = inset->getParagraphs(0);
if (result && !result->empty()) if (result && !result->empty())
return *result; return result;
} }
return bv->text->ownerParagraphs(); return &bv->text->ownerParagraphs();
} }
@ -95,7 +95,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
num = -1; num = -1;
} }
} }
t->setCursorIntern(undoParagraphs(bv, num).begin(), 0); t->setCursorIntern(undoParagraphs(bv, num)->begin(), 0);
} }
// Set the right(new) inset-owner of the paragraph if there is any. // Set the right(new) inset-owner of the paragraph if there is any.
@ -119,7 +119,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
deletepar = *before; deletepar = *before;
++deletepar; ++deletepar;
} else { } else {
deletepar = undoParagraphs(bv, undo.number_of_inset_id).begin(); deletepar = undoParagraphs(bv, undo.number_of_inset_id)->begin();
} }
// this surprisingly fills the undo! (Andre') // this surprisingly fills the undo! (Andre')
size_t par = 0; size_t par = 0;
@ -160,7 +160,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
#warning FIXME #warning FIXME
//(&**before)->next(undopar); //(&**before)->next(undopar);
} else { } else {
int id = undoParagraphs(bv, undo.number_of_inset_id).front().id(); int id = undoParagraphs(bv, undo.number_of_inset_id)->begin()->id();
ParIterator op = bv->buffer()->getParFromID(id); ParIterator op = bv->buffer()->getParFromID(id);
if (op != end && op->inInset()) { if (op != end && op->inInset()) {
#warning FIXME reimplementaion needed here #warning FIXME reimplementaion needed here
@ -175,7 +175,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// have to substitue the second paragraph with the // have to substitue the second paragraph with the
// first if the removed one is the first. // first if the removed one is the first.
if (before == end && behind != end) { if (before == end && behind != end) {
int id = undoParagraphs(bv, undo.number_of_inset_id).front().id(); int id = undoParagraphs(bv, undo.number_of_inset_id)->begin()->id();
ParIterator op = bv->buffer()->getParFromID(id); ParIterator op = bv->buffer()->getParFromID(id);
if (op != end && op->inInset()) { if (op != end && op->inInset()) {
#warning FIXME reimplementation needed here #warning FIXME reimplementation needed here
@ -273,28 +273,57 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
bool createUndo(BufferView * bv, Undo::undo_kind kind, bool createUndo(BufferView * bv, Undo::undo_kind kind,
ParagraphList::iterator itfirst, ParagraphList::iterator itbehind, ParagraphList::iterator itfirst, ParagraphList::iterator itlast,
shared_ptr<Undo> & u) shared_ptr<Undo> & u)
{ {
Paragraph * const first = &*itfirst;
Paragraph * const behind = &*itbehind;
lyx::Assert(first);
int before_number = -1;
int behind_number = -1;
int inset_id = -1;
#warning FIXME
//if (first->previous())
// before_number = first->previous()->id();
if (behind)
behind_number = behind->id();
if (first->inInset())
inset_id = first->inInset()->id();
Buffer * b = bv->buffer(); Buffer * b = bv->buffer();
// Undo::EDIT and Undo::FINISH are ParIterator it = b->par_iterator_begin();
ParIterator null = b->par_iterator_end();
ParIterator prev = null;
ParIterator before = null;
ParIterator first = null;
ParIterator last = null;
ParIterator behind = null;
for (; it != null; ++it) {
if ((*it)->id() == itfirst->id()) {
first = it;
before = prev;
} else if ((*it)->id() == itlast->id()) {
last = it;
behind = last;
++behind;
}
prev = it;
}
if (last == null)
last = first;
int const before_id = (before == null) ? -1 : (*before)->id();
int const first_id = (first == null) ? -1 : (*first)->id();
int const last_id = (last == null) ? -1 : (*last)->id();
int const behind_id = (behind == null) ? -1 : (*behind)->id();
int inset_id = (first->inInset()) ? first->inInset()->id() : -1;
lyxerr << "\nbefore_id: " << before_id << "\n";
lyxerr << "first_id: " << first_id << "\n";
lyxerr << "last_id: " << last_id << "\n";
lyxerr << "behind_id: " << behind_id << "\n";
lyxerr << "inset_id: " << inset_id << "\n";
ParagraphList * plist = 0;
if (first != null)
plist = &first.plist();
else if (behind != null)
plist = &behind.plist();
else if (!plist) {
lyxerr << "plist from buffer (should this happen?)\n";
plist = &b->paragraphs;
}
// Undo::EDIT and Undo::FINISH are
// always finished. (no overlapping there) // always finished. (no overlapping there)
// overlapping only with insert and delete inside one paragraph: // overlapping only with insert and delete inside one paragraph:
// Nobody wants all removed character // Nobody wants all removed character
@ -305,8 +334,8 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
// Check whether storing is needed. // Check whether storing is needed.
if (!b->undostack.empty() && if (!b->undostack.empty() &&
b->undostack.top()->kind == kind && b->undostack.top()->kind == kind &&
b->undostack.top()->number_of_before_par == before_number && b->undostack.top()->number_of_before_par == before_id &&
b->undostack.top()->number_of_behind_par == behind_number) { b->undostack.top()->number_of_behind_par == behind_id) {
// No undo needed. // No undo needed.
return false; return false;
} }
@ -315,49 +344,23 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
// Create a new Undo. // Create a new Undo.
std::vector<Paragraph *> undo_pars; std::vector<Paragraph *> undo_pars;
Paragraph const * end = 0; for (ParagraphList::iterator it = *first; it != *last; ++it)
undo_pars.push_back(new Paragraph(*it, true));
if (behind) { undo_pars.push_back(new Paragraph(**last, true));
#warning FIXME
//end = behind->previous();
}else {
end = first;
#warning FIXME
//while (end->next())
// end = end->next();
}
#warning FIXME
// if (first && end && (first != end->next()) &&
// ((before_number != behind_number) ||
// ((before_number < 0) && (behind_number < 0))))
// {
// undo_pars.push_back(new Paragraph(*first, true));
// for (Paragraph * tmppar = first; tmppar != end && tmppar->next(); ) {
// tmppar = tmppar->next();
// undo_pars.push_back(new Paragraph(*tmppar, true));
// size_t const n = undo_pars.size();
// undo_pars[n - 2]->next(undo_pars[n - 1]);
// undo_pars[n - 1]->previous(undo_pars[n - 2]);
// }
// undo_pars.back()->next(0);
// }
// A memory optimization: Just store the layout // A memory optimization: Just store the layout
// information when only edit. // information when only edit.
if (kind == Undo::EDIT) { if (kind == Undo::EDIT)
for (size_t i = 0, n = undo_pars.size(); i < n; ++i) for (size_t i = 0, n = undo_pars.size(); i < n; ++i)
undo_pars[i]->clearContents(); undo_pars[i]->clearContents();
}
int cursor_par = undoCursor(bv).par()->id(); int cursor_par = undoCursor(bv).par()->id();
int cursor_pos = undoCursor(bv).pos(); int cursor_pos = undoCursor(bv).pos();
//lyxerr << "createUndo: inset_id: " << inset_id << " before_number: " lyxerr << "createUndo: inset_id: " << inset_id << " before_id: "
// << before_number << " behind_number: " << behind_number << "\n"; << before_id << " behind_id: " << behind_id << "\n";
u.reset(new Undo(kind, inset_id, u.reset(new Undo(kind, inset_id,
before_number, behind_number, before_id, behind_id, cursor_par, cursor_pos, undo_pars));
cursor_par, cursor_pos, undo_pars));
undo_finished = false; undo_finished = false;
return true; return true;
@ -392,7 +395,7 @@ bool textUndoOrRedo(BufferView * bv,
if (first->next()) if (first->next())
first = first->next(); first = first->next();
} else } else
first = undoParagraphs(bv, undo->number_of_inset_id).begin(); first = undoParagraphs(bv, undo->number_of_inset_id)->begin();
if (first) { if (first) {
shared_ptr<Undo> u; shared_ptr<Undo> u;
ParIterator behind = b->getParFromID(undo->number_of_behind_par); ParIterator behind = b->getParFromID(undo->number_of_behind_par);
@ -452,28 +455,27 @@ bool textRedo(BufferView * bv)
void setUndo(BufferView * bv, Undo::undo_kind kind, void setUndo(BufferView * bv, Undo::undo_kind kind,
ParagraphList::iterator first, ParagraphList::iterator behind) ParagraphList::iterator first)
{ {
setUndo(bv, kind, first, first);
}
void setUndo(BufferView * bv, Undo::undo_kind kind,
ParagraphList::iterator first, ParagraphList::iterator last)
{
#warning DISABLED
return;
if (!undo_frozen) { if (!undo_frozen) {
shared_ptr<Undo> u; shared_ptr<Undo> u;
if (createUndo(bv, kind, first, behind, u)) if (createUndo(bv, kind, first, last, u))
bv->buffer()->undostack.push(u); bv->buffer()->undostack.push(u);
bv->buffer()->redostack.clear(); bv->buffer()->redostack.clear();
} }
} }
void setRedo(BufferView * bv, Undo::undo_kind kind,
ParagraphList::iterator first, ParagraphList::iterator behind)
{
shared_ptr<Undo> u;
if (createUndo(bv, kind, first, behind, u))
bv->buffer()->redostack.push(u);
}
void setCursorParUndo(BufferView * bv) void setCursorParUndo(BufferView * bv)
{ {
setUndo(bv, Undo::FINISH, bv->text->cursor.par(), setUndo(bv, Undo::FINISH, bv->text->cursor.par());
boost::next(bv->text->cursor.par()));
} }

View File

@ -18,24 +18,23 @@ class BufferView;
class Paragraph; class Paragraph;
/// returns false if no undo possible /// returns false if no undo possible
extern bool textUndo(BufferView *); bool textUndo(BufferView *);
/// returns false if no redo possible /// returns false if no redo possible
extern bool textRedo(BufferView *); bool textRedo(BufferView *);
/// makes sure the next operation will be stored /// makes sure the next operation will be stored
extern void finishUndo(); void finishUndo();
/// Whilst undo is frozen, all actions do not get added /// Whilst undo is frozen, all actions do not get added
/// to the undo stack /// to the undo stack
extern void freezeUndo(); void freezeUndo();
/// Track undos again /// Track undos again
extern void unFreezeUndo(); void unFreezeUndo();
/// FIXME /// FIXME
extern void setUndo(BufferView *, Undo::undo_kind kind, void setUndo(BufferView *, Undo::undo_kind kind,
ParagraphList::iterator first, ParagraphList::iterator behind); ParagraphList::iterator first, ParagraphList::iterator last);
void setUndo(BufferView *, Undo::undo_kind kind,
ParagraphList::iterator first);
/// FIXME /// FIXME
extern void setRedo(BufferView *, Undo::undo_kind kind, void setCursorParUndo(BufferView *);
ParagraphList::iterator first, ParagraphList::iterator behind);
/// FIXME
extern void setCursorParUndo(BufferView *);
/// Are we avoiding tracking undos currently ? /// Are we avoiding tracking undos currently ?
extern bool undo_frozen; extern bool undo_frozen;