From a6eb598abd84cbcd69ca1c248963610741743d11 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 2 Feb 2026 00:09:29 +0100 Subject: [PATCH] Some refactoring: global editor option pages are requested from the plugins explicitly. So the generic editor options are not added automatically. --- src/ant/ant/antPlugin.cc | 9 ++++ src/ant/ant/antPlugin.h | 2 + src/edt/edt/edtEditorOptionsPages.cc | 2 +- src/edt/edt/edtEditorOptionsPages.h | 1 - src/edt/edt/edtPlugin.cc | 14 ++++++ src/edt/edt/edtService.cc | 2 +- src/edt/edt/edtShapeService.cc | 2 +- src/img/img/imgPlugin.cc | 9 ++++ src/img/img/imgPlugin.h | 1 + src/laybasic/laybasic/layEditorOptionsPage.cc | 4 +- src/laybasic/laybasic/layEditorOptionsPage.h | 43 +++++++++++++++---- src/laybasic/laybasic/layLayoutViewBase.cc | 2 +- src/laybasic/laybasic/layMouseTracker.cc | 5 --- src/laybasic/laybasic/layMove.cc | 8 ++++ src/laybasic/laybasic/layPlugin.cc | 20 ++++++--- src/laybasic/laybasic/layPlugin.h | 21 +++------ src/laybasic/laybasic/laySelector.cc | 5 --- src/laybasic/laybasic/layZoomBox.cc | 5 --- .../layview/gsiDeclLayPluginFactory.cc | 26 +++++++++++ src/layview/layview/layEditorOptionsFrame.cc | 9 +++- src/layview/layview/layEditorOptionsPages.cc | 14 +----- src/layview/layview/layLayoutView_qt.cc | 5 +++ 22 files changed, 146 insertions(+), 63 deletions(-) diff --git a/src/ant/ant/antPlugin.cc b/src/ant/ant/antPlugin.cc index aaed7f8d6..73454b6b8 100644 --- a/src/ant/ant/antPlugin.cc +++ b/src/ant/ant/antPlugin.cc @@ -138,6 +138,15 @@ PluginDeclaration::create_plugin (db::Manager *manager, lay::Dispatcher *, lay:: return new ant::Service (manager, view); } +std::vector +PluginDeclaration::additional_editor_options_pages () const +{ + std::vector names; + // TODO: provide in a central place instead of borrowing from the edt module + names.push_back ("GenericEditorOptions"); + return names; +} + bool PluginDeclaration::menu_activated (const std::string &symbol) const { diff --git a/src/ant/ant/antPlugin.h b/src/ant/ant/antPlugin.h index 2e2812506..ce632f4de 100644 --- a/src/ant/ant/antPlugin.h +++ b/src/ant/ant/antPlugin.h @@ -54,6 +54,8 @@ public: virtual void uninitialize (lay::Dispatcher *); virtual bool menu_activated (const std::string &symbol) const; + virtual std::vector additional_editor_options_pages () const; + void register_annotation_template (const ant::Template &t, lay::Plugin *plugin = 0); void unregister_annotation_template (const std::string &category, lay::Plugin *plugin = 0); diff --git a/src/edt/edt/edtEditorOptionsPages.cc b/src/edt/edt/edtEditorOptionsPages.cc index 04a001c6c..47988b0fe 100644 --- a/src/edt/edt/edtEditorOptionsPages.cc +++ b/src/edt/edt/edtEditorOptionsPages.cc @@ -1060,7 +1060,7 @@ ConnectionToolboxWidget::configure (const std::string &name, const std::string & // Registrations // unspecific editor options - used for all plugins that want it -static tl::RegisteredClass s_factory_generic (new lay::EditorOptionsPageFactory (), 0); +static tl::RegisteredClass s_factory_generic (new lay::EditorOptionsPageFactory ("GenericEditorOptions"), 0); static tl::RegisteredClass s_factory_texts (new lay::EditorOptionsPageFactory ("edt::Service(Texts)"), 0); static tl::RegisteredClass s_factory_paths (new lay::EditorOptionsPageFactory ("edt::Service(Paths)"), 0); diff --git a/src/edt/edt/edtEditorOptionsPages.h b/src/edt/edt/edtEditorOptionsPages.h index 92f151883..23ae0e59c 100644 --- a/src/edt/edt/edtEditorOptionsPages.h +++ b/src/edt/edt/edtEditorOptionsPages.h @@ -52,7 +52,6 @@ namespace Ui namespace lay { - class PluginDeclaration; class Dispatcher; class LayoutViewBase; class Plugin; diff --git a/src/edt/edt/edtPlugin.cc b/src/edt/edt/edtPlugin.cc index 1bc60d64a..f2dcea429 100644 --- a/src/edt/edt/edtPlugin.cc +++ b/src/edt/edt/edtPlugin.cc @@ -142,6 +142,13 @@ public: } } + virtual std::vector additional_editor_options_pages () const + { + std::vector names; + names.push_back ("GenericEditorOptions"); + return names; + } + private: std::string m_title; std::string m_mouse_mode; @@ -408,6 +415,13 @@ public: return true; } + virtual std::vector additional_editor_options_pages () const + { + std::vector names; + names.push_back ("GenericEditorOptions"); + return names; + } + private: std::string m_title; std::string m_mouse_mode; diff --git a/src/edt/edt/edtService.cc b/src/edt/edt/edtService.cc index 6b0d918b7..55b83bf49 100644 --- a/src/edt/edt/edtService.cc +++ b/src/edt/edt/edtService.cc @@ -2070,7 +2070,7 @@ Service::commit_recent () auto pages = eo_pages->editor_options_pages (); for (auto op = pages.begin (); op != pages.end (); ++op) { - if ((*op)->plugin_declaration () == plugin_declaration ()) { + if ((*op)->for_plugin_declaration (plugin_declaration ())) { (*op)->commit_recent (view ()); } } diff --git a/src/edt/edt/edtShapeService.cc b/src/edt/edt/edtShapeService.cc index 71158cb81..2352ac0ea 100644 --- a/src/edt/edt/edtShapeService.cc +++ b/src/edt/edt/edtShapeService.cc @@ -85,7 +85,7 @@ ShapeEditService::config_recent_for_layer (const db::LayerProperties &lp, int cv auto pages = eo_pages->editor_options_pages (); for (auto op = pages.begin (); op != pages.end (); ++op) { - if ((*op)->plugin_declaration () == plugin_declaration ()) { + if ((*op)->for_plugin_declaration (plugin_declaration ())) { (*op)->config_recent_for_layer (dispatcher (), lp, cv_index); } } diff --git a/src/img/img/imgPlugin.cc b/src/img/img/imgPlugin.cc index c9667918e..10db2e81d 100644 --- a/src/img/img/imgPlugin.cc +++ b/src/img/img/imgPlugin.cc @@ -62,6 +62,15 @@ PluginDeclaration::get_options (std::vector < std::pair (cfg_images_visible, "true")); } +std::vector +PluginDeclaration::additional_editor_options_pages () const +{ + std::vector names; + // TODO: provide in a central place instead of borrowing from the edt module + names.push_back ("GenericEditorOptions"); + return names; +} + static tl::RegisteredClass config_decl (new img::PluginDeclaration (), 4000, "img::Plugin"); } diff --git a/src/img/img/imgPlugin.h b/src/img/img/imgPlugin.h index 7ac292a93..703cb13a3 100644 --- a/src/img/img/imgPlugin.h +++ b/src/img/img/imgPlugin.h @@ -39,6 +39,7 @@ public: virtual lay::Plugin *create_plugin (db::Manager *manager, lay::Dispatcher *, lay::LayoutViewBase *view) const; virtual bool implements_editable (std::string &title) const; virtual void get_options (std::vector < std::pair > &options) const; + virtual std::vector additional_editor_options_pages () const; }; } diff --git a/src/laybasic/laybasic/layEditorOptionsPage.cc b/src/laybasic/laybasic/layEditorOptionsPage.cc index e451c0e32..7aba418ad 100644 --- a/src/laybasic/laybasic/layEditorOptionsPage.cc +++ b/src/laybasic/laybasic/layEditorOptionsPage.cc @@ -41,13 +41,13 @@ EditorOptionsPageCollection::EditorOptionsPageCollection () // EditorOptionsPage implementation EditorOptionsPage::EditorOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) - : mp_owner (0), m_active (true), m_focus_page (false), m_modal_page (false), m_toolbox_widget (false), mp_plugin_declaration (0), mp_dispatcher (0), mp_view (0) + : mp_owner (0), m_active (true), m_focus_page (false), m_modal_page (false), m_toolbox_widget (false), mp_dispatcher (0), mp_view (0) { init (view, dispatcher); } EditorOptionsPage::EditorOptionsPage () - : mp_owner (0), m_active (true), m_focus_page (false), m_modal_page (false), m_toolbox_widget (false), mp_plugin_declaration (0), mp_dispatcher (0), mp_view (0) + : mp_owner (0), m_active (true), m_focus_page (false), m_modal_page (false), m_toolbox_widget (false), mp_dispatcher (0), mp_view (0) { // .. nothing yet .. } diff --git a/src/laybasic/laybasic/layEditorOptionsPage.h b/src/laybasic/laybasic/layEditorOptionsPage.h index 23d1cce26..239224f62 100644 --- a/src/laybasic/laybasic/layEditorOptionsPage.h +++ b/src/laybasic/laybasic/layEditorOptionsPage.h @@ -27,6 +27,8 @@ #include "tlObject.h" +#include + namespace db { struct LayerProperties; @@ -110,8 +112,22 @@ public: */ int show (); - const lay::PluginDeclaration *plugin_declaration () const { return mp_plugin_declaration; } - void set_plugin_declaration (const lay::PluginDeclaration *pd) { mp_plugin_declaration = pd; } + bool for_plugin_declaration (const lay::PluginDeclaration *pd) + { + return m_plugin_declarations.find (pd) != m_plugin_declarations.end (); + } + + void set_plugin_declaration (const lay::PluginDeclaration *pd) + { + m_plugin_declarations.clear (); + m_plugin_declarations.insert (pd); + } + + void set_plugin_declarations (const std::vector &pd) + { + m_plugin_declarations.clear (); + m_plugin_declarations.insert (pd.begin (), pd.end ()); + } void init (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher); @@ -136,7 +152,7 @@ private: bool m_active; bool m_focus_page; bool m_modal_page, m_toolbox_widget; - const lay::PluginDeclaration *mp_plugin_declaration; + std::set m_plugin_declarations; lay::Dispatcher *mp_dispatcher; lay::LayoutViewBase *mp_view; @@ -150,33 +166,42 @@ private: * * We will use it later to provide a registration-based specialized factory * for Qt-enabled option pages, which we should not link here. + * + * A factory has a name - if the name matches a plugin name, + * the factory is automatically requested to create a page for + * that plugin. + * + * Otherwise, plugins can request additional pages through + * "additional_editor_options_pages". This is a list of names + * (not plugin names) of page factories. These factories will + * be called to provide additional pages then. */ class LAYBASIC_PUBLIC EditorOptionsPageFactoryBase { public: - EditorOptionsPageFactoryBase (const char *plugin_name) - : m_plugin_name (plugin_name) + EditorOptionsPageFactoryBase (const char *name) + : m_name (name) { // .. nothing yet .. } EditorOptionsPageFactoryBase () - : m_plugin_name () + : m_name () { // .. nothing yet .. } virtual ~EditorOptionsPageFactoryBase () { } - const std::string &plugin_name () const + const std::string &name () const { - return m_plugin_name; + return m_name; } virtual lay::EditorOptionsPage *create_page (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) = 0; private: - std::string m_plugin_name; + std::string m_name; }; /** diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index efd4e1d3f..560396a66 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -400,7 +400,7 @@ LayoutViewBase::init (db::Manager *mgr) mp_canvas = new lay::LayoutCanvas (this); - create_plugins (); + LayoutViewBase::create_plugins (); } void diff --git a/src/laybasic/laybasic/layMouseTracker.cc b/src/laybasic/laybasic/layMouseTracker.cc index 11c128299..9cf30b237 100644 --- a/src/laybasic/laybasic/layMouseTracker.cc +++ b/src/laybasic/laybasic/layMouseTracker.cc @@ -147,11 +147,6 @@ public: { return new MouseTracker (view); } - - virtual bool enable_catchall_editor_options_pages () const - { - return false; - } }; static tl::RegisteredClass tracker_decl (new MouseTrackerDeclaration (), -1000, "laybasic::MouseTrackerPlugin"); diff --git a/src/laybasic/laybasic/layMove.cc b/src/laybasic/laybasic/layMove.cc index cca542403..19d222f8e 100644 --- a/src/laybasic/laybasic/layMove.cc +++ b/src/laybasic/laybasic/layMove.cc @@ -462,6 +462,14 @@ public: { return new MoveService (view); } + + virtual std::vector additional_editor_options_pages () const + { + std::vector names; + // TODO: provide in a central place instead of borrowing from the edt module + names.push_back ("GenericEditorOptions"); + return names; + } }; static tl::RegisteredClass move_service_decl (new MoveServiceDeclaration (), -970, "laybasic::MoveServicePlugin"); diff --git a/src/laybasic/laybasic/layPlugin.cc b/src/laybasic/laybasic/layPlugin.cc index 40a0b77f8..4eff30aac 100644 --- a/src/laybasic/laybasic/layPlugin.cc +++ b/src/laybasic/laybasic/layPlugin.cc @@ -342,7 +342,7 @@ PluginDeclaration::get_editor_options_pages (std::vector::get_instance (); for (auto i = reg->begin (); i != reg->end (); ++i) { lay::EditorOptionsPage *page = 0; - if (i->plugin_name () == n) { + if (i->name () == n) { page = i->create_page (view, dispatcher); if (page) { page->set_plugin_declaration (this); @@ -355,18 +355,28 @@ PluginDeclaration::get_editor_options_pages (std::vector &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) +PluginDeclaration::get_additional_editor_options_pages (std::vector &pages, LayoutViewBase *view, Dispatcher *dispatcher, const std::map > &names) { + std::set names_seen; + auto reg = tl::Registrar::get_instance (); for (auto i = reg->begin (); i != reg->end (); ++i) { - lay::EditorOptionsPage *page = 0; - if (i->plugin_name ().empty ()) { - page = i->create_page (view, dispatcher); + auto n = names.find (i->name ()); + if (n != names.end ()) { + names_seen.insert (i->name ()); + lay::EditorOptionsPage *page = i->create_page (view, dispatcher); if (page) { + page->set_plugin_declarations (n->second); pages.push_back (page); } } } + + for (auto i = names.begin (); i != names.end (); ++i) { + if (names_seen.find (i->first) == names_seen.end ()) { + tl::warn << tl::to_string (tr ("Cannot find additional editor options page: ")) << i->first; + } + } } // ---------------------------------------------------------------- diff --git a/src/laybasic/laybasic/layPlugin.h b/src/laybasic/laybasic/layPlugin.h index 4f1f3a833..17e74b01d 100644 --- a/src/laybasic/laybasic/layPlugin.h +++ b/src/laybasic/laybasic/layPlugin.h @@ -344,26 +344,19 @@ public: virtual void get_editor_options_pages (std::vector &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) const; /** - * @brief Gets the "catchall" editor options pages - * - * These are editor options pages not associated with a specific plugin. - * - * The new pages are returned in the "pages" vector. The layout view will take ownership of these pages. - * - * The implementation collects pages registered through editor options page factories. + * @brief Gets pages created from registered factories by name */ - static void get_catchall_editor_options_pages (std::vector &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher); + static void get_additional_editor_options_pages (std::vector &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher, const std::map > &names); /** - * @brief Gets a value indicating whether "catchall" editor options pages shall be included + * @brief Returns a list of editor options pages that the plugin wants to inherit * - * "catchall" editor options pages are ones that are unspecific and render a null "plugin_declaration". - * A plugin can choose to include these pages if it listens to global configuration events. - * Otherwise it should return false here to suppress these pages. + * In addition to providing pages through "get_editor_options_pages", the plugin can request pages + * from globally registered factories by name. */ - virtual bool enable_catchall_editor_options_pages () const + virtual std::vector additional_editor_options_pages () const { - return true; + return std::vector (); } /** diff --git a/src/laybasic/laybasic/laySelector.cc b/src/laybasic/laybasic/laySelector.cc index b5e7cf4cb..0cc7d4d23 100644 --- a/src/laybasic/laybasic/laySelector.cc +++ b/src/laybasic/laybasic/laySelector.cc @@ -332,11 +332,6 @@ public: { return new SelectionService (view); } - - virtual bool enable_catchall_editor_options_pages () const - { - return false; - } }; static tl::RegisteredClass selection_service_decl (new SelectionServiceDeclaration (), -980, "laybasic::SelectionServicePlugin"); diff --git a/src/laybasic/laybasic/layZoomBox.cc b/src/laybasic/laybasic/layZoomBox.cc index 064209ee2..3f3bd0fc6 100644 --- a/src/laybasic/laybasic/layZoomBox.cc +++ b/src/laybasic/laybasic/layZoomBox.cc @@ -297,11 +297,6 @@ public: { return new ZoomService (view); } - - virtual bool enable_catchall_editor_options_pages () const - { - return false; - } }; static tl::RegisteredClass zoom_service_decl (new ZoomServiceDeclaration (), -990, "laybasic::ZoomServicePlugin"); diff --git a/src/layview/layview/gsiDeclLayPluginFactory.cc b/src/layview/layview/gsiDeclLayPluginFactory.cc index 38cb0a17d..47e8d8b46 100644 --- a/src/layview/layview/gsiDeclLayPluginFactory.cc +++ b/src/layview/layview/gsiDeclLayPluginFactory.cc @@ -313,6 +313,16 @@ public: m_options.push_back (std::make_pair (name, default_value)); } + void add_editor_options_page_by_name (const std::string &name) + { + m_additional_editor_options_pages.push_back (name); + } + + virtual std::vector additional_editor_options_pages () const + { + return m_additional_editor_options_pages; + } + void has_tool_entry (bool f) { m_implements_mouse_mode = f; @@ -335,6 +345,7 @@ public: private: std::vector > m_options; + std::vector m_additional_editor_options_pages; std::vector m_menu_entries; bool m_implements_mouse_mode; std::string m_mouse_mode_title; @@ -474,6 +485,21 @@ Class decl_PluginFactory ("lay", "PluginFactory", "be set using \"set_config\" from \\MainWindow. This scheme also works without registering the configuration options, but " "doing so has the advantage that it is guaranteed that a variable with this keys exists and has the given default value initially." ) + + method ("add_editor_options_page_by_name", &gsi::PluginFactoryBase::add_editor_options_page_by_name, gsi::arg ("name"), + "@brief Requests an additional editor options page from the standard pool.\n" + "This method needs to be called in the initializer of the plugin factory class and before the 'register' call." + "It requests an additional editor options page from the standard pool. 'name' specifies which page is added.\n" + "\n" + "As of now, only 'GenericEditorOptions' is available to provide the basic grid and angle constraints settings. If you " + "wish to enable that page for the plugin, use:\n" + "\n" + "@code\n" + "add_editor_options_page_by_name(\"GenericEditorOptions\")\n" + "@/code\n" + "\n" + "This method has been introduced in version 0.30.6. Before this method was introduced, the generic editor options were " + "always added." + ) + #if defined(HAVE_QTBINDINGS) method ("add_editor_options_page", &PluginFactoryBase::add_editor_options_page, gsi::arg ("page"), "@brief Adds the given editor options page\n" diff --git a/src/layview/layview/layEditorOptionsFrame.cc b/src/layview/layview/layEditorOptionsFrame.cc index 91a640eeb..815db2b65 100644 --- a/src/layview/layview/layEditorOptionsFrame.cc +++ b/src/layview/layview/layEditorOptionsFrame.cc @@ -50,10 +50,17 @@ void EditorOptionsFrame::populate (LayoutViewBase *view) { std::vector editor_options_pages; + std::map > additional_pages; + for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { cls->get_editor_options_pages (editor_options_pages, view, view->dispatcher ()); + std::vector ap = cls->additional_editor_options_pages (); + for (auto i = ap.begin (); i != ap.end (); ++i) { + additional_pages [*i].push_back (cls.operator-> ()); + } } - lay::PluginDeclaration::get_catchall_editor_options_pages (editor_options_pages, view, view->dispatcher ()); + + lay::PluginDeclaration::get_additional_editor_options_pages (editor_options_pages, view, view->dispatcher (), additional_pages); for (std::vector::const_iterator op = editor_options_pages.begin (); op != editor_options_pages.end (); ++op) { (*op)->activate (false); diff --git a/src/layview/layview/layEditorOptionsPages.cc b/src/layview/layview/layEditorOptionsPages.cc index a3093e4a0..d1fd9ecee 100644 --- a/src/layview/layview/layEditorOptionsPages.cc +++ b/src/layview/layview/layEditorOptionsPages.cc @@ -98,8 +98,7 @@ EditorOptionsPages::editor_options_pages (const lay::PluginDeclaration *plugin_d { std::vector pages; for (auto p = m_pages.begin (); p != m_pages.end (); ++p) { - if (p->plugin_declaration () == plugin_declaration || - (p->plugin_declaration () == 0 && plugin_declaration->enable_catchall_editor_options_pages ())) { + if (p->for_plugin_declaration (plugin_declaration)) { pages.push_back (const_cast (p.operator-> ())); } } @@ -164,18 +163,9 @@ EditorOptionsPages::activate (const lay::Plugin *plugin) m_update_enabled = false; for (auto op = m_pages.begin (); op != m_pages.end (); ++op) { - - bool is_active = false; - if (op->plugin_declaration () == 0) { - is_active = (plugin && plugin->plugin_declaration ()->enable_catchall_editor_options_pages ()); - } else if (plugin && plugin->plugin_declaration () == op->plugin_declaration ()) { - is_active = true; - } - BEGIN_PROTECTED - op->activate (is_active); + op->activate (plugin && op->for_plugin_declaration (plugin->plugin_declaration ())); END_PROTECTED - } m_update_enabled = true; diff --git a/src/layview/layview/layLayoutView_qt.cc b/src/layview/layview/layLayoutView_qt.cc index 45f590f2e..f8d8e50ca 100644 --- a/src/layview/layview/layLayoutView_qt.cc +++ b/src/layview/layview/layLayoutView_qt.cc @@ -867,6 +867,11 @@ LayoutView *LayoutView::current () void LayoutView::create_plugins (const lay::PluginDeclaration *except_this) { LayoutViewBase::create_plugins (except_this); + + if (mp_editor_options_frame) { + mp_editor_options_frame->populate (this); + } + dm_setup_editor_option_pages (); }