From e5376bd800619b84d24467407ea37e8b0782cc9b Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 23 Dec 2009 14:27:43 +0000 Subject: [PATCH] another bad binding related to ticket #6416 (see r32619) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32620 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/bind/aqua.bind | 2 +- src/BufferView.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/FuncCode.h | 1 + src/LyXAction.cpp | 21 ++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/lib/bind/aqua.bind b/lib/bind/aqua.bind index bf138716ab..319dc829b8 100644 --- a/lib/bind/aqua.bind +++ b/lib/bind/aqua.bind @@ -32,7 +32,7 @@ \bind "M-~S-i s l" "newline-insert newline" \bind "M-~S-i s r" "newline-insert linebreak" \bind "M-~S-i s i" "specialchar-insert dots" -\bind "M-~S-i s e" "specialchar-insert end-of-sentence-period" +\bind "M-~S-i s e" "specialchar-insert end-of-sentence" \bind "M-~S-i s q" "self-insert \"" # FIXME: find a binding for single quotes # \bind "M-~S-i s q" "quote-insert single" diff --git a/src/BufferView.cpp b/src/BufferView.cpp index cb06810f7a..a207abd936 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1090,6 +1090,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) case LFUN_SCROLL: case LFUN_SCREEN_UP_SELECT: case LFUN_SCREEN_DOWN_SELECT: + case LFUN_INSET_FORALL: flag.setEnabled(true); break; @@ -1729,6 +1730,53 @@ bool BufferView::dispatch(FuncRequest const & cmd) break; } + + // This would be in Buffer class if only Cursor did not + // require a bufferview + case LFUN_INSET_FORALL: { + docstring const name = from_utf8(cmd.getArg(0)); + string const commandstr = cmd.getLongArg(1); + FuncRequest const fr = lyxaction.lookupFunc(commandstr); + + // an arbitrary number to limit number of iterations + const int max_iter = 1000; + int iterations = 0; + Cursor & cur = d->cursor_; + cur.reset(); + if (!cur.nextInset()) + cur.forwardInset(); + cur.beginUndoGroup(); + while(cur && iterations < max_iter) { + Inset * ins = cur.nextInset(); + if (!ins) + break; + docstring insname = ins->name(); + while (!insname.empty()) { + if (insname == name || name == from_utf8("*")) { + cur.recordUndo(); + lyx::dispatch(fr); + ++iterations; + break; + } + size_t const i = insname.rfind(':'); + if (i == string::npos) + break; + insname = insname.substr(0, i); + } + cur.forwardInset(); + } + cur.endUndoGroup(); + cur.reset(); + processUpdateFlags(Update::Force); + + if (iterations >= max_iter) + cur.errorMessage(bformat(_("inset-forall interrupted because number of actions is larger than %1$s"), max_iter)); + else + cur.message(bformat(_("Applied \"%1$s\" to %2$d insets"), from_utf8(commandstr), iterations)); + break; + } + + case LFUN_ALL_INSETS_TOGGLE: { string action; string const name = split(to_utf8(cmd.argument()), action, ' '); diff --git a/src/FuncCode.h b/src/FuncCode.h index 65f602c3fb..7324c2bf5c 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -443,6 +443,7 @@ enum FuncCode LFUN_GRAPHICS_RELOAD, // vfr 20090810 LFUN_SCREEN_SHOW_CURSOR, // vfr, 20090325 LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE, // ARRae 971202 + LFUN_INSET_FORALL, // lasgouttes, 20091127 LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index d2d9d75700..d975eb5c5b 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3434,6 +3434,27 @@ void LyXAction::init() { LFUN_GRAPHICS_RELOAD, "graphics-reload", ReadOnly | AtPoint, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_INSET_FORALL + + * \li Action: Apply the given commands on insets of a given name. WARNING: use + at your own risks; this function gives you too many ways of + shooting yourself in the foot. A typical example is + inset-forall Note note-insert + which starts an infinite loop. This is mitigated by the fact + that the number of actions is arbitrarily limited to 1000. + * \li Syntax: inset-forall + If is *, all insets are matched. + * \li Sample: The name is used like for InsetLayout in layout files: "Note" + matches all note insets, while "Note:Note" only matches LyX + yellow note insets. The following command closes all note insets + inset-forall Note inset-toggle close + * \li Origin: lasgouttes, 27 Nov 2009 + * \endvar + */ + { LFUN_INSET_FORALL, "inset-forall", ReadOnly, Edit }, + + { LFUN_NOACTION, "", Noop, Hidden } #ifndef DOXYGEN_SHOULD_SKIP_THIS };