]> git.lyx.org Git - features.git/commitdiff
Add LFUN_LYXFILES_OPEN
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 10 Feb 2021 08:36:32 +0000 (09:36 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 10 Feb 2021 08:36:32 +0000 (09:36 +0100)
This opens the new templates/examples dialog and creates a view if
necessary (#12106).

lib/RELEASE-NOTES
lib/ui/stdmenus.inc
src/FuncCode.h
src/LyXAction.cpp
src/frontends/qt/GuiApplication.cpp

index 6c63b6658575084fcc3f61408c727a9dae6b78ac..1f8069b772280e6f972eb1efa669b37357b8a6c0 100644 (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
index 08827f965e0f3f0c2678515feb0ee3123dab5a40..8138f959e54bd0c67ebd640a233e06d99ae62a5e 100644 (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"
index 9857143c2599971587e1ddba0e4f1be056599dcd..a720c642bf527fe55d677cdf91a33dc4467e81d1 100644 (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
 };
 
index 92da4d7293a1f2a26964278692498f6deba1daaf..38fa2c3cdbcca58d472d09ae948c4e2fc46b0d7c 100644 (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).
index 6507700b701613177ce8c646ecfb5c3af1dbc353..104aa00c54543ca253698241b79fb9428e55b146 100644 (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);