diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 8e4d05a1d..a38850658 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -974,10 +974,12 @@ void EditorPanel::saveAsPressed () { saveAsDialog->setInitialFileName (removeExtension (Glib::path_get_basename (openThm->getFileName()))); do { saveAsDialog->run (); - fname = saveAsDialog->getFileName (); - if (fname=="") + if (saveAsDialog->getResponse()==Gtk::RESPONSE_CANCEL) return; + // The SaveAsDialog ensure that a filename has been specified + fname = saveAsDialog->getFileName (); + options.lastSaveAsPath = saveAsDialog->getDirectory (); options.saveAsDialogWidth = saveAsDialog->get_width(); options.saveAsDialogHeight = saveAsDialog->get_height(); diff --git a/rtgui/saveasdlg.cc b/rtgui/saveasdlg.cc index 007bf72e7..e8c3e4c7c 100644 --- a/rtgui/saveasdlg.cc +++ b/rtgui/saveasdlg.cc @@ -19,6 +19,7 @@ #include "saveasdlg.h" #include #include +#include extern Options options; SaveAsDialog::SaveAsDialog (Glib::ustring initialDir) { @@ -118,7 +119,11 @@ bool SaveAsDialog::getToTailOfQueue () { Glib::ustring SaveAsDialog::getFileName () { - return removeExtension(fname) + Glib::ustring(".") + formatOpts->getFormat().format; + // fname is empty if the dialog has been cancelled + if (fname.length()) + return removeExtension(fname) + Glib::ustring(".") + formatOpts->getFormat().format; + else + return ""; } Glib::ustring SaveAsDialog::getDirectory () { @@ -134,12 +139,24 @@ SaveFormat SaveAsDialog::getFormat () { void SaveAsDialog::okPressed () { fname = fchooser->get_filename(); + + // checking if the filename field is empty. The user have to click Cancel if he don't want to specify a filename + // NB: There seem to be a bug in Gtkmm2.22 / FileChooserWidget : if you suppress the filename entry and + // click on a folder in the list, the filename field is empty but get_filename will return the folder's path :/ + if (!fname.length() || safe_file_test (fname, Glib::FILE_TEST_IS_DIR)) { + Glib::ustring msg_ = Glib::ustring("") + M("MAIN_MSG_EMPTYFILENAME") + ""; + Gtk::MessageDialog msgd (*this, msg_, true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); + msgd.run (); + return; + } + response = Gtk::RESPONSE_OK; hide (); } void SaveAsDialog::cancelPressed () { fname = ""; + response = Gtk::RESPONSE_CANCEL; hide (); } diff --git a/rtgui/saveasdlg.h b/rtgui/saveasdlg.h index 1914461c4..d98fae100 100644 --- a/rtgui/saveasdlg.h +++ b/rtgui/saveasdlg.h @@ -37,6 +37,7 @@ class SaveAsDialog : public Gtk::Dialog, public FormatChangeListener { Gtk::RadioButton* immediately; Gtk::RadioButton* putToQueueHead; Gtk::RadioButton* putToQueueTail; + Gtk::ResponseType response; public: SaveAsDialog (Glib::ustring initialDir); @@ -50,6 +51,7 @@ class SaveAsDialog : public Gtk::Dialog, public FormatChangeListener { bool getToTailOfQueue (); void setInitialFileName (Glib::ustring iname); + Gtk::ResponseType getResponse () { return response; }; void okPressed (); void cancelPressed ();