]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetLabel.cpp
This optional argument to the InsetCollapsable constructor
[lyx.git] / src / insets / InsetLabel.cpp
index 57ec16ad9f09102e95dd58cc5fc0b0331659f88d..6a3be71a0205118378ba7de4ea5bcb578faf30e3 100644 (file)
@@ -28,9 +28,9 @@
 #include "frontends/alert.h"
 
 #include "support/convert.h"
-#include "support/lyxalgo.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
+#include "support/lyxalgo.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -43,13 +43,13 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
 {}
 
 
-void InsetLabel::validate()
+void InsetLabel::initView()
 {
-       update(getParam("name"));
+       updateCommand(getParam("name"));
 }
 
 
-void InsetLabel::update(docstring const & new_label, bool updaterefs)
+void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
 {
        docstring const old_label = getParam("name");
        docstring label = new_label;
@@ -66,15 +66,19 @@ void InsetLabel::update(docstring const & new_label, bool updaterefs)
                        "it will be changed to %2$s."), new_label, label));
        }
 
+       buffer().undo().beginUndoGroup();
        setParam("name", label);
 
        if (updaterefs) {
                Buffer::References & refs = buffer().references(old_label);
                Buffer::References::iterator it = refs.begin();
                Buffer::References::iterator end = refs.end();
-               for (; it != end; ++it)
+               for (; it != end; ++it) {
+                       buffer().undo().recordUndo(it->second);
                        it->first->setParam("reference", label);
+               }
        }
+       buffer().undo().endUndoGroup();
 
        // We need an update of the Buffer reference cache. This is achieved by
        // updateLabel().
@@ -92,12 +96,6 @@ ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
 }
 
 
-void InsetLabel::getLabelList(vector<docstring> & list) const
-{
-       list.push_back(getParam("name"));
-}
-
-
 docstring InsetLabel::screenLabel() const
 {
        return screen_label_;
@@ -117,7 +115,7 @@ void InsetLabel::updateLabels(ParIterator const &)
 }
 
 
-void InsetLabel::addToToc(ParConstIterator const & cpit) const
+void InsetLabel::addToToc(DocIterator const & cpit)
 {
        docstring const & label = getParam("name");
        Toc & toc = buffer().tocBackend().toc("label");
@@ -130,7 +128,7 @@ void InsetLabel::addToToc(ParConstIterator const & cpit) const
        Buffer::References::const_iterator it = refs.begin();
        Buffer::References::const_iterator end = refs.end();
        for (; it != end; ++it) {
-               ParConstIterator const ref_pit(it->second);
+               DocIterator const ref_pit(it->second);
                toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
        }
 }
@@ -143,12 +141,12 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p(LABEL_CODE);
                // FIXME UNICODE
-               InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
+               InsetCommand::string2params("label", to_utf8(cmd.argument()), p);
                if (p.getCmdName().empty()) {
                        cur.noUpdate();
                        break;
                }
-               update(p["name"]);
+               updateCommand(p["name"]);
                break;
        }