]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #6930: no undo for inset type changing
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 29 Nov 2010 09:47:46 +0000 (09:47 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 29 Nov 2010 09:47:46 +0000 (09:47 +0000)
THis is a consequence of the new AtPoint mechanism. In the old
world, recordUndoInset was called before INSET_MODIFY. I reintroduced
manual recordUndoInset calls in all places that matter. I suspect
that this issue should be revisited later.

Note that recordUndoInset can now take an optional parameter that tells
what inset is concerned. This is useful because the cursor can be
either just inside the inset or in front of it.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36580 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
src/Cursor.cpp
src/Cursor.h
src/Undo.cpp
src/Undo.h
src/insets/InsetBox.cpp
src/insets/InsetCommand.cpp
src/insets/InsetInclude.cpp
src/insets/InsetIndex.cpp
src/insets/InsetInfo.cpp
src/insets/InsetNewline.cpp
src/insets/InsetNewpage.cpp
src/insets/InsetNote.cpp
src/insets/InsetPhantom.cpp
src/insets/InsetScript.cpp
src/insets/InsetSpace.cpp
src/insets/InsetVSpace.cpp
src/mathed/InsetMathSpace.cpp

index a76c68fae3893d4daa295de8330ee6b7c62f30c4..c96762d5f774e79e9c11ffecac87b1bf5d5a61c6 100644 (file)
@@ -336,7 +336,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
        disp_ = DispatchResult();
 
        buffer()->undo().beginUndoGroup();
-       
+
        // Is this a function that acts on inset at point?
        if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
            && nextInset()) {
@@ -2358,9 +2358,9 @@ void Cursor::recordUndo(UndoKind kind) const
 }
 
 
-void Cursor::recordUndoInset(UndoKind kind) const
+void Cursor::recordUndoInset(UndoKind kind, Inset const * inset) const
 {
-       buffer()->undo().recordUndoInset(*this, kind);
+       buffer()->undo().recordUndoInset(*this, kind, inset);
 }
 
 
index 719a2cbd4f8138e49259badd6abd6ac065cb22ce..205e56187b6dd261f554f573ebea76c1713ba33f 100644 (file)
@@ -280,7 +280,8 @@ public:
        void recordUndo(UndoKind kind = ATOMIC_UNDO) const;
 
        /// Convenience: prepare undo for the inset containing the cursor
-       void recordUndoInset(UndoKind kind = ATOMIC_UNDO) const;
+       void recordUndoInset(UndoKind kind = ATOMIC_UNDO,
+                            Inset const * inset = 0) const;
 
        /// Convenience: prepare undo for the whole buffer
        void recordUndoFullDocument() const;
index eec7ff446601aa8399956693e893aabe77c0fb61..655f6e38ddf7cfd38ac688b524434ed2c33af930 100644 (file)
@@ -503,11 +503,18 @@ void Undo::recordUndo(DocIterator const & cur, UndoKind kind)
 }
 
 
-void Undo::recordUndoInset(DocIterator const & cur, UndoKind kind)
+void Undo::recordUndoInset(DocIterator const & cur, UndoKind kind,
+                          Inset const * inset)
 {
-       DocIterator c = cur;
-       c.pop_back();
-       d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, d->undostack_);
+       if (!inset || inset == &cur.inset()) {
+               DocIterator c = cur;
+               c.pop_back();
+               d->doRecordUndo(kind, c, c.pit(), c.pit(),
+                               cur, false, d->undostack_);
+       } else if (inset == cur.nextInset())
+               recordUndo(cur, kind);
+       else
+               LYXERR0("Inset not found, no undo stack added.");
 }
 
 
index fb57e8897e5d51e9b41566f3e3bbfce4fb176a37..f91b02fe8fd7c0d13970bc4c6c9658b762265101 100644 (file)
@@ -24,6 +24,7 @@ namespace lyx {
 class Buffer;
 class BufferParams;
 class DocIterator;
+class Inset;
 class MathData;
 class ParagraphList;
 
@@ -101,8 +102,9 @@ public:
 
        /// Convenience: record undo information for the inset
        /// containing the cursor.
-       void recordUndoInset(DocIterator const & cur, 
-                            UndoKind kind = ATOMIC_UNDO);
+       void recordUndoInset(DocIterator const & cur,
+                            UndoKind kind = ATOMIC_UNDO,
+                            Inset const * inset = 0);
 
        /// Convenience: prepare undo for the whole buffer
        void recordUndoFullDocument(DocIterator const & cur);
index d3250579219978a38816a4af995c391eaaad7cbc..86121163af4df86188d8bb4b02117d1d1e81ebff 100644 (file)
@@ -192,9 +192,10 @@ void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                //lyxerr << "InsetBox::dispatch MODIFY" << endl;
-               if (cmd.getArg(0) == "changetype")
+               if (cmd.getArg(0) == "changetype") {
+                       cur.recordUndoInset(ATOMIC_UNDO, this);
                        params_.type = cmd.getArg(1);
-               else
+               else
                        string2params(to_utf8(cmd.argument()), params_);
                setButtonLabel();
                break;
index d632e23e130d9fc0082d35d5ab38ab780c98fb4d..a429e27435fb1d4fbfe2af73d71568792e047fe9 100644 (file)
@@ -146,6 +146,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
        case LFUN_INSET_MODIFY: {
                if (cmd.getArg(0) == "changetype") {
+                       cur.recordUndo();
                        p_.setCmdName(cmd.getArg(1));
                        cur.forceBufferUpdate();
                        initView();
index f0e2f99807bc96379624b9a8d54a5fcd60441e72..fa2c83554560fc7026e1ff756e479317cb6f9cb7 100644 (file)
@@ -243,6 +243,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
                // child_buffer_ = 0;
                InsetCommandParams p(INCLUDE_CODE);
                if (cmd.getArg(0) == "changetype") {
+                       cur.recordUndo();
                        InsetCommand::doDispatch(cur, cmd);
                        p = params();
                } else
index 603c865f7877507affad7a347e62e3334fa4bfc9..86da890e02dab8654dad6a399eb7f88f1239cb87 100644 (file)
@@ -207,6 +207,7 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                if (cmd.getArg(0) == "changetype") {
+                       cur.recordUndoInset(ATOMIC_UNDO, this);
                        params_.index = from_utf8(cmd.getArg(1));
                        break;
                }
@@ -478,6 +479,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                                cmd = subst(cmd, "printindex", "printsubindex");
                        else
                                cmd = subst(cmd, "printsubindex", "printindex");
+                       cur.recordUndo();
                        setCmdName(cmd);
                        break;
                } else if (cmd.argument() == from_ascii("check-printindex*")) {
@@ -485,6 +487,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
                        if (suffixIs(cmd, '*'))
                                break;
                        cmd += '*';
+                       cur.recordUndo();
                        setParam("type", docstring());
                        setCmdName(cmd);
                        break;
index 2c3943effdb643f1a62aad49c19257553070885b..88a27d61be5395af6a96fcf457b2759baffa7ada 100644 (file)
@@ -208,19 +208,19 @@ bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd,
        switch (cmd.action()) {
        case LFUN_INSET_SETTINGS:
                return InsetCollapsable::getStatus(cur, cmd, flag);
-               
+
        case LFUN_INSET_DIALOG_UPDATE:
        case LFUN_INSET_COPY_AS:
                flag.setEnabled(true);
                return true;
-               
+
        case LFUN_INSET_MODIFY:
                if (validateModifyArgument(cmd.argument())) {
                        flag.setEnabled(true);
                        return true;
                }
                //fall through
-               
+
        default:
                return false;
        }
@@ -231,6 +231,7 @@ void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action()) {
        case LFUN_INSET_MODIFY:
+               cur.recordUndo();
                setInfo(to_utf8(cmd.argument()));
                break;
 
index bb9d714680b9f8ebc6b82d308a7004dae20382aa..c775170d90f60f7df65d182d4e3dd34ef855a784 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "InsetNewline.h"
 
+#include "Cursor.h"
 #include "Dimension.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
@@ -94,6 +95,7 @@ void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                InsetNewlineParams params;
+               cur.recordUndo();
                string2params(to_utf8(cmd.argument()), params);
                params_.kind = params.kind;
                break;
index 8fb49d9ec795c5912543c8d5ce481b4aba4b32c4..0f718c2979a1b357bd5935171e6d826eed03c351 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "InsetNewpage.h"
 
+#include "Cursor.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "Lexer.h"
@@ -141,6 +142,7 @@ void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                InsetNewpageParams params;
+               cur.recordUndo();
                string2params(to_utf8(cmd.argument()), params);
                params_.kind = params.kind;
                break;
index 0e76114b02831c3196beefb87d73e5a04c8f1917..d3c1b1e2b49938e7bf4fc4dab8d526502e1e07a2 100644 (file)
@@ -174,6 +174,7 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
+               cur.recordUndoInset(ATOMIC_UNDO, this);
                string2params(to_utf8(cmd.argument()), params_);
                setButtonLabel();
                // what we really want here is a TOC update, but that means
index 238ae14d3f1e294f6e3077eeb7831a41ece9a273..f275e1c9c7711b40d80e914f5958b7b037df25b7 100644 (file)
@@ -259,6 +259,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
+               cur.recordUndoInset(ATOMIC_UNDO, this);
                string2params(to_utf8(cmd.argument()), params_);
                break;
 
index 514445a943b35acf742132ac8bce0b3fa84c6dce..76f5757c38f147766530059380d4f43b2607a537 100644 (file)
@@ -214,6 +214,7 @@ void InsetScript::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action()) {
        case LFUN_INSET_MODIFY:
+               cur.recordUndoInset(ATOMIC_UNDO, this);
                string2params(to_utf8(cmd.argument()), params_);
                break;
        default:
index 62bda8080ce25204d3755e6f24b0f6f6a7f7063c..b7c15d6eef7b6a420a0f93b4b8b3ae24e7685165 100644 (file)
@@ -144,6 +144,7 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
+               cur.recordUndo();
                string2params(to_utf8(cmd.argument()), params_);
                break;
 
index a43b122052888383dcf114a5f7dd3123d055cce6..e8fad01615a21dc07c4f5f699d044d7658401b9e 100644 (file)
@@ -58,6 +58,7 @@ void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
+               cur.recordUndo();
                InsetVSpace::string2params(to_utf8(cmd.argument()), space_);
                break;
        }
index 1b045ed0ec943b8d85ad7475796ae50f3842dd8a..9cf184fa7a7ec38e159885ae47bf26e61c908eef 100644 (file)
@@ -300,6 +300,7 @@ void InsetMathSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
                if (cmd.getArg(0) == "mathspace") {
                        MathData ar;
                        if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
+                               cur.recordUndo();
                                *this = *ar[0].nucleus()->asSpaceInset();
                                break;
                        }