]> git.lyx.org Git - features.git/commitdiff
Clean-up the undo API
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 12 Mar 2015 14:57:29 +0000 (15:57 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 1 Apr 2015 12:18:23 +0000 (14:18 +0200)
* Remove the UndoKind parameter in the general interface
* move recordUndoInset to Cursor
* remove one variant of Undo::recordUndo.
* get rid of Text::recUndo.

22 files changed:
src/Cursor.cpp
src/Cursor.h
src/Text.cpp
src/Text.h
src/Text2.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/Undo.cpp
src/Undo.h
src/insets/InsetArgument.cpp
src/insets/InsetBox.cpp
src/insets/InsetBranch.cpp
src/insets/InsetCaption.cpp
src/insets/InsetERT.cpp
src/insets/InsetFloat.cpp
src/insets/InsetIndex.cpp
src/insets/InsetListings.cpp
src/insets/InsetNote.cpp
src/insets/InsetPhantom.cpp
src/insets/InsetScript.cpp
src/insets/InsetTabular.cpp
src/insets/InsetWrap.cpp

index 898eab3128e529e8b022520adccf1d9f162eae40..45720973edbc89c3db3d7f1445ec3076d02ba079 100644 (file)
@@ -2476,15 +2476,15 @@ void Cursor::endUndoGroup() const
 }
 
 
-void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to) const
+void Cursor::recordUndo(pit_type from, pit_type to) const
 {
-       buffer()->undo().recordUndo(*this, kind, from, to);
+       buffer()->undo().recordUndo(*this, from, to);
 }
 
 
-void Cursor::recordUndo(UndoKind kind, pit_type from) const
+void Cursor::recordUndo(pit_type from) const
 {
-       buffer()->undo().recordUndo(*this, kind, from);
+       buffer()->undo().recordUndo(*this, from, pit());
 }
 
 
@@ -2494,9 +2494,16 @@ void Cursor::recordUndo(UndoKind kind) const
 }
 
 
-void Cursor::recordUndoInset(UndoKind kind, Inset const * inset) const
+void Cursor::recordUndoInset(Inset const * in) const
 {
-       buffer()->undo().recordUndoInset(*this, kind, inset);
+       if (!in || in == &inset()) {
+               CursorData c = *this;
+               c.pop_back();
+               buffer()->undo().recordUndo(c, c.pit(), c.pit());
+       } else if (in == nextInset())
+               recordUndo();
+       else
+               LYXERR0("Inset not found, no undo element added.");
 }
 
 
@@ -2520,7 +2527,7 @@ void Cursor::recordUndoSelection() const
                else
                        recordUndo();
        } else {
-               buffer()->undo().recordUndo(*this, ATOMIC_UNDO,
+               buffer()->undo().recordUndo(*this,
                        selBegin().pit(), selEnd().pit());
        }
 }
index d5b5aa43ca3c646756a745926045f6b27bb6bd94..739d228d75330a85df3ed5d351bb00629f20b43f 100644 (file)
@@ -364,18 +364,17 @@ public:
        void endUndoGroup() const;
 
        /// The general case: prepare undo for an arbitrary range.
-       void recordUndo(UndoKind kind, pit_type from, pit_type to) const;
+       void recordUndo(pit_type from, pit_type to) const;
 
        /// Convenience: prepare undo for the range between 'from' and cursor.
-       void recordUndo(UndoKind kind, pit_type from) const;
+       void recordUndo(pit_type from) const;
 
        /// Convenience: prepare undo for the single paragraph or cell
        /// containing the cursor
        void recordUndo(UndoKind kind = ATOMIC_UNDO) const;
 
        /// Convenience: prepare undo for the inset containing the cursor
-       void recordUndoInset(UndoKind kind = ATOMIC_UNDO,
-                            Inset const * inset = 0) const;
+       void recordUndoInset(Inset const * inset = 0) const;
 
        /// Convenience: prepare undo for the whole buffer
        void recordUndoFullBuffer() const;
index ead2059c0a5989778b56ed2be1fadf83469c3064..1eecee1e30443e9b068a24538508a361de7fac97 100644 (file)
@@ -1558,7 +1558,7 @@ bool Text::handleBibitems(Cursor & cur)
        // if a bibitem is deleted, merge with previous paragraph
        // if this is a bibliography item as well
        if (cur.pit() > 0 && par.layout() == prevpar.layout()) {
-               cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
+               cur.recordUndo(prevcur.pit());
                mergeParagraph(bufparams, cur.text()->paragraphs(),
                                                        prevcur.pit());
                cur.forceBufferUpdate();
@@ -1640,14 +1640,14 @@ bool Text::backspacePos0(Cursor & cur)
        // is it an empty paragraph?
        if (cur.lastpos() == 0
            || (cur.lastpos() == 1 && par.isSeparator(0))) {
-               cur.recordUndo(ATOMIC_UNDO, prevcur.pit(), cur.pit());
+               cur.recordUndo(prevcur.pit());
                plist.erase(boost::next(plist.begin(), cur.pit()));
                needsUpdate = true;
        }
        // is previous par empty?
        else if (prevcur.lastpos() == 0
                 || (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) {
-               cur.recordUndo(ATOMIC_UNDO, prevcur.pit(), cur.pit());
+               cur.recordUndo(prevcur.pit());
                plist.erase(boost::next(plist.begin(), prevcur.pit()));
                needsUpdate = true;
        }
@@ -1659,7 +1659,7 @@ bool Text::backspacePos0(Cursor & cur)
        else if (par.layout() == prevpar.layout()
                 || tclass.isDefaultLayout(par.layout())
                 || tclass.isPlainLayout(par.layout())) {
-               cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
+               cur.recordUndo(prevcur.pit());
                mergeParagraph(bufparams, plist, prevcur.pit());
                needsUpdate = true;
        }
@@ -1685,7 +1685,7 @@ bool Text::backspace(Cursor & cur)
                --prev_cur.pit();
 
                if (!prev_cur.paragraph().isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) {
-                       cur.recordUndo(ATOMIC_UNDO, prev_cur.pit(), prev_cur.pit());
+                       cur.recordUndo(prev_cur.pit(), prev_cur.pit());
                        prev_cur.paragraph().setChange(prev_cur.lastpos(), Change(Change::DELETED));
                        setCursorIntern(cur, prev_cur.pit(), prev_cur.lastpos());
                        return true;
index 7cea9dc5c100b01c76c51204b91f788bc01e1e25..7aed1655f0ce1cffa4c845fa29a18505ebf0d7b2 100644 (file)
@@ -188,11 +188,6 @@ public:
        void setCursorIntern(Cursor & cur, pit_type par,
                 pos_type pos, bool setfont = true, bool boundary = false);
 
-       ///
-       void recUndo(Cursor & cur, pit_type first, pit_type last) const;
-       ///
-       void recUndo(Cursor & cur, pit_type first) const;
-
        /// Move cursor one position backwards
        /**
         * Returns true if an update is needed after the move.
index a9e6db6b6b3ba7caf4830710b1e3828cb0a8111a..8f834e4cf0ff27255db01bc427841ecb64ad7d9a 100644 (file)
@@ -897,9 +897,8 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 
        if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
                // Delete old par.
-               old.recordUndo(ATOMIC_UNDO,
-                          max(old.pit() - 1, pit_type(0)),
-                          min(old.pit() + 1, old.lastpit()));
+               old.recordUndo(max(old.pit() - 1, pit_type(0)),
+                              min(old.pit() + 1, old.lastpit()));
                ParagraphList & plist = old.text()->paragraphs();
                bool const soa = oldpar.params().startOfAppendix();
                plist.erase(boost::next(plist.begin(), old.pit()));
@@ -977,15 +976,4 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool tra
 }
 
 
-void Text::recUndo(Cursor & cur, pit_type first, pit_type last) const
-{
-       cur.recordUndo(ATOMIC_UNDO, first, last);
-}
-
-
-void Text::recUndo(Cursor & cur, pit_type par) const
-{
-       cur.recordUndo(ATOMIC_UNDO, par, par);
-}
-
 } // namespace lyx
index 1584b9660712a59b2258a26993212114b7a0fd83..517998bef60273843b0b266fe8105c30bf2a25c6 100644 (file)
@@ -381,7 +381,7 @@ static void outline(OutlineOp mode, Cursor & cur)
                        pit_type const newpit = distance(bgn, dest);
                        pit_type const len = distance(start, finish);
                        pit_type const deletepit = pit + len;
-                       buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
+                       buf.undo().recordUndo(cur, newpit, deletepit - 1);
                        pars.splice(dest, start, finish);
                        cur.pit() = newpit;
                        break;
@@ -401,7 +401,7 @@ static void outline(OutlineOp mode, Cursor & cur)
                        }
                        // One such was found:
                        pit_type newpit = distance(bgn, dest);
-                       buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
+                       buf.undo().recordUndo(cur, pit, newpit - 1);
                        pit_type const len = distance(start, finish);
                        pars.splice(dest, start, finish);
                        cur.pit() = newpit - len;
@@ -410,7 +410,7 @@ static void outline(OutlineOp mode, Cursor & cur)
                case OutlineIn:
                case OutlineOut: {
                        pit_type const len = distance(start, finish);
-                       buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
+                       buf.undo().recordUndo(cur, pit, pit + len - 1);
                        for (; start != finish; ++start) {
                                toclevel = buf.text().getTocLevel(distance(bgn, start));
                                if (toclevel == Layout::NOT_IN_TOC)
@@ -496,7 +496,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_PARAGRAPH_MOVE_DOWN: {
                pit_type const pit = cur.pit();
-               recUndo(cur, pit, pit + 1);
+               cur.recordUndo(pit, pit + 1);
                cur.finishUndo();
                pars_.swap(pit, pit + 1);
                needsUpdate = true;
@@ -507,7 +507,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_PARAGRAPH_MOVE_UP: {
                pit_type const pit = cur.pit();
-               recUndo(cur, pit - 1, pit);
+               cur.recordUndo(pit - 1, pit);
                cur.finishUndo();
                pars_.swap(pit, pit - 1);
                --cur.pit();
@@ -526,7 +526,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // FIXME: this don't work for multipart document!
                for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
                        if (pars_[tmp].params().startOfAppendix()) {
-                               recUndo(cur, tmp);
+                               cur.recordUndo(tmp, tmp);
                                pars_[tmp].params().startOfAppendix(false);
                                break;
                        }
index 33baa8cafd0940c49d3dd1bb9fd6ed94489cd73e..479e73091489b7859dded739281bd3e512b19f71 100644 (file)
@@ -385,7 +385,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                Cursor & cur = const_cast<Cursor &>(bv_->cursor());
                // In some cases, we do not know how to record undo
                if (&cur.inset() == &text_->inset())
-                       cur.recordUndo(ATOMIC_UNDO, pit, pit);
+                       cur.recordUndo(pit, pit);
 
                int const moveCursor = par.fixBiblio(buffer);
 
index 7a5b1761f278029bc08607b6e6c302d19efa19a4..95eb160d60c9c19494cf3646fac858b90964db48 100644 (file)
@@ -575,40 +575,15 @@ void Undo::endUndoGroup(CursorData const & cur)
 }
 
 
-// FIXME: remove these convenience functions and make
-// Private::recordUndo public as sole interface. The code in the
-// convenience functions can move to Cursor.cpp.
-
 void Undo::recordUndo(CursorData const & cur, UndoKind kind)
 {
        d->recordUndo(kind, cur, cur.pit(), cur.pit(), cur);
 }
 
 
-void Undo::recordUndoInset(CursorData const & cur, UndoKind kind,
-                          Inset const * inset)
-{
-       if (!inset || inset == &cur.inset()) {
-               DocIterator c = cur;
-               c.pop_back();
-               d->recordUndo(kind, c, c.pit(), c.pit(), cur);
-       } else if (inset == cur.nextInset())
-               recordUndo(cur, kind);
-       else
-               LYXERR0("Inset not found, no undo stack added.");
-}
-
-
-void Undo::recordUndo(CursorData const & cur, UndoKind kind, pit_type from)
-{
-       d->recordUndo(kind, cur, cur.pit(), from, cur);
-}
-
-
-void Undo::recordUndo(CursorData const & cur, UndoKind kind,
-       pit_type from, pit_type to)
+void Undo::recordUndo(CursorData const & cur, pit_type from, pit_type to)
 {
-       d->recordUndo(kind, cur, from, to, cur);
+       d->recordUndo(ATOMIC_UNDO, cur, from, to, cur);
 }
 
 
index 300ef6bbbb0cca0c5d9f07579a524c47e625e2ae..789de5f39f69209dd6bae6cf8e0c51e47b035d94 100644 (file)
@@ -94,24 +94,14 @@ public:
         * give an inclusive range. This is called before you make the
         * changes to the paragraph, and it will record the original
         * information of the paragraphs in the undo stack.
+        * Kind of undo is always ATOMIC_UNDO.
         */
-       void recordUndo(CursorData const & cur, UndoKind kind,
-               pit_type from, pit_type to);
-
-       /// Convenience: record undo information for the range between
-       /// 'from' and cursor.
-       void recordUndo(CursorData const & cur, UndoKind kind, pit_type from);
+       void recordUndo(CursorData const & cur, pit_type from, pit_type to);
 
        /// Convenience: record undo information for the single
        /// paragraph or cell containing the cursor.
        void recordUndo(CursorData const & cur, UndoKind kind = ATOMIC_UNDO);
 
-       /// Convenience: record undo information for the inset
-       /// containing the cursor.
-       void recordUndoInset(CursorData const & cur,
-                            UndoKind kind = ATOMIC_UNDO,
-                            Inset const * inset = 0);
-
        /// Convenience: record undo for buffer parameters
        void recordUndoBufferParams(CursorData const & cur);
 
index 4c27323235cd92982a37637ae735009ba8dd4f26..26aa2f3754c16bdaf8f0c5c23b0381acef5e0f2e 100644 (file)
@@ -148,7 +148,7 @@ void InsetArgument::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.undispatched();
                        return;
                }
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                name_ = cmd.getArg(1);
                cur.forceBufferUpdate();
                break;
index 75498ad2e59173aaca6d33b3528c3d3dfa8cffb4..ddb1dce1ddad66612d33b0ea51aa686b3f9bfd18 100644 (file)
@@ -221,7 +221,7 @@ void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.undispatched();
                        return;
                }
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                if (change_type)
                        params_.type = cmd.getArg(1);
                else // if (for_box)
index 9743208e587cf6132ae9334e058810c0464ad6ca..13ed53aed90722b301533196aa2e5556477c1112 100644 (file)
@@ -132,7 +132,7 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetBranchParams params;
                InsetBranch::string2params(to_utf8(cmd.argument()), params);
 
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                params_.branch = params.branch;
                // what we really want here is a TOC update, but that means
                // a full buffer update
index e9642396255977311c11c7269eb1ae5ea3480234..2465e7a7279bc3d0ee71d12bae6604bd0800d3b2 100644 (file)
@@ -197,7 +197,7 @@ void InsetCaption::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                if (cmd.getArg(0) == "changetype") {
-                       cur.recordUndoInset(ATOMIC_UNDO, this);
+                       cur.recordUndoInset(this);
                        type_ = cmd.getArg(1);
                        cur.forceBufferUpdate();
                        break;
index eb9a808fbf733e028bf82e031e02150005227967..ce9d3834d2b74d3e5c20394ccdfcac7ecad721de 100644 (file)
@@ -111,7 +111,7 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
        case LFUN_INSET_MODIFY:
                if (cmd.getArg(0) == "ert") {
-                       cur.recordUndoInset(ATOMIC_UNDO, this);
+                       cur.recordUndoInset(this);
                        setStatus(cur, string2params(to_utf8(cmd.argument())));
                        break;
                }
index 0b6ed66fd99e24b3c2a02ffa540e53fb70128ee7..a79affc0c302be9102a3cdd0acb6c059e723d43d 100644 (file)
@@ -142,7 +142,7 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_INSET_MODIFY: {
                InsetFloatParams params;
                string2params(to_utf8(cmd.argument()), params);
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
 
                // placement, wide and sideways are not used for subfloats
                if (!params_.subfloat) {
index 9db1aca4dde3c485400b925f47ed587526754a2b..a2539b00d77b6e629a7ce8ea8462e9016469349f 100644 (file)
@@ -200,13 +200,13 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                if (cmd.getArg(0) == "changetype") {
-                       cur.recordUndoInset(ATOMIC_UNDO, this);
+                       cur.recordUndoInset(this);
                        params_.index = from_utf8(cmd.getArg(1));
                        break;
                }
                InsetIndexParams params;
                InsetIndex::string2params(to_utf8(cmd.argument()), params);
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                params_.index = params.index;
                // what we really want here is a TOC update, but that means
                // a full buffer update
index f6b699b4a8051de74fc05d1047dc6b0f37be3056..99645e78d5f55777792c5ffa3b4fa795e32baa6a 100644 (file)
@@ -324,7 +324,7 @@ void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                InsetListings::string2params(to_utf8(cmd.argument()), params());
                break;
        }
index 37055027862167ce14776f1b327c751b17d2dcce..a80e1be2300fd49c7c0368861c8fd3daa0893330 100644 (file)
@@ -161,7 +161,7 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
                if (params_.type == params.type)
                  break;
 
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                string2params(to_utf8(cmd.argument()), params_);
                setButtonLabel();
                // what we really want here is a TOC update, but that means
index 040c596b8d69e6daea5fd716c05ea50765797025..06365d680b6a9ce653249af46c9c5a9ddba7f4bf 100644 (file)
@@ -261,7 +261,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                string2params(to_utf8(cmd.argument()), params_);
                setButtonLabel();
                cur.forceBufferUpdate();
index 35c181fbe9ea211e5fcbb58fdb411f153050810f..a85444784f1c636e44c3e7493fb3599cc6c5dc60 100644 (file)
@@ -216,7 +216,7 @@ void InsetScript::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action()) {
        case LFUN_INSET_MODIFY:
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                string2params(to_utf8(cmd.argument()), params_);
                break;
        default:
index b0f9576476aec3ae13db889a7e23816f2e1c56d7..1bf349de5222bb00c08a22a43c086ea1b1203d5f 100644 (file)
@@ -5421,7 +5421,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                break;
        }
 
-       cur.recordUndoInset(ATOMIC_UNDO, this);
+       cur.recordUndoInset(this);
 
        getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
        row_type const row = tabular.cellRow(cur.idx());
index d86fc25c3d43a2f35de0b288a34dbc02b6555d78..cfe887033dd5c5446e96c6a0cedc344b24418c72 100644 (file)
@@ -82,7 +82,7 @@ void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action()) {
        case LFUN_INSET_MODIFY: {
-               cur.recordUndoInset(ATOMIC_UNDO, this);
+               cur.recordUndoInset(this);
                InsetWrapParams params;
                InsetWrap::string2params(to_utf8(cmd.argument()), params);
                params_.lines = params.lines;