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.
This commit is contained in:
Matthias Koefferlein 2017-10-28 22:37:52 +02:00
parent 6ee4ba6a90
commit c5017c811e
4 changed files with 10 additions and 9 deletions

View File

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

View File

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

View File

@ -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<lym::MacroCollection *>::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)

View File

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