Add LFUN_LYXFILES_OPEN

This opens the new templates/examples dialog and creates a view if
necessary (#12106).
This commit is contained in:
Juergen Spitzmueller 2021-02-10 09:36:32 +01:00
parent fdde74cd24
commit c2822d684b
5 changed files with 35 additions and 2 deletions

View File

@ -90,6 +90,8 @@
* ifrelatives is a helper function to check whether a buffer has a master or children.
* lyxfiles-open opens the new examples or templates dialog.
* 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

View File

@ -43,10 +43,10 @@ Menuset
Menu "file"
Item "New|N" "buffer-new"
Item "New from Template...|m" "dialog-show lyxfiles templates"
Item "New from Template...|m" "lyxfiles-open templates"
Item "Open...|O" "file-open"
Submenu "Open Recent|t" "file_lastfiles"
Item "Open Example...|p" "dialog-show lyxfiles examples"
Item "Open Example...|p" "lyxfiles-open examples"
Separator
Item "Close|C" "buffer-close"
Item "Close All" "buffer-close-all"

View File

@ -494,6 +494,7 @@ enum FuncCode
LFUN_TOOLBAR_SET, // spitz 20201217
// 385
LFUN_INSET_SPLIT, // jspitzm 20201222
LFUN_LYXFILES_OPEN, // jspitzm 20210210
LFUN_LASTACTION // end of the table
};

View File

@ -1900,6 +1900,16 @@ void LyXAction::init()
*/
{ LFUN_HELP_OPEN, "help-open", NoBuffer | Argument, Buffer },
/*!
* \var lyx::FuncCode lyx::LFUN_LYXFILES_OPEN
* \li Action: Open lyxfiles (templates/examples). Create a view if he have none.
* \li Syntax: lyxfiles-open [<TYPE>]
* \li Params: <TYPE>: templates or examples. Default is templates.
* \li Origin: spitz, 10 Feb 2021
* \endvar
*/
{ LFUN_LYXFILES_OPEN, "lyxfiles-open", NoBuffer | Argument, Buffer },
/*!
* \var lyx::FuncCode lyx::LFUN_HREF_INSERT
* \li Action: Inserts hyperlinks into the document (clickable in pdf output).

View File

@ -1379,6 +1379,7 @@ bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
case LFUN_BUFFER_NEW:
case LFUN_BUFFER_NEW_TEMPLATE:
case LFUN_FILE_OPEN:
case LFUN_LYXFILES_OPEN:
case LFUN_HELP_OPEN:
case LFUN_SCREEN_FONT_UPDATE:
case LFUN_SET_COLOR:
@ -1821,6 +1822,25 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break;
}
case LFUN_LYXFILES_OPEN: {
// This is the actual reason for this method (#12106).
validateCurrentView();
if (!current_view_
|| (!lyxrc.open_buffers_in_tabs
&& current_view_->documentBufferView() != nullptr))
createView();
string arg = to_utf8(cmd.argument());
if (arg.empty())
// set default
arg = "templates";
if (arg != "templates" && arg != "examples") {
current_view_->message(_("Wrong argument. Must be 'examples' or 'templates'."));
break;
}
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "lyxfiles " + arg));
break;
}
case LFUN_SET_COLOR: {
string const lyx_name = cmd.getArg(0);
string x11_name = cmd.getArg(1);