]> git.lyx.org Git - features.git/commitdiff
Implement master-buffer-forall
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 31 Dec 2019 11:27:00 +0000 (12:27 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:49 +0000 (15:48 +0200)
Similar to buffer-forall with the notable exception that its scope is
limited to the files of a project (master and all children)

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

index 262edd92e4c9d11bb6a50540638db283abd0769c..9da7d8cec1e3053f37d7e94b0f62b699f4eb1200 100644 (file)
@@ -69,6 +69,8 @@
 
 * export-cancel: Used to cancel background export processes.
 
+* 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
   surrounding the actual cursor position.
 
index e94a7873ac33c7823cf8af5f812cb9a965e4b8c6..10d65b3e59752710319fed2d7bd7cb3740e54ff1 100644 (file)
@@ -488,6 +488,7 @@ enum FuncCode
        LFUN_BIDI,
        // 380
        LFUN_BUFFER_RESET_EXPORT,       // spitz 20191226
+       LFUN_MASTER_BUFFER_FORALL,      // spitz 20191231
        LFUN_LASTACTION                 // end of the table
 };
 
index 410d0f6ae55b38fbe1bad170abea505dc66cabb2..aa57112776325997d643e2bb1d09fdf7caa6f114 100644 (file)
@@ -2587,6 +2587,26 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_MASTER_BUFFER_EXPORT, "master-buffer-export", ReadOnly, Buffer },
+               
+/*!
+ * \var lyx::FuncCode lyx::LFUN_MASTER_BUFFER_FORALL
+ * \li Action: Applies a command to a buffer and all it children, starting from the master.
+ * \li Syntax: master-buffer-forall <LFUN-COMMAND>
+ * \li Params: <LFUN-COMMAND>: The command to be applied to the buffers.
+ * \li Sample: Close all Notes in buffers: \n
+              master-buffer-forall inset-forall Note inset-toggle close \n
+              Toggle change tracking on buffers: \n
+              master-buffer-forall changes-track \n
+              Toggle read-only for buffers: \n
+              master-buffer-forall buffer-toggle-read-only \n
+              Show statistics for individual buffers: \n
+              master-buffer-forall statistics \n
+              Activate the branch named "Solutions" in buffers: \n
+              master-buffer-forall branch-activate Solutions \n
+ * \li Origin: spitz, 31 Dec 2019
+ * \endvar
+ */
+               { LFUN_MASTER_BUFFER_FORALL, "master-buffer-forall", ReadOnly | Argument, Buffer },
 
 /*!
  * \var lyx::FuncCode lyx::LFUN_MASTER_BUFFER_UPDATE
index 32d6d9334f58777b3ee7cb8e0172037362cbd187..a7839114b9d2bd928732f23744a9c793e781a598 100644 (file)
@@ -1967,6 +1967,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                enable = doc_buffer != 0;
                break;
 
+       case LFUN_MASTER_BUFFER_FORALL:
+               enable = doc_buffer != 0;
+               break;
+
        case LFUN_BUFFER_WRITE:
                enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
                break;
@@ -4179,6 +4183,25 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        break;
                }
 
+               case LFUN_MASTER_BUFFER_FORALL: {
+                       if (!doc_buffer)
+                               break;
+
+                       FuncRequest funcToRun = lyxaction.lookupFunc(cmd.getLongArg(0));
+                       funcToRun.allowAsync(false);
+
+                       for (Buffer const * buf : doc_buffer->allRelatives()) {
+                               // Switch to other buffer view and resend cmd
+                               lyx::dispatch(FuncRequest(
+                                       LFUN_BUFFER_SWITCH, buf->absFileName()));
+                               lyx::dispatch(funcToRun);
+                       }
+                       // switch back
+                       lyx::dispatch(FuncRequest(
+                               LFUN_BUFFER_SWITCH, doc_buffer->absFileName()));
+                       break;
+               }
+
                case LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR:
                        LASSERT(doc_buffer, break);
                        doc_buffer->clearExternalModification();