From 6365ddfe828bd1432209bac7c7060bd5f0c61065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Fri, 3 Jul 2020 23:41:52 +0200 Subject: [PATCH] Fixed #591 (two topics for macro editor) (#595) * Fixed #591 (crash on Macro/Add Location) The main reason was that the QSortFilterProxyModel is very sensitive to the order of signals it receives from the proxy model. In this case, dataChanged() must not be send between layoutAboutToBeChanged() and layoutChanged(). This happened implicitly during load() of a macro while scanning the freshly added folder. * Fixed another part of #591: ability to disable template selection pop-up in macro editor. Tied to the tip window now - if this is dismissed, no template selection dialog will be shown. --- src/buddies/src/bd/strmrun.cc | 1 + src/lay/lay/layMacroEditorDialog.cc | 15 ++++++---- src/laybasic/laybasic/layTipDialog.cc | 40 +++++++++++++++++++-------- src/laybasic/laybasic/layTipDialog.h | 5 ++++ src/lym/lym/lymMacro.cc | 21 +++++++------- 5 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/buddies/src/bd/strmrun.cc b/src/buddies/src/bd/strmrun.cc index 796966259..f76976389 100644 --- a/src/buddies/src/bd/strmrun.cc +++ b/src/buddies/src/bd/strmrun.cc @@ -87,5 +87,6 @@ BD_PUBLIC int strmrun (int argc, char *argv[]) lym::Macro macro; macro.load_from (script); + macro.set_file_path (script); return macro.run (); } diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 308bf4d8e..1b33d9429 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -668,18 +668,21 @@ BEGIN_PROTECTED } } - if (collection && (force_add || (collection->begin () == collection->end () && collection->begin_children () == collection->end_children ()))) { + bool open_template_dialog = false; + if (! force_add && collection && (collection->begin () == collection->end () && collection->begin_children () == collection->end_children ())) { + TipDialog td (this, + tl::to_string (QObject::tr ("To get started with the macro development feature, read the documentation provided: About Macro Development.")), + "macro-editor-basic-tips"); + open_template_dialog = td.exec_dialog () && td.will_be_shown (); + } + + if (collection && (force_add || open_template_dialog)) { lym::Macro *m = new_macro (); if (force_add && m) { set_run_macro (m); } } - TipDialog td (this, - tl::to_string (QObject::tr ("To get started with the macro development feature, read the documentation provided: About Macro Development.")), - "macro-editor-basic-tips"); - td.exec_dialog (); - } else { if (! cat.empty ()) { diff --git a/src/laybasic/laybasic/layTipDialog.cc b/src/laybasic/laybasic/layTipDialog.cc index b4510d4da..416f64468 100644 --- a/src/laybasic/laybasic/layTipDialog.cc +++ b/src/laybasic/laybasic/layTipDialog.cc @@ -128,12 +128,9 @@ TipDialog::no_pressed () accept (); } -bool -TipDialog::do_exec_dialog (button_type *button) +static std::pair +tip_dialog_status (const std::string &key) { - bool must_show = true; - mp_res = button; - std::string th; if (lay::Dispatcher::instance ()) { lay::Dispatcher::instance ()->config_get (cfg_tip_window_hidden, th); @@ -148,20 +145,39 @@ TipDialog::do_exec_dialog (button_type *button) } int r = -1; ex.test ("=") && ex.try_read (r); - if (k == m_key) { - if (r >= 0) { - *mp_res = button_type (r); - } - must_show = false; - break; + if (k == key) { + return std::make_pair (false, r); } ex.test (","); } - if (must_show) { + return std::make_pair (true, -1); +} + +bool +TipDialog::will_be_shown () +{ + return tip_dialog_status (m_key).first; +} + +bool +TipDialog::do_exec_dialog (button_type *button) +{ + mp_res = button; + + std::string th; + if (lay::Dispatcher::instance ()) { + lay::Dispatcher::instance ()->config_get (cfg_tip_window_hidden, th); + } + + std::pair td_status = tip_dialog_status (m_key); + if (td_status.first) { exec (); return true; } else { + if (td_status.second >= 0) { + *mp_res = button_type (td_status.second); + } return false; } } diff --git a/src/laybasic/laybasic/layTipDialog.h b/src/laybasic/laybasic/layTipDialog.h index 90627304f..4a0a74618 100644 --- a/src/laybasic/laybasic/layTipDialog.h +++ b/src/laybasic/laybasic/layTipDialog.h @@ -65,6 +65,11 @@ public: */ ~TipDialog (); + /** + * @brief Returns true, if the tip dialog will be shown + */ + bool will_be_shown (); + /** * @brief Show the dialog * diff --git a/src/lym/lym/lymMacro.cc b/src/lym/lym/lymMacro.cc index 1cfefd7b1..0c00c2847 100644 --- a/src/lym/lym/lymMacro.cc +++ b/src/lym/lym/lymMacro.cc @@ -251,6 +251,7 @@ void Macro::load_from (const std::string &fn) } m_modified = true; + m_is_file = true; on_changed (); } @@ -293,9 +294,6 @@ void Macro::load_from_string (const std::string &text, const std::string &url) void Macro::load () { load_from (path ()); - m_modified = false; - m_is_file = true; - on_changed (); } bool @@ -449,13 +447,13 @@ void Macro::reset_modified () bool Macro::rename (const std::string &n) { - if (m_is_file) { + if (m_is_file && parent ()) { std::string suffix = suffix_for_format (m_interpreter, m_dsl_interpreter, m_format); if (tl::verbosity () >= 20) { tl::log << "Renaming macro " << path () << " to " << n; } QFile f (tl::to_qstring (path ())); - if (! f.rename (QFileInfo (QDir (tl::to_qstring (mp_parent->path ())), tl::to_qstring (n + suffix)).filePath ())) { + if (! f.rename (QFileInfo (QDir (tl::to_qstring (parent ()->path ())), tl::to_qstring (n + suffix)).filePath ())) { return false; } } @@ -1294,14 +1292,15 @@ MacroCollection::add_folder (const std::string &description, const std::string & begin_changes (); MacroCollection *mc = m_folders.insert (std::make_pair (path, new MacroCollection ())).first->second; - mc->set_parent (this); mc->set_name (path); mc->set_description (description); mc->set_category (cat); mc->set_readonly (readonly); mc->scan (path); + mc->set_parent (this); on_changed (); + on_macro_changed (0); return mc; } @@ -1376,7 +1375,6 @@ void MacroCollection::scan (const std::string &path) } if (! found) { Macro *m = m_macros.insert (std::make_pair (n, new Macro ()))->second; - m->set_parent (this); m->set_interpreter (interpreter); m->set_autorun_default (autorun); m->set_autorun (autorun); @@ -1387,6 +1385,7 @@ void MacroCollection::scan (const std::string &path) m->set_readonly (m_readonly); m->reset_modified (); m->set_is_file (); + m->set_parent (this); } } @@ -1425,6 +1424,7 @@ void MacroCollection::scan (const std::string &path) try { std::string n = tl::to_string (QFileInfo (*f).completeBaseName ()); + std::string mp = tl::to_string (dir.absoluteFilePath (*f)); Macro::Format format = Macro::NoFormat; Macro::Interpreter interpreter = Macro::None; @@ -1451,10 +1451,11 @@ void MacroCollection::scan (const std::string &path) m->set_autorun (autorun); m->set_interpreter (interpreter); m->set_dsl_interpreter (dsl_name); - m->set_parent (this); m->set_name (n); - m->load (); + m->load_from (mp); + m->reset_modified (); m->set_readonly (m_readonly); + m->set_parent (this); } } @@ -1478,12 +1479,12 @@ void MacroCollection::scan (const std::string &path) MacroCollection *&mc = m_folders.insert (std::make_pair (n, (MacroCollection *) 0)).first->second; if (! mc) { mc = new MacroCollection (); - mc->set_parent (this); mc->set_name (n); mc->set_virtual_mode (NotVirtual); bool ro = (m_readonly || ! QFileInfo (dir.filePath (*f)).isWritable ()); mc->set_readonly (ro); mc->scan (tl::to_string (dir.filePath (*f))); + mc->set_parent (this); } } catch (tl::Exception &ex) {