Fixed #486 ('save as' feature for macros)

This commit is contained in:
Matthias Koefferlein 2020-02-23 14:10:26 +01:00
parent 99f22c3221
commit 7d7c9aecc6
4 changed files with 64 additions and 15 deletions

View File

@ -1572,6 +1572,14 @@ p, li { white-space: pre-wrap; }
<string>Ctrl+F</string>
</property>
</action>
<action name="actionSaveAs">
<property name="text">
<string>Save As</string>
</property>
<property name="toolTip">
<string>Save As</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -314,6 +314,7 @@ MacroEditorDialog::MacroEditorDialog (lay::PluginRoot *pr, lym::MacroCollection
macro_tree->addAction (s3);
macro_tree->addAction (actionSaveAll);
macro_tree->addAction (actionSave);
macro_tree->addAction (actionSaveAs);
macro_tree->header ()->hide ();
@ -422,6 +423,7 @@ MacroEditorDialog::MacroEditorDialog (lay::PluginRoot *pr, lym::MacroCollection
connect (actionSaveAll, SIGNAL (triggered ()), this, SLOT (save_all_button_clicked ()));
connect (saveButton, SIGNAL (clicked ()), this, SLOT (save_button_clicked ()));
connect (actionSave, SIGNAL (triggered ()), this, SLOT (save_button_clicked ()));
connect (actionSaveAs, SIGNAL (triggered ()), this, SLOT (save_as_button_clicked ()));
connect (dbgOn, SIGNAL (clicked (bool)), this, SLOT (set_debugging_on (bool)));
connect (runButton, SIGNAL (clicked ()), this, SLOT (run_button_clicked ()));
connect (runThisButton, SIGNAL (clicked ()), this, SLOT (run_this_button_clicked ()));
@ -1996,7 +1998,40 @@ BEGIN_PROTECTED
END_PROTECTED
}
void
void
MacroEditorDialog::save_as_button_clicked ()
{
if (m_in_exec) {
return;
}
BEGIN_PROTECTED
lym::Macro *m = current_macro_tree ()->current_macro ();
if (! m) {
return;
}
lay::FileDialog file_dialog (lay::MainWindow::instance (), tl::to_string (QObject::tr ("Save Macro As")), tl::to_string (QObject::tr ("All files (*)")), "");
std::string fn = m->path ();
if (file_dialog.get_save (fn)) {
m->save_to (fn);
reload_macros ();
lym::Macro *lym = mp_root->find_macro (fn);
if (lym) {
open_macro (lym);
}
}
END_PROTECTED
}
void
MacroEditorDialog::setup_button_clicked ()
{
if (m_in_exec) {
@ -2089,11 +2124,7 @@ MacroEditorDialog::new_macro()
// we don't want to keep the template's description
m->set_description (std::string ());
MacroEditorPage *page = create_page (m);
int index = tabWidget->addTab (page, tl::to_qstring (m->name ()));
tabWidget->setTabToolTip (index, tl::to_qstring (m->summary ()));
tabWidget->setCurrentWidget (page);
m_tab_widgets.insert (std::make_pair (m, page));
open_macro (m);
// NOTE: we save to make the file watcher go silent and to keep the file system in sync
m->save ();
@ -2710,6 +2741,16 @@ BEGIN_PROTECTED
END_PROTECTED
}
void
MacroEditorDialog::open_macro (lym::Macro *m)
{
MacroEditorPage *page = create_page (m);
m_tab_widgets.insert (std::make_pair (m, page));
int index = tabWidget->addTab (page, tl::to_qstring (m->name ()));
tabWidget->setTabToolTip (index, tl::to_qstring (m->summary ()));
tabWidget->setCurrentWidget (page);
}
void
MacroEditorDialog::item_double_clicked(lym::Macro *m)
{
@ -2717,13 +2758,7 @@ BEGIN_PROTECTED
std::map <lym::Macro *, MacroEditorPage *>::iterator page = m_tab_widgets.find (m);
if (page == m_tab_widgets.end ()) {
MacroEditorPage *page = create_page (m);
m_tab_widgets.insert (std::make_pair (m, page));
int index = tabWidget->addTab (page, tl::to_qstring (m->name ()));
tabWidget->setTabToolTip (index, tl::to_qstring (m->summary ()));
tabWidget->setCurrentWidget (page);
open_macro (m);
} else {
tabWidget->setCurrentIndex (tabWidget->indexOf (page->second));
}

View File

@ -186,6 +186,7 @@ private slots:
void new_folder_button_clicked ();
void save_all_button_clicked ();
void save_button_clicked ();
void save_as_button_clicked ();
void run_button_clicked ();
void run_this_button_clicked ();
void single_step_button_clicked ();
@ -255,6 +256,7 @@ private:
lym::Macro *create_macro_here(const char *name = 0);
void move_subfolder (lym::MacroCollection *source, lym::MacroCollection *target);
lay::MacroEditorPage *create_page (lym::Macro *macro);
void open_macro (lym::Macro *macro);
void ensure_writeable_collection_selected ();
void update_console_text ();
void start_exec (gsi::Interpreter *interpreter);

View File

@ -176,10 +176,15 @@ public:
std::string path () const;
/**
* @brief Saves the macro to the specificed path
* @brief Saves the macro to it's path
*/
void save ();
/**
* @brief Saves the macro to the specificed path
*/
void save_to (const std::string &path);
/**
* @brief Delete the original file (the file behind the macro)
*
@ -601,7 +606,6 @@ private:
void on_menu_needs_update ();
void on_changed ();
void save_to (const std::string &path);
static bool format_from_suffix_string (const std::string &suffix, Macro::Interpreter &interpreter, std::string &dsl_name, bool &autorun_pref, Macro::Format &format);
static std::pair<bool, std::string> format_from_filename (const std::string &fn, Macro::Interpreter &interpreter, std::string &dsl_name, bool &autorun_pref, Macro::Format &format);