diff --git a/synfig-studio/src/gui/app.cpp b/synfig-studio/src/gui/app.cpp index f9324cf..bfc75f6 100644 --- a/synfig-studio/src/gui/app.cpp +++ b/synfig-studio/src/gui/app.cpp @@ -89,7 +89,6 @@ #include "dialogs/dialog_gradient.h" #include "dialogs/dialog_input.h" #include "dialogs/dialog_color.h" -#include "mainwindow.h" #include "docks/dock_toolbox.h" #include "onemoment.h" @@ -1409,7 +1408,7 @@ App::App(const synfig::String& basepath, int *argc, char ***argv): // Initialize the Synfig library try { synfigapp_main=etl::smart_ptr(new synfigapp::Main(basepath,&synfig_init_cb)); } - catch(std::runtime_error x) + catch(std::runtime_error &x) { get_ui_interface()->error(strprintf("%s\n\n%s", _("Failed to initialize synfig!"), x.what())); throw; @@ -1711,7 +1710,7 @@ App::App(const synfig::String& basepath, int *argc, char ***argv): details, _("Got it")); } - catch(String x) + catch(String &x) { get_ui_interface()->error(_("Unknown exception caught when constructing App.\nThis software may be unstable.") + String("\n\n") + x); } @@ -2774,6 +2773,34 @@ App::dialog_open_file_with_history_button(const std::string &title, std::string #endif // not USE_WIN32_FILE_DIALOGS } +bool +App::dialog_open_folder(const std::string &title, std::string &foldername, std::string preference, Gtk::Window& transientwind) +{ + synfig::String prev_path; + synfigapp::Settings settings; + if(settings.get_value(preference, prev_path)) + prev_path = "."; + + prev_path = absolute_path(prev_path); + + Gtk::FileChooserDialog *dialog = new Gtk::FileChooserDialog(*App::main_window, + title, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); + + dialog->set_transient_for(transientwind); + dialog->set_current_folder(prev_path); + dialog->add_button(_("Cancel"), Gtk::RESPONSE_CANCEL)->set_image_from_icon_name("gtk-cancel", Gtk::ICON_SIZE_BUTTON); + dialog->add_button(_("Open"), Gtk::RESPONSE_ACCEPT)->set_image_from_icon_name("gtk-open", Gtk::ICON_SIZE_BUTTON); + + if(dialog->run() == GTK_RESPONSE_ACCEPT) + { + foldername = dialog->get_filename(); + delete dialog; + return true; + } + delete dialog; + return false; +} + bool App::dialog_save_file(const std::string &title, std::string &filename, std::string preference) @@ -3559,7 +3586,7 @@ App::open_as(std::string filename,std::string as,synfig::FileContainerZip::file_ instance->dialog_cvs_update(); } } - catch(String x) + catch(String &x) { dialog_message_1b( "ERROR", @@ -3569,7 +3596,7 @@ App::open_as(std::string filename,std::string as,synfig::FileContainerZip::file_ return false; } - catch(runtime_error x) + catch(runtime_error &x) { dialog_message_1b( "ERROR", @@ -3652,7 +3679,7 @@ App::open_from_temporary_container_as(std::string container_filename_base,std::s instance->dialog_cvs_update(); } } - catch(String x) + catch(String &x) { dialog_message_1b( "ERROR", @@ -3662,7 +3689,7 @@ App::open_from_temporary_container_as(std::string container_filename_base,std::s return false; } - catch(runtime_error x) + catch(runtime_error &x) { dialog_message_1b( "ERROR", diff --git a/synfig-studio/src/gui/app.h b/synfig-studio/src/gui/app.h index bf0b356..36d4f2d 100644 --- a/synfig-studio/src/gui/app.h +++ b/synfig-studio/src/gui/app.h @@ -49,6 +49,7 @@ #include #include #include "iconcontroller.h" +#include "mainwindow.h" /* === M A C R O S ========================================================= */ @@ -377,6 +378,7 @@ public: static bool dialog_open_file_image(const std::string &title, std::string &filename, std::string preference); static bool dialog_open_file_audio(const std::string &title, std::string &filename, std::string preference); static bool dialog_open_file_with_history_button(const std::string &title, std::string &filename, bool &show_history, std::string preference); + static bool dialog_open_folder(const std::string &title, std::string &filename, std::string preference, Gtk::Window& transientwind=*App::main_window); static bool dialog_save_file(const std::string &title, std::string &filename, std::string preference); static bool dialog_save_file_spal(const std::string &title, std::string &filename, std::string preference); static bool dialog_save_file_sketch(const std::string &title, std::string &filename, std::string preference); diff --git a/synfig-studio/src/gui/dialogs/dialog_setup.cpp b/synfig-studio/src/gui/dialogs/dialog_setup.cpp index 162cae7..a142ecf 100644 --- a/synfig-studio/src/gui/dialogs/dialog_setup.cpp +++ b/synfig-studio/src/gui/dialogs/dialog_setup.cpp @@ -34,7 +34,6 @@ #endif #include "app.h" -#include "mainwindow.h" #include "dialogs/dialog_setup.h" #include #include @@ -50,8 +49,6 @@ #include -#include -#include #include #include "dialogs/dialog_setup.h" @@ -1477,43 +1474,14 @@ Dialog_Setup::on_treeviewselection_changed() void Dialog_Setup::on_brush_path_add_clicked() { - - bool newpath(false); - synfig::String dir_name, dialog_title(_("Select a new path for brush")); - //! TODO Make it app member - { - synfig::String prev_path; - synfigapp::Settings settings; - if(settings.get_value(MISC_DIR_PREFERENCE, prev_path)) - prev_path = "."; - - prev_path = absolute_path(prev_path); - - Gtk::FileChooserDialog *dialog = new Gtk::FileChooserDialog(*App::main_window, - dialog_title, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); - - dialog->set_transient_for(*this); - dialog->set_current_folder(prev_path); - dialog->add_button(_("Cancel"), Gtk::RESPONSE_CANCEL)->set_image_from_icon_name("gtk-cancel", Gtk::ICON_SIZE_BUTTON); - dialog->add_button(_("Open"), Gtk::RESPONSE_ACCEPT)->set_image_from_icon_name("gtk-open", Gtk::ICON_SIZE_BUTTON); - - if(dialog->run() == GTK_RESPONSE_ACCEPT) - { - dir_name = dialog->get_filename(); - newpath = true; - //delete dialog; - //return true; - } - delete dialog; - } - - if(newpath) + synfig::String foldername; + if(App::dialog_open_folder(_("Select a new path for brush"), foldername, MISC_DIR_PREFERENCE, *this)) { // add the new path Glib::RefPtr liststore = Glib::RefPtr::cast_dynamic( listviewtext_brushes_path->get_model()); Gtk::TreeIter it(liststore->append()); - (*it)[prefs_brushpath.path]=dir_name; + (*it)[prefs_brushpath.path]=foldername; // high light it in the brush path list listviewtext_brushes_path->scroll_to_row(listviewtext_brushes_path->get_model()->get_path(*it)); listviewtext_brushes_path->get_selection()->select(listviewtext_brushes_path->get_model()->get_path(*it));