]> git.lyx.org Git - lyx.git/commitdiff
Add LFUN_NOTES_MUTATE for global change of note insets type.
authorPavel Sanda <sanda@lyx.org>
Wed, 18 Jun 2008 18:16:50 +0000 (18:16 +0000)
committerPavel Sanda <sanda@lyx.org>
Wed, 18 Jun 2008 18:16:50 +0000 (18:16 +0000)
http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg141339.html

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25306 a592a061-630c-0410-9148-cb99ea01b6c8

src/FuncCode.h
src/LyXAction.cpp
src/LyXFunc.cpp
src/insets/InsetNote.cpp
src/insets/InsetNote.h

index 9af6daea29905e76dffc4b6e11b5aae3ec362d99..021d2091d8298b49c0ee00291cfd9495626191c3 100644 (file)
@@ -166,6 +166,7 @@ enum FuncCode
        LFUN_WORD_DELETE_FORWARD,
        LFUN_WORD_DELETE_BACKWARD,
        LFUN_LINE_DELETE,
        LFUN_WORD_DELETE_FORWARD,
        LFUN_WORD_DELETE_BACKWARD,
        LFUN_LINE_DELETE,
+       LFUN_NOTES_MUTATE,
        // 115
        LFUN_MARK_OFF,
        LFUN_MARK_ON,
        // 115
        LFUN_MARK_OFF,
        LFUN_MARK_ON,
index 223cbf57f57d09c99145783ab7f10c1969ae00a7..e6a998461430cede406a47d1a08c0a9adf7b18bd 100644 (file)
@@ -532,6 +532,16 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_NOTE_NEXT, "note-next", ReadOnly, Edit },
  * \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.
 /*!
  * \var lyx::FuncCode lyx::LFUN_NEWLINE_INSERT
  * \li Action: Inserts a line break or new line.
index ad802c7c2ca60862dbb5aa67b771cea5000c41b8..5a926eca4f5dbf5ffb38df739d445e982af2bebb 100644 (file)
@@ -583,6 +583,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_INSET_EDIT:
        case LFUN_ALL_INSETS_TOGGLE:
        case LFUN_GRAPHICS_GROUPS_UNIFY:
        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:
        case LFUN_BUFFER_LANGUAGE:
        case LFUN_TEXTCLASS_APPLY:
        case LFUN_TEXTCLASS_LOAD:
@@ -1416,6 +1417,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
                        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();
                case LFUN_BUFFER_LANGUAGE: {
                        LASSERT(lyx_view_, /**/);
                        Buffer & buffer = *lyx_view_->buffer();
index 92c44eec175507156d4d5e7b7d623ffe8831424b..14701429bfa11001026abdce7df43e61392bfc0b 100644 (file)
@@ -24,7 +24,7 @@
 #include "Exporter.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #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 "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
@@ -35,6 +35,7 @@
 
 #include "support/debug.h"
 #include "support/docstream.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/Translator.h"
 
 #include "frontends/Application.h"
 #include "support/Translator.h"
 
 #include "frontends/Application.h"
@@ -369,5 +370,34 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params)
        params.read(lex);
 }
 
        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
 
 } // namespace lyx
index d588f011aa7c558d905991235fc4dd119407c60f..70faf4c03df691be7fe3c2b8d8682684eaaba266 100644 (file)
@@ -111,6 +111,13 @@ private:
        InsetNoteParams params_;
 };
 
        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
 
 
 } // namespace lyx