]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNote.cpp
This optional argument to the InsetCollapsable constructor
[lyx.git] / src / insets / InsetNote.cpp
index 85aa740bc1aaa391b6d682f7117113f0ca836199..5431712447862e4eb43b5756321217729f5a89f8 100644 (file)
@@ -24,7 +24,7 @@
 #include "Exporter.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "support/gettext.h"
+#include "InsetIterator.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
@@ -35,6 +35,7 @@
 
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/Translator.h"
 
 #include "frontends/Application.h"
@@ -202,7 +203,7 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_INSET_MODIFY:
                // disallow comment and greyed out in commands
-               flag.enabled(!cur.paragraph().layout().isCommand() ||
+               flag.setEnabled(!cur.paragraph().layout().isCommand() ||
                                cmd.getArg(2) == "Note");
                if (cmd.getArg(0) == "note") {
                        InsetNoteParams params;
@@ -212,7 +213,7 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
                return true;
 
        case LFUN_INSET_DIALOG_UPDATE:
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        default:
@@ -221,25 +222,18 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetNote::updateLabels(ParIterator const & it)
-{
-       DocumentClass const & tclass = buffer().params().documentClass();
-       Counters savecnt = tclass.counters();
-       InsetCollapsable::updateLabels(it);
-       tclass.counters() = savecnt;
-}
-
-
-void InsetNote::addToToc(ParConstIterator const & cpit) const
+void InsetNote::addToToc(DocIterator const & cpit)
 {
-       ParConstIterator pit = cpit;
-       pit.push_back(*this);
+       DocIterator pit = cpit;
+       pit.push_back(CursorSlice(*this));
 
        Toc & toc = buffer().tocBackend().toc("note");
        docstring str;
        str = notetranslator_loc().find(params_.type) + from_ascii(": ")
                + getNewLabel(str);
        toc.push_back(TocItem(pit, 0, str));
+       // Proceed with the rest of the inset.
+       InsetCollapsable::addToToc(cpit);
 }
 
 
@@ -368,27 +362,45 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params)
                return;
 
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
+       lex.setContext("InsetNote::string2params");
+       lex >> "note" >> "Note";
 
-       string name;
-       lex >> name;
-       if (!lex || name != "note") {
-               LYXERR0("Expected arg 1 to be \"note\" in " << in);
-               return;
-       }
+       params.read(lex);
+}
 
-       // This is part of the inset proper that is usually swallowed
-       // by Text::readInset
-       string id;
-       lex >> id;
-       if (!lex || id != "Note") {
-               LYXERR0("Expected arg 1 to be \"Note\" in " << in);
-               return;
+bool mutateNotes(Cursor & cur, string const & source, string const &target)
+{
+       InsetNoteParams::Type typeSrc = notetranslator().find(source);
+       InsetNoteParams::Type typeTrt = notetranslator().find(target);
+       // syntax check of arguments
+       string sSrc = notetranslator().find(typeSrc);
+       string sTrt = notetranslator().find(typeTrt);
+       if ((sSrc != source) || (sTrt != target))
+               return false;
+
+       // did we found some conforming inset?
+       bool ret = false;
+
+       cur.beginUndoGroup();
+       Inset & inset = cur.buffer().inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it) {
+               if (it->lyxCode() == NOTE_CODE) {
+                       InsetNote & ins = static_cast<InsetNote &>(*it);
+                       if (ins.params().type == typeSrc) {
+                               cur.buffer().undo().recordUndo(it);
+                               FuncRequest fr(LFUN_INSET_MODIFY, "note Note " + target);
+                               ins.dispatch(cur, fr);
+                               ret = true;
+                       }
+               }
        }
+       cur.endUndoGroup();
 
-       params.read(lex);
+       return ret;
 }
 
-
 } // namespace lyx