From: Abdelrazak Younes Date: Sat, 3 Oct 2009 19:12:21 +0000 (+0000) Subject: Move Undo::beginUndoGroup() and Undo::endUndoGroup() calls to where they are used... X-Git-Tag: 2.0.0~5431 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d38ca04ff7a2c5d4f6e6b056423d1364551ce50b;p=features.git Move Undo::beginUndoGroup() and Undo::endUndoGroup() calls to where they are used and necessary, hopefully. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31492 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index b9a4f42958..94f46af094 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1742,6 +1742,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) string const argument = to_utf8(func.argument()); // We'll set this back to false if need be. bool dispatched = true; + undo().beginUndoGroup(); switch (func.action) { case LFUN_BUFFER_TOGGLE_READ_ONLY: @@ -2065,6 +2066,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) break; } dr.dispatched(dispatched); + undo().endUndoGroup(); } diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 46b3e079b4..82399c77b7 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1214,6 +1214,11 @@ bool BufferView::dispatch(FuncRequest const & cmd) if (buffer_.isInternal() && lyxaction.funcHasFlag(cmd.action, LyXAction::NoInternal)) return false; + // We'll set this back to false if need be. + bool dispatched = true; + if (cmd.action != LFUN_UNDO && cmd.action != LFUN_REDO) + buffer_.undo().beginUndoGroup(); + switch (cmd.action) { case LFUN_BUFFER_PARAMS_APPLY: { @@ -1868,22 +1873,21 @@ bool BufferView::dispatch(FuncRequest const & cmd) if (!setCursorFromInset(inset)) { LASSERT(false, break); } - // useful if we are called from a dialog. - cur.beginUndoGroup(); cur.recordUndo(); FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument()); inset->dispatch(cur, fr); - cur.endUndoGroup(); processUpdateFlags(Update::SinglePar | Update::FitCursor); break; } - default: - return false; + dispatched = false; + break; } - return true; + if (cmd.action != LFUN_UNDO && cmd.action != LFUN_REDO) + buffer_.undo().endUndoGroup(); + return dispatched; } diff --git a/src/Cursor.cpp b/src/Cursor.cpp index b8d1b9fe57..9b6c82dcd8 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -286,6 +286,8 @@ void Cursor::dispatch(FuncRequest const & cmd0) fixIfBroken(); FuncRequest cmd = cmd0; Cursor safe = *this; + + buffer()->undo().beginUndoGroup(); // store some values to be used inside of the handlers beforeDispatchCursor_ = *this; @@ -327,6 +329,7 @@ void Cursor::dispatch(FuncRequest const & cmd0) // are possible which would change it beforeDispatchCursor_ = safe.beforeDispatchCursor_; } + buffer()->undo().endUndoGroup(); } diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index ef568b57e5..72bbee61ca 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -734,20 +734,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd) ? &(lv->documentBufferView()->buffer()) : 0; if (doc_buffer && !theBufferList().isLoaded(doc_buffer)) doc_buffer = 0; - // Start an undo group. This may be needed for - // some stuff like inset-apply on labels. - if (doc_buffer) - doc_buffer->undo().beginUndoGroup(); // Let the current LyXView dispatch its own actions. if (lv->dispatch(cmd)) { BufferView * bv = lv->currentBufferView(); - if (bv) { - Buffer * buffer = &(bv->buffer()); + if (bv) updateFlags = bv->cursor().result().update(); - if (buffer == doc_buffer && theBufferList().isLoaded(buffer)) - buffer->undo().endUndoGroup(); - } break; } @@ -757,21 +749,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // Let the current BufferView dispatch its own actions. if (bv->dispatch(cmd)) { // The BufferView took care of its own updates if needed. - Buffer * buffer = &(bv->buffer()); updateFlags = Update::None; - if (buffer == doc_buffer && theBufferList().isLoaded(buffer)) - buffer->undo().endUndoGroup(); break; } BufferView * doc_bv = lv->documentBufferView(); // Try with the document BufferView dispatch if any. if (doc_bv && doc_bv->dispatch(cmd)) { - // The BufferView took care of its own updates if needed. - Buffer * buffer = &(doc_bv->buffer()); updateFlags = Update::None; - if (buffer == doc_buffer && theBufferList().isLoaded(buffer)) - buffer->undo().endUndoGroup(); break; } @@ -818,9 +803,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (badcursor) bv->cursor().fixIfBroken(); } - Buffer * buffer = &(bv->buffer()); - if (buffer == doc_buffer && theBufferList().isLoaded(buffer)) - buffer->undo().endUndoGroup(); // update completion. We do it here and not in // processKeySym to avoid another redraw just for a diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index 7eae64667b..538c04c177 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -174,6 +174,9 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd) TocItem const & item = gui_view_.tocModels().currentItem(current_type_, index); + // Start an undo group. + cur.beginUndoGroup(); + switch (cmd.action) { case LFUN_CHANGE_ACCEPT: @@ -202,6 +205,7 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd) if (inset) inset->dispatch(cur, tmpcmd); } + cur.endUndoGroup(); }