Code

Store last used paths separately for the 'Save as ...' and 'Save a copy ...' dialogs...
authorcilix42 <cilix42@users.sourceforge.net>
Fri, 7 Aug 2009 09:31:39 +0000 (09:31 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Fri, 7 Aug 2009 09:31:39 +0000 (09:31 +0000)
src/file.cpp
src/preferences-skeleton.h
src/ui/dialog/filedialog.cpp
src/ui/dialog/filedialog.h
src/ui/dialog/filedialogimpl-gtkmm.cpp
src/ui/dialog/filedialogimpl-gtkmm.h
src/ui/dialog/filedialogimpl-win32.cpp
src/ui/dialog/filedialogimpl-win32.h

index 049c1acb405313bce8ad55075074075720e742cc..f16d87cbd82313873a2dff960259a326db81d12e 100644 (file)
@@ -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;
     }
index 21bacd5a4d146e95b9d2a3a6be1238bc1ea8cbf2..db21697cac6f0da985b9d0719d11f9967c487466 100644 (file)
@@ -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"
index 172edf8a5c45f65a53aa622caf256f450ad24d98..b1385195f4c3f38e91cc37e280b72624c6a76639 100644 (file)
@@ -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)
index 52dcd1b237fee2acb41f631698e20e2aa4b43474..6eab75a5b41fa027d5d1e091b164f2aafdb769b5 100644 (file)
@@ -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);
 
 
     /**
index 749a67b288fbb31bf31a923675ea83f3348f26dd..53faa075ab9100ae72da6c0ab92c7387e2d7b705 100644 (file)
@@ -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;
         }
index 90dddce59a51a8ba5858d32796a1fb9ffcc5d139..2a37aed2b62e37ae9a36bdb8c7b34053cd3228cb 100644 (file)
@@ -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();
 
@@ -301,6 +302,11 @@ private:
     void change_path(const Glib::ustring& path);
     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
      */
index 0d8f0de5f7c3a1674af6eea74b648ec03b5d829f..c703d3c759ae6dd4b7f465c8ea8eae0651a323e2 100644 (file)
@@ -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)
 {
index bb026169a706fcfabebf11fa071865d0fcbb8c72..f75133fe33f034d37cf18ba93b5346b761fd9aa4 100644 (file)
@@ -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();