]> 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 c8dededc59efd2b55677973ab1e85fc4de771cff..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:
@@ -231,6 +232,8 @@ void InsetNote::addToToc(DocIterator const & cpit)
        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);
 }
 
 
@@ -367,5 +370,37 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params)
        params.read(lex);
 }
 
+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();
+
+       return ret;
+}
 
 } // namespace lyx