]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNote.cpp
Inset::addToToc(): change signature. Use DocIterator instead of ParConstIterator...
[lyx.git] / src / insets / InsetNote.cpp
index 4c11a1e89e8f3c710cb6ff826f7d42bca514197e..c8dededc59efd2b55677973ab1e85fc4de771cff 100644 (file)
@@ -37,6 +37,8 @@
 #include "support/docstream.h"
 #include "support/Translator.h"
 
+#include "frontends/Application.h"
+
 #include <algorithm>
 #include <sstream>
 
@@ -106,27 +108,22 @@ void InsetNoteParams::read(Lexer & lex)
 }
 
 
-InsetNote::InsetNote(BufferParams const & bp, string const & label)
-       : InsetCollapsable(bp)
+/////////////////////////////////////////////////////////////////////
+//
+// InsetNode
+//
+/////////////////////////////////////////////////////////////////////
+
+InsetNote::InsetNote(Buffer const & buf, string const & label)
+       : InsetCollapsable(buf)
 {
        params_.type = notetranslator().find(label);
 }
 
 
-InsetNote::InsetNote(InsetNote const & in)
-       : InsetCollapsable(in), params_(in.params_)
-{}
-
-
 InsetNote::~InsetNote()
 {
-       InsetNoteMailer(*this).hideDialog();
-}
-
-
-Inset * InsetNote::clone() const
-{
-       return new InsetNote(*this);
+       hideDialogs("note", this);
 }
 
 
@@ -171,7 +168,8 @@ void InsetNote::setButtonLabel()
 
 bool InsetNote::showInsetDialog(BufferView * bv) const
 {
-       InsetNoteMailer(const_cast<InsetNote &>(*this)).showDialog(bv);
+       bv->showDialog("note", params2string(params()),
+               const_cast<InsetNote *>(this));
        return true;
 }
 
@@ -181,14 +179,15 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY:
-               InsetNoteMailer::string2params(to_utf8(cmd.argument()), params_);
+               string2params(to_utf8(cmd.argument()), params_);
                // get a bp from cur:
                setLayout(cur.buffer().params());
                break;
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetNoteMailer(*this).updateDialog(&cur.bv());
+               cur.bv().updateDialog("note", params2string(params()));
                break;
+
        default:
                InsetCollapsable::doDispatch(cur, cmd);
                break;
@@ -202,6 +201,16 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY:
+               // disallow comment and greyed out in commands
+               flag.enabled(!cur.paragraph().layout().isCommand() ||
+                               cmd.getArg(2) == "Note");
+               if (cmd.getArg(0) == "note") {
+                       InsetNoteParams params;
+                       string2params(to_utf8(cmd.argument()), params);
+                       flag.setOnOff(params_.type == params.type);
+               }
+               return true;
+
        case LFUN_INSET_DIALOG_UPDATE:
                flag.enabled(true);
                return true;
@@ -211,19 +220,11 @@ 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;
@@ -335,31 +336,22 @@ void InsetNote::validate(LaTeXFeatures & features) const
 }
 
 
-
-string const InsetNoteMailer::name_("note");
-
-InsetNoteMailer::InsetNoteMailer(InsetNote & inset)
-       : inset_(inset)
-{}
-
-
-string const InsetNoteMailer::inset2string(Buffer const &) const
+docstring InsetNote::contextMenu(BufferView const &, int, int) const
 {
-       return params2string(inset_.params());
+       return from_ascii("context-note");
 }
 
 
-string const InsetNoteMailer::params2string(InsetNoteParams const & params)
+string InsetNote::params2string(InsetNoteParams const & params)
 {
        ostringstream data;
-       data << name_ << ' ';
+       data << "note" << ' ';
        params.write(data);
        return data.str();
 }
 
 
-void InsetNoteMailer::string2params(string const & in,
-                                   InsetNoteParams & params)
+void InsetNote::string2params(string const & in, InsetNoteParams & params)
 {
        params = InsetNoteParams();
 
@@ -367,20 +359,10 @@ void InsetNoteMailer::string2params(string const & in,
                return;
 
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
-
-       string name;
-       lex >> name;
-       if (!lex || name != name_)
-               return print_mailer_error("InsetNoteMailer", in, 1, name_);
-
-       // This is part of the inset proper that is usually swallowed
-       // by Text::readInset
-       string id;
-       lex >> id;
-       if (!lex || id != "Note")
-               return print_mailer_error("InsetBoxMailer", in, 2, "Note");
+       lex.setContext("InsetNote::string2params");
+       lex >> "note" >> "Note";
 
        params.read(lex);
 }