From 1a0d54d2ae0adedd0ad8e662a74d3b7ce43a5792 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 1 Oct 2023 20:08:42 +0200 Subject: [PATCH] Fixed issue #1486 (Some macros are configured to run automatically - when changing reader options) --- src/lay/lay/layApplication.cc | 8 +++---- src/lym/lym/lymMacro.cc | 12 +++++++++- src/lym/lym/lymMacro.h | 14 ++++++++++++ src/lym/lym/lymMacroCollection.cc | 37 +++++++++++++------------------ src/lym/lym/lymMacroCollection.h | 4 ++-- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/lay/lay/layApplication.cc b/src/lay/lay/layApplication.cc index b4309db4a..e7c54f768 100644 --- a/src/lay/lay/layApplication.cc +++ b/src/lay/lay/layApplication.cc @@ -817,10 +817,8 @@ ApplicationBase::init_app () } } - std::set already_executed; - // run all early autorun macros - lym::MacroCollection::root ().autorun_early (&already_executed); + lym::MacroCollection::root ().autorun_early (); // redo gsi::initialize as the macros may have registered new external classes // through the "doc to external class" mechanism. @@ -833,7 +831,7 @@ ApplicationBase::init_app () // as this regenerates the macro collection, autorun_early is required again // note: this does no re-execute macros that have been executed already - lym::MacroCollection::root ().autorun_early (&already_executed); + lym::MacroCollection::root ().autorun_early (); } @@ -842,7 +840,7 @@ ApplicationBase::init_app () lym::MacroCollection::root ().rescan (); // and yet another autorun_early pass .. - lym::MacroCollection::root ().autorun_early (&already_executed); + lym::MacroCollection::root ().autorun_early (); // creates the main window or plugin root as required setup (); diff --git a/src/lym/lym/lymMacro.cc b/src/lym/lym/lymMacro.cc index ac179c0ea..e6884cce1 100644 --- a/src/lym/lym/lymMacro.cc +++ b/src/lym/lym/lymMacro.cc @@ -55,7 +55,10 @@ namespace lym // ---------------------------------------------------------------------- Macro::Macro () - : m_modified (true), m_readonly (false), m_autorun (false), m_autorun_default (false), m_autorun_early (false), m_priority (0), m_show_in_menu (false), m_is_file (false), m_interpreter (None), m_format (Macro::NoFormat) + : m_modified (true), m_readonly (false), + m_autorun (false), m_autorun_default (false), m_autorun_early (false), m_was_autorun (false), + m_priority (0), m_show_in_menu (false), m_is_file (false), + m_interpreter (None), m_format (Macro::NoFormat) { mp_parent = 0; } @@ -70,6 +73,8 @@ void Macro::on_menu_needs_update () void Macro::on_changed () { + m_was_autorun = false; + #if defined(HAVE_QT) emit changed (); if (mp_parent) { @@ -796,6 +801,11 @@ void Macro::set_autorun (bool f) } } +void Macro::set_was_autorun (bool f) +{ + m_was_autorun = f; +} + void Macro::set_priority (int p) { if (p != m_priority) { diff --git a/src/lym/lym/lymMacro.h b/src/lym/lym/lymMacro.h index 10acb6f36..88af3159d 100644 --- a/src/lym/lym/lymMacro.h +++ b/src/lym/lym/lymMacro.h @@ -426,6 +426,19 @@ public: return m_autorun_early; } + /** + * @brief Sets a value indicating whether the macro was alread auto-runned + */ + void set_was_autorun (bool f); + + /** + * @brief Gets a value indicating whether the macro was alread auto-runned + */ + bool was_autorun () const + { + return m_was_autorun; + } + /** * @brief Sets a value indicating whether the macro shall be executed on startup */ @@ -618,6 +631,7 @@ private: bool m_autorun; bool m_autorun_default; bool m_autorun_early; + bool m_was_autorun; int m_priority; bool m_show_in_menu; std::string m_group_name; diff --git a/src/lym/lym/lymMacroCollection.cc b/src/lym/lym/lymMacroCollection.cc index 6712d6549..4982ae192 100644 --- a/src/lym/lym/lymMacroCollection.cc +++ b/src/lym/lym/lymMacroCollection.cc @@ -868,7 +868,7 @@ static bool has_autorun_for (const lym::MacroCollection &collection, bool early) } for (lym::MacroCollection::const_iterator c = collection.begin (); c != collection.end (); ++c) { - if ((early && c->second->is_autorun_early ()) || (!early && c->second->is_autorun () && !c->second->is_autorun_early ())) { + if (((early && c->second->is_autorun_early ()) || (!early && c->second->is_autorun () && !c->second->is_autorun_early ())) && ! c->second->was_autorun ()) { return true; } } @@ -909,35 +909,28 @@ static int collect_priority (lym::MacroCollection &collection, bool early, int f return p; } -static void autorun_for_prio (lym::MacroCollection &collection, bool early, std::set *executed_already, int prio) +static void autorun_for_prio (lym::MacroCollection &collection, bool early, int prio) { for (lym::MacroCollection::child_iterator c = collection.begin_children (); c != collection.end_children (); ++c) { - autorun_for_prio (*c->second, early, executed_already, prio); + autorun_for_prio (*c->second, early, prio); } for (lym::MacroCollection::iterator c = collection.begin (); c != collection.end (); ++c) { - if (c->second->priority () == prio && c->second->can_run () && ((early && c->second->is_autorun_early ()) || (!early && c->second->is_autorun () && !c->second->is_autorun_early ()))) { + if (! c->second->was_autorun () && c->second->priority () == prio && c->second->can_run () && ((early && c->second->is_autorun_early ()) || (!early && c->second->is_autorun () && !c->second->is_autorun_early ()))) { - if (!executed_already || executed_already->find (c->second->path ()) == executed_already->end ()) { - - BEGIN_PROTECTED_SILENT - c->second->run (); - c->second->install_doc (); - END_PROTECTED_SILENT - - if (executed_already) { - executed_already->insert (c->second->path ()); - } - - } + BEGIN_PROTECTED_SILENT + c->second->run (); + c->second->set_was_autorun (true); + c->second->install_doc (); + END_PROTECTED_SILENT } } } -static void autorun_for (lym::MacroCollection &collection, bool early, std::set *executed_already) +static void autorun_for (lym::MacroCollection &collection, bool early) { int prio = 0; while (true) { @@ -945,19 +938,19 @@ static void autorun_for (lym::MacroCollection &collection, bool early, std::set< if (p < prio) { break; } - autorun_for_prio (collection, early, executed_already, p); + autorun_for_prio (collection, early, p); prio = p + 1; } } -void MacroCollection::autorun (std::set *already_executed) +void MacroCollection::autorun () { - autorun_for (*this, false, already_executed); + autorun_for (*this, false); } -void MacroCollection::autorun_early (std::set *already_executed) +void MacroCollection::autorun_early () { - autorun_for (*this, true, already_executed); + autorun_for (*this, true); } void MacroCollection::dump (int l) diff --git a/src/lym/lym/lymMacroCollection.h b/src/lym/lym/lymMacroCollection.h index 60c779bc5..427f68262 100644 --- a/src/lym/lym/lymMacroCollection.h +++ b/src/lym/lym/lymMacroCollection.h @@ -419,7 +419,7 @@ public: /** * @brief Runs all macros marked with auto-run */ - void autorun (std::set *already_executed = 0); + void autorun (); /** * @brief Returns true, if the collection has an early autorun macro @@ -429,7 +429,7 @@ public: /** * @brief Runs all macros marked with early auto-run */ - void autorun_early (std::set *already_executed = 0); + void autorun_early (); /** * @brief Redo the scan (will add new files or folders)