mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Add LFUN_NOTES_MUTATE for global change of note insets type.
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
This commit is contained in:
parent
a7de101b64
commit
1f1951e210
@ -166,6 +166,7 @@ enum FuncCode
|
||||
LFUN_WORD_DELETE_FORWARD,
|
||||
LFUN_WORD_DELETE_BACKWARD,
|
||||
LFUN_LINE_DELETE,
|
||||
LFUN_NOTES_MUTATE,
|
||||
// 115
|
||||
LFUN_MARK_OFF,
|
||||
LFUN_MARK_ON,
|
||||
|
@ -532,6 +532,16 @@ void LyXAction::init()
|
||||
* \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.
|
||||
|
@ -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_NOTES_MUTATE:
|
||||
case LFUN_BUFFER_LANGUAGE:
|
||||
case LFUN_TEXTCLASS_APPLY:
|
||||
case LFUN_TEXTCLASS_LOAD:
|
||||
@ -1416,6 +1417,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
||||
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();
|
||||
|
@ -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"
|
||||
@ -369,5 +370,34 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params)
|
||||
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
|
||||
|
@ -111,6 +111,13 @@ private:
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user