summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2009-08-07 09:31:39 +0000
committercilix42 <cilix42@users.sourceforge.net>2009-08-07 09:31:39 +0000
commitc5b0b577134ed7c2df538ed019a6c07cb75bf38e (patch)
treef3dc9f3582bc21808ab86d1e8c59d45492df6c41
parentFix buglet: In the Save dialog the file extension should be automatically upd... (diff)
downloadinkscape-c5b0b577134ed7c2df538ed019a6c07cb75bf38e.tar.gz
inkscape-c5b0b577134ed7c2df538ed019a6c07cb75bf38e.zip
Store last used paths separately for the 'Save as ...' and 'Save a copy ...' dialogs and remember the last used file types in each case (closes LP #184655 and perhaps others; LP #386292 was fixed by the previous commit).
(bzr r8432)
-rw-r--r--src/file.cpp65
-rw-r--r--src/preferences-skeleton.h3
-rw-r--r--src/ui/dialog/filedialog.cpp13
-rw-r--r--src/ui/dialog/filedialog.h3
-rw-r--r--src/ui/dialog/filedialogimpl-gtkmm.cpp30
-rw-r--r--src/ui/dialog/filedialogimpl-gtkmm.h16
-rw-r--r--src/ui/dialog/filedialogimpl-win32.cpp5
-rw-r--r--src/ui/dialog/filedialogimpl-win32.h7
8 files changed, 93 insertions, 49 deletions
diff --git a/src/file.cpp b/src/file.cpp
index 049c1acb4..f16d87cbd 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -711,9 +711,9 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
//# Get the default extension name
Glib::ustring default_extension;
- char *attr = (char *)repr->attribute("inkscape:output_extension");
+ char *attr = (char *)repr->attribute(is_copy ? "inkscape:output_extension_copy" : "inkscape:output_extension");
if (!attr) {
- Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
+ Glib::ustring attr2 = prefs->getString(is_copy ? "/dialogs/save_copy/default" : "/dialogs/save_as/default");
if(!attr2.empty()) default_extension = attr2;
} else {
default_extension = attr;
@@ -723,18 +723,24 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
Glib::ustring save_path;
Glib::ustring save_loc;
- if (doc->uri == NULL) {
- char formatBuf[256];
- int i = 1;
-
- Glib::ustring filename_extension = ".svg";
+ if (!default_extension.empty()) {
extension = dynamic_cast<Inkscape::Extension::Output *>
(Inkscape::Extension::db.get(default_extension.c_str()));
+ } else {
+ g_warning ("No default extension!!!! What to do?\n");
+ }
+
+ if (doc->uri && !is_copy) {
+ // Saving as a regular file: recover the filename from the existing doc->uri
+ save_loc = Glib::build_filename(Glib::path_get_dirname(doc->uri),
+ Glib::path_get_basename(doc->uri));
+ } else {
+ Glib::ustring filename_extension = ".svg";
//g_warning("%s: extension ptr: 0x%x", __FUNCTION__, (unsigned int)extension);
if (extension)
filename_extension = extension->get_extension();
- Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
+ Glib::ustring attr3 = prefs->getString(is_copy ? "/dialogs/save_copy/path" : "/dialogs/save_as/path");
if (!attr3.empty())
save_path = attr3;
@@ -747,18 +753,30 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
save_loc = save_path;
save_loc.append(G_DIR_SEPARATOR_S);
- snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
- save_loc.append(formatBuf);
- while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
- save_loc = save_path;
- save_loc.append(G_DIR_SEPARATOR_S);
- snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
+ char formatBuf[256];
+ int i = 1;
+ if (!doc->uri) {
+ // We are saving for the first time; create a unique default filename
+ snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
save_loc.append(formatBuf);
+
+ while (Inkscape::IO::file_test(save_loc.c_str(), G_FILE_TEST_EXISTS)) {
+ save_loc = save_path;
+ save_loc.append(G_DIR_SEPARATOR_S);
+ snprintf(formatBuf, 255, _("drawing-%d%s"), i++, filename_extension.c_str());
+ save_loc.append(formatBuf);
+ }
+ } else {
+ if (is_copy) {
+ // Use the document uri's base name as the filename but
+ // store in the directory last used for "Save a copy ..."
+ snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->uri).c_str());
+ save_loc.append(formatBuf);
+ } else {
+ g_assert_not_reached();
+ }
}
- } else {
- 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
@@ -784,7 +802,8 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
Inkscape::UI::Dialog::SVG_TYPES,
dialog_title,
default_extension,
- doc_title ? doc_title : ""
+ doc_title ? doc_title : "",
+ is_copy
);
saveDialog->setSelectionType(extension);
@@ -823,7 +842,7 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy)
save_path = Glib::path_get_dirname(fileName);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setString("/dialogs/save_as/path", save_path);
+ prefs->setString(is_copy ? "/dialogs/save_copy/path" : "/dialogs/save_as/path", save_path);
return success;
}
@@ -1144,9 +1163,9 @@ sp_file_export_dialog(void *widget)
//# Get the default extension name
Glib::ustring default_extension;
- char *attr = (char *)repr->attribute("inkscape:output_extension");
+ char *attr = (char *)repr->attribute("inkscape:output_extension_export");
if (!attr) {
- Glib::ustring attr2 = prefs->getString("/dialogs/save_as/default");
+ Glib::ustring attr2 = prefs->getString("/dialogs/save_export/default");
if(!attr2.empty()) default_extension = attr2;
} else {
default_extension = attr;
@@ -1164,7 +1183,7 @@ sp_file_export_dialog(void *widget)
if (extension)
filename_extension = extension->get_extension();
- Glib::ustring attr3 = prefs->getString("/dialogs/save_as/path");
+ Glib::ustring attr3 = prefs->getString("/dialogs/save_export/path");
if (!attr3.empty())
export_path = attr3;
@@ -1232,7 +1251,7 @@ sp_file_export_dialog(void *widget)
}
export_path = fileName;
- prefs->setString("/dialogs/save_as/path", export_path);
+ prefs->setString("/dialogs/save_export/path", export_path);
return success;
}
diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h
index 21bacd5a4..db21697ca 100644
--- a/src/preferences-skeleton.h
+++ b/src/preferences-skeleton.h
@@ -179,11 +179,12 @@ static char const preferences_skeleton[] =
" <group id=\"preferences\" state=\"1\"/>\n"
" <group id=\"gradienteditor\"/>\n"
" <group id=\"object\"/>\n"
-" <group id=\"export\">\n"
+" <group id=\"export\" default=\"\" append_extension=\"1\" path=\"\">\n"
" <group id=\"exportarea\"/>\n"
" <group id=\"defaultxdpi\"/>\n"
" </group>\n"
" <group id=\"save_as\" default=\"\" append_extension=\"1\" enable_preview=\"1\" path=\"\"/>\n"
+" <group id=\"save_copy\" default=\"\" append_extension=\"1\" enable_preview=\"1\" path=\"\"/>\n"
" <group id=\"open\" enable_preview=\"1\" path=\"\"/>\n"
" <group id=\"import\" enable_preview=\"1\" path=\"\"/>\n"
" <group id=\"debug\" redirect=\"0\"/>\n"
diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp
index 172edf8a5..b1385195f 100644
--- a/src/ui/dialog/filedialog.cpp
+++ b/src/ui/dialog/filedialog.cpp
@@ -105,16 +105,17 @@ Glib::ustring FileOpenDialog::getFilename()
* Public factory method. Used in file.cpp
*/
FileSaveDialog *FileSaveDialog::create(Gtk::Window& parentWindow,
- const Glib::ustring &path,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const char *title,
const Glib::ustring &default_key,
- const gchar *docTitle)
+ const gchar *docTitle,
+ const bool save_copy)
{
#ifdef WIN32
- FileSaveDialog *dialog = new FileSaveDialogImplWin32(parentWindow, path, fileTypes, title, default_key, docTitle);
+ FileSaveDialog *dialog = new FileSaveDialogImplWin32(parentWindow, path, fileTypes, title, default_key, docTitle, save_copy);
#else
- FileSaveDialog *dialog = new FileSaveDialogImplGtk(parentWindow, path, fileTypes, title, default_key, docTitle);
+ FileSaveDialog *dialog = new FileSaveDialogImplGtk(parentWindow, path, fileTypes, title, default_key, docTitle, save_copy);
#endif
return dialog;
}
@@ -168,8 +169,8 @@ void FileSaveDialog::appendExtension(Glib::ustring& path, Inkscape::Extension::O
/**
* Public factory method. Used in file.cpp
*/
- FileExportDialog *FileExportDialog::create(Gtk::Window& parentWindow,
- const Glib::ustring &path,
+FileExportDialog *FileExportDialog::create(Gtk::Window& parentWindow,
+ const Glib::ustring &path,
FileDialogType fileTypes,
const char *title,
const Glib::ustring &default_key)
diff --git a/src/ui/dialog/filedialog.h b/src/ui/dialog/filedialog.h
index 52dcd1b23..6eab75a5b 100644
--- a/src/ui/dialog/filedialog.h
+++ b/src/ui/dialog/filedialog.h
@@ -163,7 +163,8 @@ public:
FileDialogType fileTypes,
const char *title,
const Glib::ustring &default_key,
- const gchar *docTitle);
+ const gchar *docTitle,
+ const bool save_copy);
/**
diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp
index 749a67b28..53faa075a 100644
--- a/src/ui/dialog/filedialogimpl-gtkmm.cpp
+++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp
@@ -883,8 +883,10 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow,
FileDialogType fileTypes,
const Glib::ustring &title,
const Glib::ustring &/*default_key*/,
- const gchar* docTitle) :
- FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/save_as")
+ const gchar* docTitle,
+ const bool save_copy) :
+ FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, save_copy ? "/dialogs/save_copy" : "/dialogs/save_as"),
+ is_copy(save_copy)
{
FileSaveDialog::myDocTitle = docTitle;
@@ -922,7 +924,11 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk( Gtk::Window &parentWindow,
//###### Do we want the .xxx extension automatically added?
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
- fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_as/append_extension", true));
+ if (save_copy) {
+ fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_copy/append_extension", true));
+ } else {
+ fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_as/append_extension", true));
+ }
createFileTypeMenu();
fileTypeComboBox.set_size_request(200,40);
@@ -1109,10 +1115,18 @@ FileSaveDialogImplGtk::show()
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// Store changes of the "Append filename automatically" checkbox back to preferences.
- prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active());
+ if (is_copy) {
+ prefs->setBool("/dialogs/save_copy/append_extension", fileTypeCheckbox.get_active());
+ } else {
+ prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active());
+ }
// Store the last used save-as filetype to preferences.
- prefs->setString("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
+ if (is_copy) {
+ prefs->setString("/dialogs/save_copy/default", ( extension != NULL ? extension->get_id() : "" ));
+ } else {
+ prefs->setString("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
+ }
cleanup( true );
@@ -1356,7 +1370,7 @@ FileExportDialogImpl::FileExportDialogImpl( Gtk::Window& parentWindow,
destDPISpinner("DPI", _("Resolution (dots per inch)"))
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- append_extension = prefs->getBool("/dialogs/save_as/append_extension", true);
+ append_extension = prefs->getBool("/dialogs/save_export/append_extension", true);
/* One file at a time */
set_select_multiple(false);
@@ -1566,8 +1580,8 @@ FileExportDialogImpl::show()
append_extension = checkbox.get_active();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setBool("/dialogs/save_as/append_extension", append_extension);
- prefs->setBool("/dialogs/save_as/default", ( extension != NULL ? extension->get_id() : "" ));
+ prefs->setBool("/dialogs/save_export/append_extension", append_extension);
+ prefs->setBool("/dialogs/save_export/default", ( extension != NULL ? extension->get_id() : "" ));
*/
return TRUE;
}
diff --git a/src/ui/dialog/filedialogimpl-gtkmm.h b/src/ui/dialog/filedialogimpl-gtkmm.h
index 90dddce59..2a37aed2b 100644
--- a/src/ui/dialog/filedialogimpl-gtkmm.h
+++ b/src/ui/dialog/filedialogimpl-gtkmm.h
@@ -281,11 +281,12 @@ class FileSaveDialogImplGtk : public FileSaveDialog, public FileDialogBaseGtk
public:
FileSaveDialogImplGtk(Gtk::Window &parentWindow,
- const Glib::ustring &dir,
- FileDialogType fileTypes,
- const Glib::ustring &title,
- const Glib::ustring &default_key,
- const gchar* docTitle);
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const Glib::ustring &title,
+ const Glib::ustring &default_key,
+ const gchar* docTitle,
+ const bool save_copy);
virtual ~FileSaveDialogImplGtk();
@@ -302,6 +303,11 @@ private:
void updateNameAndExtension();
/**
+ * Whether the dialog was invoked by "Save as ..." or "Save a copy ..."
+ */
+ bool is_copy;
+
+ /**
* Fix to allow the user to type the file name
*/
Gtk::Entry *fileNameEntry;
diff --git a/src/ui/dialog/filedialogimpl-win32.cpp b/src/ui/dialog/filedialogimpl-win32.cpp
index 0d8f0de5f..c703d3c75 100644
--- a/src/ui/dialog/filedialogimpl-win32.cpp
+++ b/src/ui/dialog/filedialogimpl-win32.cpp
@@ -1497,8 +1497,9 @@ FileSaveDialogImplWin32::FileSaveDialogImplWin32(Gtk::Window &parent,
FileDialogType fileTypes,
const char *title,
const Glib::ustring &/*default_key*/,
- const char *docTitle) :
- FileDialogBaseWin32(parent, dir, title, fileTypes, "dialogs.save_as"),
+ const char *docTitle,
+ const bool save_copy) :
+ FileDialogBaseWin32(parent, dir, title, fileTypes, save_copy ? "dialogs.save_copy" : "dialogs.save_as"),
_title_label(NULL),
_title_edit(NULL)
{
diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h
index bb026169a..f75133fe3 100644
--- a/src/ui/dialog/filedialogimpl-win32.h
+++ b/src/ui/dialog/filedialogimpl-win32.h
@@ -120,9 +120,10 @@ public:
/// @param title The title caption for the dialog in UTF-8
/// @param type The dialog type
FileOpenDialogImplWin32(Gtk::Window &parent,
- const Glib::ustring &dir,
- FileDialogType fileTypes,
- const char *title);
+ const Glib::ustring &dir,
+ FileDialogType fileTypes,
+ const char *title,
+ const bool save_copy);
/// Destructor
virtual ~FileOpenDialogImplWin32();