Implement master-buffer-forall

Similar to buffer-forall with the notable exception that its scope is
limited to the files of a project (master and all children)
This commit is contained in:
Juergen Spitzmueller 2019-12-31 12:27:00 +01:00
parent 0e6a7aa85a
commit 69792bbaa5
4 changed files with 46 additions and 0 deletions

View File

@ -69,6 +69,8 @@
* export-cancel: Used to cancel background export processes. * 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 * paragraph-select is a new convenience function to select the paragraph
surrounding the actual cursor position. surrounding the actual cursor position.

View File

@ -488,6 +488,7 @@ enum FuncCode
LFUN_BIDI, LFUN_BIDI,
// 380 // 380
LFUN_BUFFER_RESET_EXPORT, // spitz 20191226 LFUN_BUFFER_RESET_EXPORT, // spitz 20191226
LFUN_MASTER_BUFFER_FORALL, // spitz 20191231
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -2588,6 +2588,26 @@ void LyXAction::init()
*/ */
{ LFUN_MASTER_BUFFER_EXPORT, "master-buffer-export", ReadOnly, Buffer }, { 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 * \var lyx::FuncCode lyx::LFUN_MASTER_BUFFER_UPDATE
* \li Action: Update (export) the document built from the master buffer, * \li Action: Update (export) the document built from the master buffer,

View File

@ -1967,6 +1967,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
enable = doc_buffer != 0; enable = doc_buffer != 0;
break; break;
case LFUN_MASTER_BUFFER_FORALL:
enable = doc_buffer != 0;
break;
case LFUN_BUFFER_WRITE: case LFUN_BUFFER_WRITE:
enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean()); enable = doc_buffer && (doc_buffer->isUnnamed() || !doc_buffer->isClean());
break; break;
@ -4179,6 +4183,25 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break; 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: case LFUN_BUFFER_EXTERNAL_MODIFICATION_CLEAR:
LASSERT(doc_buffer, break); LASSERT(doc_buffer, break);
doc_buffer->clearExternalModification(); doc_buffer->clearExternalModification();