]> git.lyx.org Git - features.git/commitdiff
This patch allows for multiple LFUNs to be bound to a single key, via a new command...
authorRichard Heck <rgheck@comcast.net>
Wed, 24 Sep 2008 15:08:46 +0000 (15:08 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 24 Sep 2008 15:08:46 +0000 (15:08 +0000)
\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
src/LyXAction.cpp
src/LyXFunc.cpp

index 43f22c7f407bb83a0dffe682f777bc25456a6e5f..6a009a2f3f7b2179f6208a9344cb4d252a882ca8 100644 (file)
@@ -408,6 +408,7 @@ enum FuncCode
        LFUN_COMPLETION_CANCEL,
        LFUN_COMPLETION_ACCEPT,
        // 315
+       LFUN_COMMAND_ALTERNATIVES,
        LFUN_LASTACTION                  // end of the table
 };
 
index a33ffdb6b9b174574fa2f815b7be6d84efd4cabd..f90d5cae28569384d9b7bbb688020a00c81810d6 100644 (file)
@@ -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 <CMDS>
+ * \li Params: <CMDS>: 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).
index 9e25d5c4d89f4553868b7d1dc3c72f8062e5bc39..34af99954ace5001a0caccc66a2481447e7d138e 100644 (file)
@@ -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)) {