From c5017c811edfb17f9e814bbc96660fb073654ddc Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 28 Oct 2017 22:37:52 +0200 Subject: [PATCH] Bugfix: avoid data loss in macro editor The bug was this: - A macro is opened and modified in the macro IDE - The directory which the macro is kept in is touched Effect: the macro was reloaded and the edits were discarded. --- src/lay/lay/layMacroController.cc | 2 +- src/lay/lay/layMacroEditorDialog.cc | 2 +- src/lym/lym/lymMacro.cc | 12 ++++++------ src/lym/lym/lymMacro.h | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lay/lay/layMacroController.cc b/src/lay/lay/layMacroController.cc index a0edfb34f..3ea71c08a 100644 --- a/src/lay/lay/layMacroController.cc +++ b/src/lay/lay/layMacroController.cc @@ -779,7 +779,7 @@ void MacroController::sync_files () { tl::log << tl::to_string (tr ("Detected file system change in macro folders - updating")); - lym::MacroCollection::root ().reload (); + lym::MacroCollection::root ().reload (true /*safe*/); } MacroController * diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 2c41953a2..6dca6adbc 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -2454,7 +2454,7 @@ MacroEditorDialog::reload_macros () { m_file_watcher->clear (); try { - mp_root->reload (); + mp_root->reload (false); refresh_file_watcher (); } catch (...) { refresh_file_watcher (); diff --git a/src/lym/lym/lymMacro.cc b/src/lym/lym/lymMacro.cc index c2a144c1c..bd253a8db 100644 --- a/src/lym/lym/lymMacro.cc +++ b/src/lym/lym/lymMacro.cc @@ -1682,7 +1682,7 @@ MacroCollection &MacroCollection::root () return ms_root; } -static bool sync_macros (lym::MacroCollection *current, lym::MacroCollection *actual) +static bool sync_macros (lym::MacroCollection *current, lym::MacroCollection *actual, bool safe) { bool ret = false; @@ -1706,7 +1706,7 @@ static bool sync_macros (lym::MacroCollection *current, lym::MacroCollection *ac cm = current->create_folder (m->first.c_str (), false); ret = true; } - if (sync_macros(cm, m->second)) { + if (sync_macros(cm, m->second, safe)) { ret = true; } } @@ -1715,7 +1715,7 @@ static bool sync_macros (lym::MacroCollection *current, lym::MacroCollection *ac // delete folders which do no longer exist for (std::vector::iterator m = folders_to_delete.begin (); m != folders_to_delete.end (); ++m) { ret = true; - sync_macros (*m, 0); + sync_macros (*m, 0, safe); current->erase (*m); } @@ -1732,7 +1732,7 @@ static bool sync_macros (lym::MacroCollection *current, lym::MacroCollection *ac for (lym::MacroCollection::iterator m = actual->begin (); m != actual->end (); ++m) { lym::Macro *cm = current->macro_by_name (m->first, m->second->format ()); if (cm) { - if (*cm != *m->second) { + if (*cm != *m->second && (! safe || ! cm->is_modified ())) { cm->assign (*m->second); } cm->set_readonly (m->second->is_readonly ()); @@ -1754,7 +1754,7 @@ static bool sync_macros (lym::MacroCollection *current, lym::MacroCollection *ac return ret; } -void MacroCollection::reload () +void MacroCollection::reload (bool safe) { // create a new collection and synchronize @@ -1764,7 +1764,7 @@ void MacroCollection::reload () } // and synchronize current with the actual one - sync_macros (this, &new_collection); + sync_macros (this, &new_collection, safe); } static bool has_autorun_for (const lym::MacroCollection &collection, bool early) diff --git a/src/lym/lym/lymMacro.h b/src/lym/lym/lymMacro.h index e3a6f66d0..9d7e65474 100644 --- a/src/lym/lym/lymMacro.h +++ b/src/lym/lym/lymMacro.h @@ -1005,8 +1005,9 @@ public: * @brief Reloads the macro collection * * This method is similar to rescan, but it will also remove folders and macros. + * In safe mode (safe = true), modified macros won't be overwritten. */ - void reload (); + void reload (bool safe); /** * @brief Gets the root of the macro hierarchy corresponding to the configuration space