From 6576aed3d52f3e2ea58db2789c52acdff24fbe02 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 24 Sep 2008 15:08:46 +0000 Subject: [PATCH] This patch allows for multiple LFUNs to be bound to a single key, via a new command-alternatives function, to be used like so: \bind "Tab" "command-alternatives" "completion-accept;cell-forward" The first of the metioned functions that is enabled with be called. The code is pretty trivial and just stolen from command-sequence. The binding mentioned is more or less the point of the patch, but we still need to decide exactly what the bindings should be. There have been various threads concerning this. You can use the above for testing. Add it to site.bind, replacing the existing binding. Jose: Once the bindings have been sorted out, that will complete the work on this we said we wanted to do for rc3. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26518 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/FuncCode.h | 1 + src/LyXAction.cpp | 10 ++++++++++ src/LyXFunc.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/FuncCode.h b/src/FuncCode.h index 43f22c7f40..6a009a2f3f 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -408,6 +408,7 @@ enum FuncCode LFUN_COMPLETION_CANCEL, LFUN_COMPLETION_ACCEPT, // 315 + LFUN_COMMAND_ALTERNATIVES, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index a33ffdb6b9..f90d5cae28 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2922,6 +2922,16 @@ void LyXAction::init() * \endvar */ { LFUN_COMMAND_SEQUENCE, "command-sequence", NoBuffer, System }, +/*! + * \var lyx::FuncCode lyx::LFUN_COMMAND_ALTERNATIVES + * \li Action: Runs the first listed command that is enabled. + * \li Syntax: command-alternatives + * \li Params: : Sequence of commands separated by semicolons. + * \li Sample: command-alternatives completion-accept;cell-forward + * \li Origin: rgh, 24 September 2008 + * \endvar + */ + { LFUN_COMMAND_ALTERNATIVES, "command-alternatives", NoBuffer, System }, /*! * \var lyx::FuncCode lyx::LFUN_MESSAGE * \li Action: Shows message in statusbar (for script purposes). diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 9e25d5c4d8..34af99954a 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -533,6 +533,23 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const break; } + // we want to check if at least one of these is enabled + case LFUN_COMMAND_ALTERNATIVES: { + // argument contains ';'-terminated commands + string arg = to_utf8(cmd.argument()); + while (!arg.empty()) { + string first; + arg = split(arg, first, ';'); + FuncRequest func(lyxaction.lookupFunc(first)); + func.origin = cmd.origin; + flag = getStatus(func); + // if this one is enabled, the whole thing is + if (flag.enabled()) + break; + } + break; + } + case LFUN_CALL: { FuncRequest func; string name = to_utf8(cmd.argument()); @@ -1344,6 +1361,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; } + case LFUN_COMMAND_ALTERNATIVES: { + // argument contains ';'-terminated commands + string arg = argument; + while (!arg.empty()) { + string first; + arg = split(arg, first, ';'); + FuncRequest func(lyxaction.lookupFunc(first)); + func.origin = cmd.origin; + FuncStatus stat = getStatus(func); + if (stat.enabled()) { + dispatch(func); + break; + } + } + break; + } + case LFUN_CALL: { FuncRequest func; if (theTopLevelCmdDef().lock(argument, func)) {