From 305941d63be322f6f571a29b5845485fe6de4219 Mon Sep 17 00:00:00 2001 From: kidproto Date: Tue, 22 Aug 2006 08:01:11 +0000 Subject: [PATCH] Committed a great patch which adds a Save A Copy menu function. This is the first gloss of this patch...I will add more stuff to it shortly... --- AUTHORS | 1 + src/extension/output.cpp | 4 ++-- src/extension/system.cpp | 7 ++++++- src/file.cpp | 39 ++++++++++++++++++++++++++++----------- src/file.h | 9 ++++++++- src/menus-skeleton.h | 1 + src/verbs.cpp | 5 +++++ src/verbs.h | 1 + 8 files changed, 52 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index 90c96ac0f..d65e9dd2a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -83,3 +83,4 @@ Daniel Yacob David Yip Masatake Yamato Jos Hirth +Alan Horkan diff --git a/src/extension/output.cpp b/src/extension/output.cpp index eb3f85ed8..b0f254a9c 100644 --- a/src/extension/output.cpp +++ b/src/extension/output.cpp @@ -221,7 +221,7 @@ Output::save (SPDocument * doc, const gchar * uri) gboolean saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive (doc, FALSE); - repr->setAttribute("inkscape:output_extension", NULL); + //repr->setAttribute("inkscape:output_extension", NULL); repr->setAttribute("inkscape:dataloss", NULL); if (repr->attribute("sodipodi:modified") != NULL) modified = true; @@ -239,7 +239,7 @@ Output::save (SPDocument * doc, const gchar * uri) saved = sp_document_get_undo_sensitive(doc); sp_document_set_undo_sensitive (doc, FALSE); - repr->setAttribute("inkscape:output_extension", get_id()); + //repr->setAttribute("inkscape:output_extension", get_id()); if (dataloss) { repr->setAttribute("inkscape:dataloss", "true"); } diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 81bf3075e..3a8a54214 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -244,10 +244,15 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, throw Output::no_overwrite(); } + // if 'official' save the filename and extension for future saves. if (official) { + // save the filename for next use sp_document_set_uri(doc, fileName); + // also save the extension for next use + Inkscape::XML::Node *repr = sp_document_repr_root(doc); + repr->setAttribute("inkscape:output_extension", omod->get_id()); } - + omod->save(doc, fileName); g_free(fileName); diff --git a/src/file.cpp b/src/file.cpp index 6154fb97d..b350ce97b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -484,10 +484,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; @@ -495,7 +498,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); @@ -528,9 +531,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 bAsCopy) { Inkscape::XML::Node *repr = sp_document_repr_root(doc); @@ -600,7 +605,7 @@ sp_file_save_dialog(SPDocument *doc) Inkscape::UI::Dialog::FileSaveDialog::create( save_loc, Inkscape::UI::Dialog::SVG_TYPES, - (char const *) _("Select file to save to"), + bAsCopy ? (char const *) _("Select file to save copy to") : (char const *) _("Select file to save to"), default_extension ); @@ -622,7 +627,7 @@ 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, !bAsCopy); if (success) prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc)); @@ -650,14 +655,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 { @@ -691,11 +696,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 @@ -991,7 +1008,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)); diff --git a/src/file.h b/src/file.h index f86dc5a21..4e128f161 100644 --- a/src/file.h +++ b/src/file.h @@ -89,6 +89,13 @@ bool sp_file_save (gpointer object, gpointer data); */ bool sp_file_save_as (gpointer object, gpointer data); +/** + * Saves a copy of the given document. Displays a file select dialog + * to choose a name for the copy. + */ +bool sp_file_save_a_copy (gpointer object, gpointer data); + + /** * Saves the given document. Displays a file select dialog * if needed. @@ -96,7 +103,7 @@ bool sp_file_save_as (gpointer object, gpointer data); bool sp_file_save_document (SPDocument *document); /* Do the saveas dialog with a document as the parameter */ -bool sp_file_save_dialog (SPDocument *doc); +bool sp_file_save_dialog (SPDocument *doc, bool bAsCopy = FALSE); /*###################### diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index f25ca742c..7d97967d6 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -25,6 +25,7 @@ static char const menus_skeleton[] = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" diff --git a/src/verbs.cpp b/src/verbs.cpp index 409a332b9..d30cba2b9 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -798,6 +798,9 @@ FileVerb::perform(SPAction *action, void *data, void *pdata) case SP_VERB_FILE_SAVE_AS: sp_file_save_as(NULL, NULL); break; + case SP_VERB_FILE_SAVE_A_COPY: + sp_file_save_a_copy(NULL, NULL); + break; case SP_VERB_FILE_PRINT: sp_file_print(); break; @@ -1943,6 +1946,8 @@ Verb *Verb::_base_verbs[] = { GTK_STOCK_SAVE ), new FileVerb(SP_VERB_FILE_SAVE_AS, "FileSaveAs", N_("Save _As..."), N_("Save document under a new name"), GTK_STOCK_SAVE_AS ), + new FileVerb(SP_VERB_FILE_SAVE_A_COPY, "FileSaveACopy", N_("Save a Cop_y..."), + N_("Save a copy of the document under a new name"), NULL ), new FileVerb(SP_VERB_FILE_PRINT, "FilePrint", N_("_Print..."), N_("Print document"), GTK_STOCK_PRINT ), // TRANSLATORS: "Vacuum Defs" means "Clean up defs" (so as to remove unused definitions) diff --git a/src/verbs.h b/src/verbs.h index fa232280b..dacb3ec51 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -31,6 +31,7 @@ enum { SP_VERB_FILE_REVERT, /**< Revert this file to its original state. */ SP_VERB_FILE_SAVE, /**< Save the current file with its saved filename */ SP_VERB_FILE_SAVE_AS, /**< Save the current file with a new filename */ + SP_VERB_FILE_SAVE_A_COPY, /**< Save a copy of the current file */ SP_VERB_FILE_PRINT, SP_VERB_FILE_VACUUM, SP_VERB_FILE_PRINT_DIRECT, -- 2.30.2