mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
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
This commit is contained in:
parent
0cdc8c3aca
commit
6774176aab
@ -452,6 +452,7 @@ enum FuncCode
|
|||||||
// 350
|
// 350
|
||||||
LFUN_CLIPBOARD_PASTE_SIMPLE, // tommaso, 20111028
|
LFUN_CLIPBOARD_PASTE_SIMPLE, // tommaso, 20111028
|
||||||
LFUN_IPA_INSERT, // spitz, 20120305
|
LFUN_IPA_INSERT, // spitz, 20120305
|
||||||
|
LFUN_BUFFER_FORALL, // scottkostyshak, 20120720
|
||||||
|
|
||||||
LFUN_LASTACTION // end of the table
|
LFUN_LASTACTION // end of the table
|
||||||
};
|
};
|
||||||
|
@ -3126,6 +3126,28 @@ void LyXAction::init()
|
|||||||
* \endvar
|
* \endvar
|
||||||
*/
|
*/
|
||||||
{ LFUN_BUFFER_WRITE_AS, "buffer-write-as", ReadOnly, Buffer },
|
{ 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
|
* \var lyx::FuncCode lyx::LFUN_BUFFER_WRITE_ALL
|
||||||
* \li Action: Save all changed documents.
|
* \li Action: Save all changed documents.
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "Font.h"
|
#include "Font.h"
|
||||||
#include "FuncRequest.h"
|
#include "FuncRequest.h"
|
||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
|
#include "GuiWorkArea.h"
|
||||||
#include "Intl.h"
|
#include "Intl.h"
|
||||||
#include "KeyMap.h"
|
#include "KeyMap.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
@ -1077,6 +1078,15 @@ bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
|
|||||||
enable = true;
|
enable = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LFUN_BUFFER_FORALL: {
|
||||||
|
if (!currentView() || !currentView()->currentBufferView() || !¤tView()->currentBufferView()->buffer()) {
|
||||||
|
flag.message(from_utf8(N_("Command not allowed without any visible document in the active window")));
|
||||||
|
flag.setEnabled(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1592,6 +1602,63 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
break;
|
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: {
|
case LFUN_COMMAND_ALTERNATIVES: {
|
||||||
// argument contains ';'-terminated commands
|
// argument contains ';'-terminated commands
|
||||||
string arg = argument;
|
string arg = argument;
|
||||||
|
Loading…
Reference in New Issue
Block a user