From 2d39bd620f88ae2e13b5be39d57f8dcd7618f079 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 Feb 2015 06:48:08 +0000 Subject: Clean up save dialog stuff. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5563 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/GraphBox.cpp | 67 ++++++++++++++++++++++++++++------------------------ src/gui/GraphBox.hpp | 9 +++---- 2 files changed, 41 insertions(+), 35 deletions(-) (limited to 'src/gui') diff --git a/src/gui/GraphBox.cpp b/src/gui/GraphBox.cpp index d2387d24..8e59c0e7 100644 --- a/src/gui/GraphBox.cpp +++ b/src/gui/GraphBox.cpp @@ -469,18 +469,30 @@ GraphBox::event_save() } } -int -GraphBox::message_dialog(const Glib::ustring& message, - const Glib::ustring& secondary_text, - Gtk::MessageType type, - Gtk::ButtonsType buttons) +void +GraphBox::error(const Glib::ustring& message, + const Glib::ustring& secondary_text) { - Gtk::MessageDialog dialog(message, true, type, buttons, true); + Gtk::MessageDialog dialog( + message, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); dialog.set_secondary_text(secondary_text); if (_window) { dialog.set_transient_for(*_window); } - return dialog.run(); + dialog.run(); +} + +bool +GraphBox::confirm(const Glib::ustring& message, + const Glib::ustring& secondary_text) +{ + Gtk::MessageDialog dialog( + message, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); + dialog.set_secondary_text(secondary_text); + if (_window) { + dialog.set_transient_for(*_window); + } + return dialog.run() == Gtk::RESPONSE_YES; } void @@ -488,7 +500,8 @@ GraphBox::event_save_as() { const URIs& uris = _app->uris(); while (true) { - Gtk::FileChooserDialog dialog("Save Graph", Gtk::FILE_CHOOSER_ACTION_SAVE); + Gtk::FileChooserDialog dialog( + "Save Graph", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); if (_window) { dialog.set_transient_for(*_window); } @@ -519,57 +532,49 @@ GraphBox::event_save_as() if (basename.find('.') == std::string::npos) { filename += ".ingen"; basename += ".ingen"; - } else if (filename.substr(filename.length() - 10) != ".ingen") { - message_dialog( - "Ingen graphs must be saved to Ingen bundles (*.ingen).", - "", Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK); + } else if (filename.substr(filename.length() - 6) != ".ingen") { + error("Ingen bundles must end in \".ingen\""); continue; } const std::string symbol(basename.substr(0, basename.find('.'))); if (!Raul::Symbol::is_valid(symbol)) { - message_dialog( + error( "Ingen bundle names must be valid symbols.", - "All characters must be _, a-z, A-Z, or 0-9, but the first may not be 0-9.", - Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK); + "All characters must be _, a-z, A-Z, or 0-9, but the first may not be 0-9."); continue; } //_graph->set_property(uris.lv2_symbol, Atom(symbol.c_str())); - bool confirm = true; + bool confirmed = true; if (Glib::file_test(filename, Glib::FILE_TEST_IS_DIR)) { if (Glib::file_test(Glib::build_filename(filename, "manifest.ttl"), Glib::FILE_TEST_EXISTS)) { - int ret = message_dialog( - (boost::format("A bundle named \"%1%\" already exists." - " Replace it?") % basename).str(), - "", Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO); - confirm = (ret == Gtk::RESPONSE_YES); + confirmed = confirm( + (boost::format("The bundle \"%1%\" already exists." + " Replace it?") % basename).str()); } else { - int ret = message_dialog( + confirmed = confirm( (boost::format("A directory named \"%1%\" already exists," "but is not an Ingen bundle. " "Save into it anyway?") % basename).str(), "This will create at least 2 .ttl files in this directory," "and possibly several more files and/or directories, recursively. " - "Existing files will be overwritten.", - Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO); - confirm = (ret == Gtk::RESPONSE_YES); + "Existing files will be overwritten."); } } else if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) { - int ret = message_dialog( + confirmed = confirm( (boost::format("A file named \"%1%\" already exists. " "Replace it with an Ingen bundle?") - % basename).str(), - "", Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO); - confirm = (ret == Gtk::RESPONSE_YES); - if (confirm) + % basename).str()); + if (confirmed) { ::g_remove(filename.c_str()); + } } - if (confirm) { + if (confirmed) { const Glib::ustring uri = Glib::filename_to_uri(filename); _app->loader()->save_graph(_graph, uri); const_cast(_graph.get())->set_property( diff --git a/src/gui/GraphBox.hpp b/src/gui/GraphBox.hpp index 7ba2fd01..aee4902c 100644 --- a/src/gui/GraphBox.hpp +++ b/src/gui/GraphBox.hpp @@ -97,10 +97,11 @@ private: void property_changed(const Raul::URI& predicate, const Atom& value); void show_status(const Client::ObjectModel* model); - int message_dialog(const Glib::ustring& message, - const Glib::ustring& secondary_text, - Gtk::MessageType type, - Gtk::ButtonsType buttons); + void error(const Glib::ustring& message, + const Glib::ustring& secondary_text=""); + + bool confirm(const Glib::ustring& message, + const Glib::ustring& secondary_text=""); void event_import(); void event_save(); -- cgit v1.2.1