Fixed issue #1486 (Some macros are configured to run automatically - when changing reader options)

This commit is contained in:
Matthias Koefferlein 2023-10-01 20:08:42 +02:00
parent 75e3c3131f
commit 1a0d54d2ae
5 changed files with 45 additions and 30 deletions

View File

@ -817,10 +817,8 @@ ApplicationBase::init_app ()
}
}
std::set<std::string> 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 ();

View File

@ -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) {

View File

@ -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;

View File

@ -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<std::string> *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<std::string> *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<std::string> *already_executed)
void MacroCollection::autorun ()
{
autorun_for (*this, false, already_executed);
autorun_for (*this, false);
}
void MacroCollection::autorun_early (std::set<std::string> *already_executed)
void MacroCollection::autorun_early ()
{
autorun_for (*this, true, already_executed);
autorun_for (*this, true);
}
void MacroCollection::dump (int l)

View File

@ -419,7 +419,7 @@ public:
/**
* @brief Runs all macros marked with auto-run
*/
void autorun (std::set<std::string> *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<std::string> *already_executed = 0);
void autorun_early ();
/**
* @brief Redo the scan (will add new files or folders)