Now LyX has functions for adding one module (LFUN_LAYOUT_MODULE_ADD) and for removing all modules (LFUN_LAYOUT_MODULES_CLEAR), but removing only one module is impossible. I propose to add such function: LFUN_LAYOUT_MODULE_REMOVE.

My current use case: adding and removing module "Minimalistic Insets" to unclutter document with many branch insets by hiding their labels during work on content.

Without such LFUN this should be done manually. With it we will be able to do:

layout-module-add minimalistic
layout-module-remove minimalistic


Yuriy
From d9f6b76582f665e7f53e165588ff1d530c330df5 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.ska...@gmail.com>
Date: Thu, 21 Oct 2021 18:50:49 +0300
Subject: [PATCH] Add LFUN for removing LyX modules

---
 src/BufferParams.cpp   |  6 ++++++
 src/BufferParams.h     |  2 ++
 src/BufferView.cpp     | 13 +++++++++++++
 src/FuncCode.h         |  1 +
 src/LayoutModuleList.h |  2 ++
 src/LyXAction.cpp      | 10 ++++++++++
 6 files changed, 34 insertions(+)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index bbbce16bef..a14e3211f9 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2608,6 +2608,12 @@ bool BufferParams::addLayoutModule(string const & 
modName)
 }
 
 
+void BufferParams::removeLayoutModule(string const & modName)
+{
+       layout_modules_.remove(modName);
+}
+
+
 string BufferParams::bufferFormat() const
 {
        return documentClass().outputFormat();
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 52d8219cb4..3a40be60a0 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -175,6 +175,8 @@ public:
        /// if you want to check for compatibility.
        /// \return true if module was successfully added.
        bool addLayoutModule(std::string const & modName);
+       ///
+       void removeLayoutModule(std::string const & modName);
        /// checks to make sure module's requriements are satisfied, that it 
does
        /// not conflict with already-present modules, isn't already loaded, 
etc.
        bool layoutModuleCanBeAdded(std::string const & modName) const;
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index ac9a8235db..fead2c3683 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1156,6 +1156,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, 
FuncStatus & flag)
        case LFUN_BUFFER_PARAMS_APPLY:
        case LFUN_LAYOUT_MODULES_CLEAR:
        case LFUN_LAYOUT_MODULE_ADD:
+       case LFUN_LAYOUT_MODULE_REMOVE:
        case LFUN_LAYOUT_RELOAD:
        case LFUN_TEXTCLASS_APPLY:
        case LFUN_TEXTCLASS_LOAD:
@@ -1400,6 +1401,18 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                break;
        }
 
+       case LFUN_LAYOUT_MODULE_REMOVE: {
+               // FIXME: this modifies the document in 
cap::switchBetweenClasses
+               //  without calling recordUndo. Fix this before using
+               //  recordUndoBufferParams().
+               cur.recordUndoFullBuffer();
+               buffer_.params().removeLayoutModule(argument);
+               makeDocumentClass();
+               dr.screenUpdate(Update::Force);
+               dr.forceBufferUpdate();
+               break;
+       }
+
        case LFUN_TEXTCLASS_APPLY: {
                // since this shortcircuits, the second call is made only if
                // the first fails
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 20231eb164..2a3221641d 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -502,6 +502,7 @@ enum FuncCode
        LFUN_SPELLING_REMOVE_LOCAL,     // jspitzm 20210307
        LFUN_FINISHED_DOWN,             // lasgouttes 20210629
        LFUN_FINISHED_UP,               // lasgouttes 20210629
+       LFUN_LAYOUT_MODULE_REMOVE,      // yuriy 20211021
        LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LayoutModuleList.h b/src/LayoutModuleList.h
index 868c1cf945..1c65ae8564 100644
--- a/src/LayoutModuleList.h
+++ b/src/LayoutModuleList.h
@@ -51,6 +51,8 @@ public:
        ///
        void push_back(std::string const & str) { lml_.push_back(str); }
        ///
+       void remove(std::string const & str) { lml_.remove(str); }
+       ///
        size_t size() const { return lml_.size(); }
        /// This is needed in GuiDocument. It seems better than an
        /// implicit conversion.
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 254060e789..e2d6cd3cca 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -2477,6 +2477,16 @@ void LyXAction::init()
  */
                { LFUN_LAYOUT_MODULE_ADD, "layout-module-add", NoInternal, 
Layout },
 
+/*!
+ * \var lyx::FuncCode lyx::LFUN_LAYOUT_MODULE_REMOVE
+ * \li Action: Removes a module.
+ * \li Notion: Removes a module from the list of included modules for the 
current buffer.
+ * \li Syntax: layout-module-remove <MODULE>
+ * \li Params: <MODULE>: the module to be removed
+ * \endvar
+ */
+               { LFUN_LAYOUT_MODULE_REMOVE, "layout-module-remove", 
NoInternal, Layout },
+
 /*!
  * \var lyx::FuncCode lyx::LFUN_LAYOUT_PARAGRAPH
  * \li Action: Launches the paragraph settings dialog.
-- 
2.28.0.windows.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to