]> git.lyx.org Git - features.git/commitdiff
New helper lfun ifrelatives
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 2 Jan 2020 13:09:24 +0000 (14:09 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:49 +0000 (15:48 +0200)
This executes a command only if a buffer has either a master or children

Helps to disable master-related items in the UI

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

index 9da7d8cec1e3053f37d7e94b0f62b699f4eb1200..30e294840d6dc2bf22597d57685c8232bbb02679 100644 (file)
@@ -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
index 10d65b3e59752710319fed2d7bd7cb3740e54ff1..762bc035caf96562b384e84ab0cf0abfb4b104d6 100644 (file)
@@ -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
 };
 
index aa57112776325997d643e2bb1d09fdf7caa6f114..a9789ad29037467c94d4ea959fe06c618a77134b 100644 (file)
@@ -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.
index e67a47621817ad1fb1f5c35339dd0db110cfbfde..9c15d7a770dcc157683745d64f20a058fff5d0b2 100644 (file)
@@ -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);