Code

separate updating window from updating layers
[inkscape.git] / src / file.cpp
index a9c9184f69f7f165211d4eda9f6c0aa9e7808cc4..568d32572874d523c83b69445f4ed41917d5c7b0 100644 (file)
@@ -8,9 +8,10 @@
  *   Chema Celorio <chema@celorio.com>
  *   bulia byak <buliabyak@users.sf.net>
  *
+ * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
  * Copyright (C) 1999-2005 Authors
- * Copyright (C) 2001-2002 Ximian, Inc.
  * Copyright (C) 2004 David Turner
+ * Copyright (C) 2001-2002 Ximian, Inc.
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -87,7 +88,10 @@ void dump_ustr(Glib::ustring const &ustr);
 SPDesktop*
 sp_file_new(const Glib::ustring &templ)
 {
-    SPDocument *doc = sp_document_new(templ.c_str(), TRUE, true);
+    char *templName = NULL;
+    if (templ.size()>0)
+        templName = (char *)templ.c_str();
+    SPDocument *doc = sp_document_new(templName, TRUE, true);
     g_return_val_if_fail(doc != NULL, NULL);
 
     SPDesktop *dt;
@@ -102,6 +106,7 @@ sp_file_new(const Glib::ustring &templ)
         sp_create_window(dtw, TRUE);
         dt = static_cast<SPDesktop*>(dtw->view);
         sp_namedview_window_from_document(dt);
+        sp_namedview_update_layers_from_document(dt);
     }
     return dt;
 }
@@ -130,7 +135,7 @@ sp_file_new_default()
         sources.pop_front();
     }
 
-    return sp_file_new(NULL);
+    return sp_file_new("");
 }
 
 
@@ -197,9 +202,8 @@ sp_file_open(const Glib::ustring &uri,
         // everyone who cares now has a reference, get rid of ours
         sp_document_unref(doc);
         // resize the window to match the document properties
-        // (this may be redundant for new windows... if so, move to the "virgin"
-        //  section above)
         sp_namedview_window_from_document(desktop);
+        sp_namedview_update_layers_from_document(desktop);
 
         if (add_to_recent) {
             prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc));
@@ -459,7 +463,7 @@ sp_file_vacuum()
     unsigned int diff = vacuum_document (doc);
 
     sp_document_done(doc, SP_VERB_FILE_VACUUM, 
-                     /* TODO: annotate */ "file.cpp:515");
+                     _("Vacuum &lt;defs&gt;"));
 
     SPDesktop *dt = SP_ACTIVE_DESKTOP;
     if (diff > 0) {
@@ -481,10 +485,13 @@ sp_file_vacuum()
 
 /**
  * This 'save' function called by the others below
+ *
+ * \param    official  whether to set :output_module and :modified in the
+ *                     document; is true for normal save, false for temporary saves
  */
 static bool
 file_save(SPDocument *doc, const Glib::ustring &uri,
-          Inkscape::Extension::Extension *key, bool saveas)
+          Inkscape::Extension::Extension *key, bool saveas, bool official)
 {
     if (!doc || uri.size()<1) //Safety check
         return false;
@@ -492,7 +499,7 @@ file_save(SPDocument *doc, const Glib::ustring &uri,
     try {
         Inkscape::Extension::save(key, doc, uri.c_str(),
                  saveas && prefs_get_int_attribute("dialogs.save_as", "append_extension", 1),
-                 saveas, TRUE); // save officially, with inkscape: attributes set
+                 saveas, official); 
     } catch (Inkscape::Extension::Output::no_extension_found &e) {
         gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str());
         gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s).  This may have been caused by an unknown filename extension."), safeUri);
@@ -525,9 +532,11 @@ static Inkscape::UI::Dialog::FileSaveDialog *saveDialogInstance = NULL;
 
 /**
  *  Display a SaveAs dialog.  Save the document if OK pressed.
+ *
+ * \param    ascopy  (optional) wether to set the documents->uri to the new filename or not
  */
 bool
-sp_file_save_dialog(SPDocument *doc)
+sp_file_save_dialog(SPDocument *doc, bool is_copy)
 {
 
     Inkscape::XML::Node *repr = sp_document_repr_root(doc);
@@ -580,7 +589,8 @@ sp_file_save_dialog(SPDocument *doc)
             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
@@ -592,6 +602,12 @@ sp_file_save_dialog(SPDocument *doc)
         save_loc = save_loc_local;
 
     //# Show the SaveAs dialog
+    char const * dialog_title;
+    if (is_copy) {
+        dialog_title = (char const *) _("Select file to save a copy to");
+    } else {
+        dialog_title = (char const *) _("Select file to save to");
+    }
     if (!saveDialogInstance)
         saveDialogInstance =
              Inkscape::UI::Dialog::FileSaveDialog::create(
@@ -600,7 +616,10 @@ sp_file_save_dialog(SPDocument *doc)
                  (char const *) _("Select file to save to"),
                  default_extension
             );
-
+    else
+        saveDialogInstance->change_path(save_loc);
+    saveDialogInstance->change_title(dialog_title);
+    
     bool success = saveDialogInstance->show();
     if (!success)
         return success;
@@ -619,12 +638,12 @@ sp_file_save_dialog(SPDocument *doc)
         else
             g_warning( "Error converting save filename to UTF-8." );
 
-        success = file_save(doc, fileName, selectionType, TRUE);
+        success = file_save(doc, fileName, selectionType, TRUE, !is_copy);
 
         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;
@@ -647,14 +666,14 @@ sp_file_save_document(SPDocument *doc)
 
     gchar const *fn = repr->attribute("sodipodi:modified");
     if (fn != NULL) {
-        if (doc->uri == NULL
-            || repr->attribute("inkscape:output_extension") == NULL)
+        if ( doc->uri == NULL
+            || repr->attribute("inkscape:output_extension") == NULL )
         {
-            return sp_file_save_dialog(doc);
+            return sp_file_save_dialog(doc, FALSE);
         } else {
             fn = g_strdup(doc->uri);
             gchar const *ext = repr->attribute("inkscape:output_extension");
-            success = file_save(doc, fn, Inkscape::Extension::db.get(ext), FALSE);
+            success = file_save(doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE);
             g_free((void *) fn);
         }
     } else {
@@ -688,11 +707,23 @@ sp_file_save_as(gpointer object, gpointer data)
     if (!SP_ACTIVE_DOCUMENT)
         return false;
     sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
-    return sp_file_save_dialog(SP_ACTIVE_DOCUMENT);
+    return sp_file_save_dialog(SP_ACTIVE_DOCUMENT, FALSE);
 }
 
 
 
+/**
+ *  Save a copy of a document, always displaying a sort of SaveAs dialog.
+ */
+bool
+sp_file_save_a_copy(gpointer object, gpointer data)
+{
+    if (!SP_ACTIVE_DOCUMENT)
+        return false;
+    sp_namedview_document_from_window(SP_ACTIVE_DESKTOP);
+    return sp_file_save_dialog(SP_ACTIVE_DOCUMENT, TRUE);
+}
+
 
 /*######################
 ## I M P O R T
@@ -818,7 +849,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri,
 
         sp_document_unref(doc);
         sp_document_done(in_doc, SP_VERB_FILE_IMPORT,
-                         /* TODO: annotate */ "file.cpp:900");
+                         _("Import"));
 
     } else {
         gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), uri.c_str());
@@ -988,7 +1019,7 @@ sp_file_export_dialog(void *widget)
         else
             g_warning( "Error converting save filename to UTF-8." );
 
-        success = file_save(doc, fileName, selectionType, TRUE);
+        success = file_save(doc, fileName, selectionType, TRUE, FALSE);
 
         if (success)
             prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc));