commit c2822d684b00b8425ba05628a1454b4e2a44f720
Author: Juergen Spitzmueller <[email protected]>
Date:   Wed Feb 10 09:36:32 2021 +0100

    Add LFUN_LYXFILES_OPEN
    
    This opens the new templates/examples dialog and creates a view if
    necessary (#12106).
---
 lib/RELEASE-NOTES                   |    2 ++
 lib/ui/stdmenus.inc                 |    4 ++--
 src/FuncCode.h                      |    1 +
 src/LyXAction.cpp                   |   10 ++++++++++
 src/frontends/qt/GuiApplication.cpp |   20 ++++++++++++++++++++
 5 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index 6c63b66..1f8069b 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 08827f9..8138f95 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 9857143..a720c64 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 92da4d7..38fa2c3 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1901,6 +1901,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).
  * \li Notion: Hyperlink target can be set via selection + hyperlink-insert 
function.
diff --git a/src/frontends/qt/GuiApplication.cpp 
b/src/frontends/qt/GuiApplication.cpp
index 6507700..104aa00 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);
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to