The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit 6774176aab831a375cd18c02c6f6ae7a5dd08b43
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Fri Jul 20 10:50:29 2012 +0200

    Implement new LFUN buffer-forall [<BUFFER-TYPE>] <LFUN-COMMAND>
    
    This is a patch from Scott Kostyshak. See the thread here for some
    background info:
    http://thread.gmane.org/gmane.editors.lyx.devel/142300/focus=142362

diff --git a/src/FuncCode.h b/src/FuncCode.h
index 9a7b06e..a1cf57f 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -452,6 +452,7 @@ enum FuncCode
        // 350
        LFUN_CLIPBOARD_PASTE_SIMPLE,    // tommaso, 20111028
        LFUN_IPA_INSERT,                // spitz, 20120305
+       LFUN_BUFFER_FORALL,             // scottkostyshak, 20120720
 
        LFUN_LASTACTION                 // end of the table
 };
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 39018ce..7a4ec33 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3127,6 +3127,28 @@ void LyXAction::init()
  */
                { LFUN_BUFFER_WRITE_AS, "buffer-write-as", ReadOnly, Buffer },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_FORALL
+ * \li Action: Applies a command to all visible, hidden, or both types of 
buffers in the active window.
+ * \li Syntax: buffer-forall [<BUFFER-TYPE>] <LFUN-COMMAND>
+ * \li Params: <BUFFER-TYPE>: <visible|hidden|both default:> default: visible  
             
+               <LFUN-COMMAND>: The command that is to be applied to the 
buffers.
+ * \li Sample: Close all Notes in all visible documents: \n
+                  buffer-forall inset-forall Note inset-toggle close \n
+               Toggle change tracking on all documents: \n
+                  buffer-forall both changes-track \n
+               Toggle read-only for all visible documents: \n
+                  buffer-forall buffer-toggle-read-only \n
+               Show statistics for each document: \n
+                  buffer-forall both statistics \n
+               Activate the branch named "Solutions" in all visible documents: 
\n
+                  buffer-forall branch-activate Solutions \n
+               Export all visible documents to PDF (pdflatex): \n
+                  buffer-forall buffer-export pdf2 \n
+ * \li Origin: scottkostyshak, 20 Jul 2012
+ * \endvar
+ */
+               { LFUN_BUFFER_FORALL, "buffer-forall", ReadOnly | Argument, 
Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_BUFFER_WRITE_ALL
  * \li Action: Save all changed documents.
  * \li Syntax: buffer-write-all
diff --git a/src/frontends/qt4/GuiApplication.cpp 
b/src/frontends/qt4/GuiApplication.cpp
index b855067..94581a3 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -38,6 +38,7 @@
 #include "Font.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "GuiWorkArea.h"
 #include "Intl.h"
 #include "KeyMap.h"
 #include "Language.h"
@@ -1077,6 +1078,15 @@ bool GuiApplication::getStatus(FuncRequest const & cmd, 
FuncStatus & flag) const
                enable = true;
                break;
 
+       case LFUN_BUFFER_FORALL: {
+               if (!currentView() || !currentView()->currentBufferView() || 
!&currentView()->currentBufferView()->buffer()) {
+                       flag.message(from_utf8(N_("Command not allowed without 
any visible document in the active window")));
+                       flag.setEnabled(false);
+               }
+               break;
+       }
+
+
        default:
                return false;
        }
@@ -1592,6 +1602,63 @@ void GuiApplication::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                break;
        }
 
+       case LFUN_BUFFER_FORALL: {
+               GuiView * gv = currentView();
+               Buffer * const buf = &gv->currentBufferView()->buffer();
+
+               bool processVisible = true;
+               bool processHidden = false;
+               docstring msg = _("Applied the following command to all visible 
buffers in the active window: ");
+               string commandToRun = argument;
+               if (cmd.getArg(0) == "both") {
+                       processHidden = true;
+                       msg = _("Applied the following command to all visible 
and hidden buffers in the active window: ");
+                       commandToRun = cmd.getLongArg(1);
+               } else if (cmd.getArg(0) == "visible") {
+                       commandToRun = cmd.getLongArg(1);
+               } else if (cmd.getArg(0) == "hidden") {
+                       processHidden = true;
+                       processVisible = false;
+                       commandToRun = cmd.getLongArg(1);
+                       msg = _("Applied the following command to all hidden 
buffers in the active window: ");
+               }
+               FuncRequest const funcToRun = 
lyxaction.lookupFunc(commandToRun);
+               dr.setMessage(bformat(_("%1$s%2$s"), msg, 
from_utf8(commandToRun)));
+
+               Buffer * const last = theBufferList().last();
+               Buffer * b = theBufferList().first();
+               Buffer * nextBuf = 0;
+               // We cannot use a for loop as the buffer list cycles.
+               while (true) {
+                       if (b != last)
+                               nextBuf = theBufferList().next(b); //get next 
now bc LFUN might close current 
+
+                       bool const hidden = !(gv && gv->workArea(*b));
+                       if (hidden) {
+                               if (processHidden) {
+                                       gv->setBuffer(b);
+                                       lyx::dispatch(funcToRun);
+                                       
gv->currentWorkArea()->view().hideWorkArea(gv->currentWorkArea());
+                               }
+                       }
+
+                       else {
+                               if (processVisible) {
+                                       gv->setBuffer(b);
+                                       lyx::dispatch(funcToRun);
+                               }
+                       }
+
+                       if (b == last)
+                               break;
+                       b = nextBuf;
+               }
+
+               if (theBufferList().isLoaded(buf)) //the LFUN might have closed 
buf
+                       gv->setBuffer(buf);
+               break;
+       }
+
        case LFUN_COMMAND_ALTERNATIVES: {
                // argument contains ';'-terminated commands
                string arg = argument;

-----------------------------------------------------------------------

Summary of changes:
 src/FuncCode.h                       |    1 +
 src/LyXAction.cpp                    |   22 +++++++++++
 src/frontends/qt4/GuiApplication.cpp |   67 ++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 0 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to