The "SaveAs" feature was saving the image even if the filename field was leaved empty, because it was automatically adding the format suffix.

The SaveAsDialog is now most secured too: no empty filename field is allowed when pressing OK.
This commit is contained in:
Hombre
2011-08-09 23:24:14 +02:00
parent aac3be6386
commit 613f8308a3
3 changed files with 24 additions and 3 deletions

View File

@@ -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();

View File

@@ -19,6 +19,7 @@
#include "saveasdlg.h"
#include <multilangmgr.h>
#include <guiutils.h>
#include <safegtk.h>
extern Options options;
SaveAsDialog::SaveAsDialog (Glib::ustring initialDir) {
@@ -118,7 +119,11 @@ bool SaveAsDialog::getToTailOfQueue () {
Glib::ustring SaveAsDialog::getFileName () {
// 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("<b>") + M("MAIN_MSG_EMPTYFILENAME") + "</b>";
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 ();
}

View File

@@ -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 ();