diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES index 6c63b66585..1f8069b772 100644 --- a/lib/RELEASE-NOTES +++ b/lib/RELEASE-NOTES @@ -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 diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 08827f965e..8138f959e5 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -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" diff --git a/src/FuncCode.h b/src/FuncCode.h index 9857143c25..a720c642bf 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -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 }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 92da4d7293..38fa2c3cdb 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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 [] + * \li Params: : 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). diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index 6507700b70..104aa00c54 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -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);