]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetLabel.cpp
revert r37459 and add a note to the sources:
[lyx.git] / src / insets / InsetLabel.cpp
index 5217dffd1aad3d0aae47b6a1c41457d7ed5e3e26..6f2e9f59ce295f7f0c22050dcc22e4842e419647 100644 (file)
@@ -49,7 +49,7 @@ namespace lyx {
 
 
 InsetLabel::InsetLabel(Buffer * buf, InsetCommandParams const & p)
-       : InsetCommand(buf, p, "label")
+       : InsetCommand(buf, p)
 {}
 
 
@@ -86,12 +86,10 @@ void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
                for (; it != end; ++it) {
                        buffer().undo().recordUndo(it->second);
                        if (it->first->lyxCode() == MATH_REF_CODE) {
-                               InsetMathHull * mi =
-                                       static_cast<InsetMathHull *>(it->first);
+                               InsetMathHull * mi = it->first->asInsetMath()->asHullInset();
                                mi->asRefInset()->changeTarget(label);
                        } else {
-                               InsetCommand * ref =
-                                       static_cast<InsetCommand *>(it->first);
+                               InsetCommand * ref = it->first->asInsetCommand();
                                ref->setParam("reference", label);
                        }
                }
@@ -127,7 +125,7 @@ void InsetLabel::updateBuffer(ParIterator const & par, UpdateType utype)
        buffer().setInsetLabel(label, this);
        screen_label_ = label;
 
-       if (utype) {
+       if (utype == OutputUpdate) {
                // save info on the active counter
                Counters const & cnts = 
                        buffer().masterBuffer()->params().documentClass().counters();
@@ -137,14 +135,14 @@ void InsetLabel::updateBuffer(ParIterator const & par, UpdateType utype)
                        counter_value_ = cnts.theCounter(active_counter_, lang->code());
                        pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code());
                } else {
-                       counter_value_ = from_ascii("??");
-                       pretty_counter_ = from_ascii("??");
+                       counter_value_ = from_ascii("#");
+                       pretty_counter_ = from_ascii("#");
                }
        }
 }
 
 
-void InsetLabel::addToToc(DocIterator const & cpit)
+void InsetLabel::addToToc(DocIterator const & cpit) const
 {
        docstring const & label = getParam("name");
        Toc & toc = buffer().tocBackend().toc("label");
@@ -160,8 +158,7 @@ void InsetLabel::addToToc(DocIterator const & cpit)
                DocIterator const ref_pit(it->second);
                if (it->first->lyxCode() == MATH_REF_CODE)
                        toc.push_back(TocItem(ref_pit, 1,
-                               static_cast<InsetMathHull *>(it->first)->asRefInset()
-                                       ->screenLabel()));
+                               it->first->asInsetMath()->asRefInset()->screenLabel()));
                else
                        toc.push_back(TocItem(ref_pit, 1,
                                static_cast<InsetRef *>(it->first)->screenLabel()));
@@ -194,13 +191,15 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_INSET_MODIFY: {
                InsetCommandParams p(LABEL_CODE);
                // FIXME UNICODE
-               InsetCommand::string2params("label", to_utf8(cmd.argument()), p);
+               InsetCommand::string2params(to_utf8(cmd.argument()), p);
                if (p.getCmdName().empty()) {
                        cur.noScreenUpdate();
                        break;
                }
-               if (p["name"] != params()["name"])
+               if (p["name"] != params()["name"]) {
+                       // undo is handled in updateCommand
                        updateCommand(p["name"]);
+               }
                cur.forceBufferUpdate();
                break;
        }
@@ -216,7 +215,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_LABEL_INSERT_AS_REF: {
                InsetCommandParams p(REF_CODE, "ref");
                p["reference"] = getParam("name");
-               string const data = InsetCommand::params2string("ref", p);
+               string const data = InsetCommand::params2string(p);
                lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
                break;
        }