X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetNote.cpp;h=5431712447862e4eb43b5756321217729f5a89f8;hb=d6f1915684328c6e3fe61c6eef8846b5cabec334;hp=c764f801ee9ea5494587160c56ee4e395f80dbc9;hpb=11a0458d3f66bce83b90e23f1c85175a8ffcae45;p=lyx.git diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index c764f801ee..5431712447 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -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); } @@ -370,25 +364,43 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params) istringstream data(in); 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(*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