LFUN_WORD_DELETE_FORWARD,
LFUN_WORD_DELETE_BACKWARD,
LFUN_LINE_DELETE,
+ LFUN_NOTES_MUTATE,
// 115
LFUN_MARK_OFF,
LFUN_MARK_ON,
* \endvar
*/
{ LFUN_NOTE_NEXT, "note-next", ReadOnly, Edit },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_NOTES_MUTATE
+ * \li Action: Changes all Note insets of a particular type (source)
+ to a different type (target) fot the current document.
+ * \li Syntax: notes-mutate <SOURCE> <TARGET>
+ * \li Params: <SOURCE/TARGET>: Note|Comment|Greyedout
+ * \li Origin: ps, 18 Jun 2008
+ * \endvar
+ */
+ { LFUN_NOTES_MUTATE, "notes-mutate", ReadOnly, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_NEWLINE_INSERT
* \li Action: Inserts a line break or new line.
case LFUN_INSET_EDIT:
case LFUN_ALL_INSETS_TOGGLE:
case LFUN_GRAPHICS_GROUPS_UNIFY:
+ case LFUN_NOTES_MUTATE:
case LFUN_BUFFER_LANGUAGE:
case LFUN_TEXTCLASS_APPLY:
case LFUN_TEXTCLASS_LOAD:
break;
}
+ // BOTH GRAPHICS_GROUPS_UNIFY and NOTES_MUTATE should be in Buffer dispatch once
+ // view->cursor() is not needed.
+ // Also they could be rewriten using some command like forall <insetname> <command>
+ // once the insets refactoring is done.
+ case LFUN_NOTES_MUTATE: {
+ LASSERT(lyx_view_ && lyx_view_->view(), /**/);
+ if (argument.empty() || !lyx_view_->buffer())
+ break;
+ view()->cursor().recordUndoFullDocument();
+
+ if (mutateNotes(view(), cmd.getArg(0), cmd.getArg(1))) {
+ lyx_view_->buffer()->markDirty();
+ updateFlags = Update::Force | Update::FitCursor;
+ }
+ break;
+ }
+
case LFUN_BUFFER_LANGUAGE: {
LASSERT(lyx_view_, /**/);
Buffer & buffer = *lyx_view_->buffer();
#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"
#include "support/debug.h"
#include "support/docstream.h"
+#include "support/gettext.h"
#include "support/Translator.h"
#include "frontends/Application.h"
params.read(lex);
}
+bool mutateNotes(lyx::BufferView * view, 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;
+
+ Inset & inset = view->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) {
+ FuncRequest fr(LFUN_INSET_MODIFY, "note Note " + target);
+ ins.dispatch(view->cursor(), fr);
+ ret = true;
+ }
+ }
+ }
+
+ return ret;
+}
} // namespace lyx
InsetNoteParams params_;
};
+class BufferView;
+
+/**
+ * Mutate all NoteInsets of "source" type to the "target" type in the document.
+ * Returns true when some inset was changed.
+ */
+bool mutateNotes(lyx::BufferView * view, std::string const & source, std::string const &target);
} // namespace lyx