mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
New helper lfun ifrelatives
This executes a command only if a buffer has either a master or children Helps to disable master-related items in the UI
This commit is contained in:
parent
3f7b8db1b1
commit
dc41c1f6df
@ -69,6 +69,8 @@
|
||||
|
||||
* export-cancel: Used to cancel background export processes.
|
||||
|
||||
* ifrelatives is a helper function to check whether a buffer has a master or children.
|
||||
|
||||
* master-buffer-forall executes an lfun in the master and all children of a document.
|
||||
|
||||
* paragraph-select is a new convenience function to select the paragraph
|
||||
|
@ -489,6 +489,7 @@ enum FuncCode
|
||||
// 380
|
||||
LFUN_BUFFER_RESET_EXPORT, // spitz 20191226
|
||||
LFUN_MASTER_BUFFER_FORALL, // spitz 20191231
|
||||
LFUN_IF_RELATIVES, // spitz 20200102
|
||||
LFUN_LASTACTION // end of the table
|
||||
};
|
||||
|
||||
|
@ -1923,6 +1923,19 @@ void LyXAction::init()
|
||||
*/
|
||||
{ LFUN_ICON_SIZE, "icon-size", NoBuffer, Buffer },
|
||||
|
||||
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_IF_RELATIVES
|
||||
* \li Action: Helper function for master-related actions
|
||||
* \li Notion: In a buffer, the function will be disabled if the buffer
|
||||
* has no master or children. It thus allows to enable
|
||||
* actions only in documents with master/children
|
||||
* \li Syntax: ifrelatives <ACTION>
|
||||
* \li Origin: spitz, 2 January 2020
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_IF_RELATIVES, "ifrelatives", Noop, Buffer },
|
||||
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_INDEX_INSERT
|
||||
* \li Action: Inserts Index entry.
|
||||
|
@ -1310,6 +1310,20 @@ bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_IF_RELATIVES: {
|
||||
string const lfun = to_utf8(cmd.argument());
|
||||
BufferView const * bv =
|
||||
current_view_ ? current_view_->currentBufferView() : nullptr;
|
||||
if (!bv || (bv->buffer().parent() == nullptr && !bv->buffer().hasChildren())) {
|
||||
enable = false;
|
||||
break;
|
||||
}
|
||||
FuncRequest func(lyxaction.lookupFunc(lfun));
|
||||
func.setOrigin(cmd.origin());
|
||||
flag = getStatus(func);
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
|
||||
case LFUN_REPEAT:
|
||||
case LFUN_PREFERENCES_SAVE:
|
||||
@ -2051,6 +2065,18 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_IF_RELATIVES: {
|
||||
string const lfun = to_utf8(cmd.argument());
|
||||
FuncRequest func(lyxaction.lookupFunc(lfun));
|
||||
func.setOrigin(cmd.origin());
|
||||
FuncStatus const stat = getStatus(func);
|
||||
if (stat.enabled()) {
|
||||
dispatch(func);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_PREFERENCES_SAVE:
|
||||
lyxrc.write(support::makeAbsPath("preferences",
|
||||
package().user_support().absFileName()), false);
|
||||
|
Loading…
Reference in New Issue
Block a user