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
This commit is contained in:
Richard Heck 2008-09-24 15:08:46 +00:00
parent b8cf8cbab2
commit 6576aed3d5
3 changed files with 45 additions and 0 deletions

View File

@ -408,6 +408,7 @@ enum FuncCode
LFUN_COMPLETION_CANCEL,
LFUN_COMPLETION_ACCEPT,
// 315
LFUN_COMMAND_ALTERNATIVES,
LFUN_LASTACTION // end of the table
};

View 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).

View 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)) {