[PATCH] bug in FileSaveDialog
I know inkscape is normally a patch-first-talk-later place, but I haven't done a "serious" commit to SVN in a while, so I thought I'd see what people thought of this patch...
Here is the problem: in Ubuntu Edgy (glib 2.12.3) the filedialog throws an error if you give it a _file_ rather than a _path_ in set_current_folder(). src/file.cpp expected (at one time) to give the dialog a full path, not a directory, but at some point the logic slowly changed. This patch restores the logic of letting the dialog specify a full path name. (And as such, the "drawing.svg", "drawing-1.svg" default names re-appear too.)
Example scenario:
- start without ~/.inkscape dir and without any ~/drawing*.svg files - open inkscape - draw anything - click "save" expected results: put in home directory, with "drawing.svg" already in the filename entry box. - click "OK" - open new inkscape window - draw anything - click "save" expected results: put in home directory, with "drawing-1.svg" - click on "Filesystem" and scroll to "tmp". - click "OK" - switch back to first window - Select "File/Save As..." expected results: put in home directory, with "drawing.svg" already in the filename entry box.
Thoughts?
Index: src/ui/dialog/filedialog.h =================================================================== --- src/ui/dialog/filedialog.h (revision 13104) +++ src/ui/dialog/filedialog.h (working copy) @@ -172,6 +172,10 @@ */ virtual void change_title(const Glib::ustring& title) =0;
+ /** + * Change the default save path location. + */ + virtual void change_path(const Glib::ustring& path) =0;
}; //FileSaveDialog
Index: src/ui/dialog/filedialog.cpp =================================================================== --- src/ui/dialog/filedialog.cpp (revision 13104) +++ src/ui/dialog/filedialog.cpp (working copy) @@ -1138,6 +1138,7 @@ Glib::ustring getFilename();
void change_title(const Glib::ustring& title); + void change_path(const Glib::ustring& dir);
private: @@ -1355,7 +1356,7 @@ // leaving a trailing backslash on the directory name leads to the infamous // double-directory bug on win32 if (len != 0 && udir[len - 1] == '\') udir.erase(len - 1); - set_current_folder(udir.c_str()); + myFilename = udir; }
//###### Add the file types menu @@ -1455,10 +1456,7 @@ bool FileSaveDialogImpl::show() { - Glib::ustring s = Glib::filename_to_utf8 (get_current_folder()); - if (s.length() == 0) - s = getcwd (NULL, 0); - set_current_folder(Glib::filename_from_utf8(s)); //hack to force initial dir listing + change_path(myFilename); set_modal (TRUE); //Window sp_transientize((GtkWidget *)gobj()); //Make transient gint b = run(); //Dialog @@ -1519,6 +1517,24 @@ this->set_title(title); }
+/** + * Change the default save path location. + */ +void +FileSaveDialogImpl::change_path(const Glib::ustring& path) +{ + myFilename = path; + if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) { + //fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str()); + set_current_folder(myFilename); + } else { + //fprintf(stderr,"set_filename(%s)\n",myFilename.c_str()); + set_filename(myFilename); + Glib::ustring basename = Glib::path_get_basename(myFilename); + //fprintf(stderr,"set_current_name(%s)\n",basename.c_str()); + set_current_name(basename); + } +}
Index: src/file.cpp =================================================================== --- src/file.cpp (revision 13104) +++ src/file.cpp (working copy) @@ -589,7 +589,8 @@ save_loc.append(formatBuf); } } else { - save_loc = Glib::path_get_dirname(doc->uri); + save_loc = Glib::build_filename(Glib::path_get_dirname(doc->uri), + Glib::path_get_basename(doc->uri)); }
// convert save_loc from utf-8 to locale @@ -615,6 +616,8 @@ (char const *) _("Select file to save to"), default_extension ); + else + saveDialogInstance->change_path(save_loc); saveDialogInstance->change_title(dialog_title);
bool success = saveDialogInstance->show(); @@ -640,7 +643,7 @@ if (success) prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc));
- save_path = fileName; + save_path = Glib::path_get_dirname(fileName); prefs_set_string_attribute("dialogs.save_as", "path", save_path.c_str());
return success;
participants (1)
-
Kees Cook