From 69792bbaa5991e24f3b2c3c9bd1c383fb4f6647f Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 31 Dec 2019 12:27:00 +0100 Subject: [PATCH] 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) --- lib/RELEASE-NOTES | 2 ++ src/FuncCode.h | 1 + src/LyXAction.cpp | 20 ++++++++++++++++++++ src/frontends/qt/GuiView.cpp | 23 +++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES index 262edd92e4..9da7d8cec1 100644 --- a/lib/RELEASE-NOTES +++ b/lib/RELEASE-NOTES @@ -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. diff --git a/src/FuncCode.h b/src/FuncCode.h index e94a7873ac..10d65b3e59 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -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 }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 410d0f6ae5..aa57112776 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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 + * \li Params: : 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 diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index 32d6d9334f..a7839114b9 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -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();