From 8b04d0db6c55e36935690d37defb6f9b68945796 Mon Sep 17 00:00:00 2001 From: johnce Date: Wed, 5 Aug 2009 05:40:36 +0000 Subject: SPDocument->Document (bzr r8404) --- src/file.cpp | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 159 insertions(+), 18 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 049c1acb4..afca379ca 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1,3 +1,4 @@ + /** @file * @brief File/Print operations */ @@ -65,6 +66,14 @@ #include "uri.h" #include "xml/rebase-hrefs.h" +#include "streams-handles.h" +#include "streams-webdav.h" +#include "streams-ftp.h" +#include "streams-http.h" + +//#include "buffersystem.h" +#include + #ifdef WITH_GNOME_VFS # include #endif @@ -119,7 +128,7 @@ sp_file_new(const Glib::ustring &templ) char *templName = NULL; if (templ.size()>0) templName = (char *)templ.c_str(); - SPDocument *doc = sp_document_new(templName, TRUE, true); + Document *doc = sp_document_new(templName, TRUE, true); g_return_val_if_fail(doc != NULL, NULL); SPDesktop *dt; @@ -201,7 +210,7 @@ sp_file_open(const Glib::ustring &uri, if (desktop) desktop->setWaitingCursor(); - SPDocument *doc = NULL; + Document *doc = NULL; try { doc = Inkscape::Extension::open(key, uri.c_str()); } catch (Inkscape::Extension::Input::no_extension_found &e) { @@ -214,7 +223,7 @@ sp_file_open(const Glib::ustring &uri, desktop->clearWaitingCursor(); if (doc) { - SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL; + Document *existing = desktop ? sp_desktop_document(desktop) : NULL; if (existing && existing->virgin && replace_empty) { // If the current desktop is empty, open the document there @@ -254,6 +263,137 @@ sp_file_open(const Glib::ustring &uri, } } + + + +//NOTE1 +bool +sp_file_open_uri(const Inkscape::URI &uri, + Inkscape::Extension::Extension *key, + bool add_to_recent, bool replace_empty) +{ + Document *doc = NULL; + try { + doc = Inkscape::Extension::open(key, uri.toNativeFilename()); + } catch (Inkscape::Extension::Input::no_extension_found &e) { + doc = NULL; + } catch (Inkscape::Extension::Input::open_failed &e) { + doc = NULL; + } + + //FIXME1 KLUDGE switch + + //WebDAV + /* + if (std::strstr(uri.toString(), "http") != NULL) + { + if (strcmp(uri.toString(), "/http") >= 5//FIXME3 skip begining '/' + || + strcmp(uri.toString(), "http") >= 4 + ) + { + + std::cout<<"+++ 'http' uri.toString->"< FTP , HTTP etc."<= 4//FIXME3 skip begining '/' + || + strcmp(uri.toString(), "ftp") >= 3 + ) + { + std::cout<<"+++ 'ftp' uri.toString->"<> buf; + std::cout<<"buf->"<= 5//FIXME3 skip begining '/' + || + strcmp(uri.toString(), "http") >= 4 + ) + { + std::cout<<"+++ 'http' uri.toString->"<> buf; + std::cout<<"buf->"<virgin && replace_empty) { + // If the current desktop is empty, open the document there + sp_document_ensure_up_to_date (doc); + desktop->change_document(doc); + sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc)); + } else { + if (!Inkscape::NSApplication::Application::getNewGui()) { + // create a whole new desktop and window + SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); + sp_create_window(dtw, TRUE); + desktop = static_cast(dtw->view); + } else { + desktop = Inkscape::NSApplication::Editor::createDesktop (doc); + } + } + + doc->virgin = FALSE; + // everyone who cares now has a reference, get rid of ours + sp_document_unref(doc); + // resize the window to match the document properties + sp_namedview_window_from_document(desktop); + sp_namedview_update_layers_from_document(desktop); + + if (add_to_recent) { +//--tullarisc prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc)); + } + + return TRUE; + } else { + //FIXME 1 + //gchar *safeUri = Inkscape::IO::sanitizeString(uri.toNativeFilename()); + //gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), safeUri); + //sp_ui_error_dialog(text); + //g_free(text); + //g_free(safeUri); + return FALSE; + } +} + + /** * Handle prompting user for "do you want to revert"? Revert on "OK" */ @@ -263,7 +403,7 @@ sp_file_revert_dialog() SPDesktop *desktop = SP_ACTIVE_DESKTOP; g_assert(desktop != NULL); - SPDocument *doc = sp_desktop_document(desktop); + Document *doc = sp_desktop_document(desktop); g_assert(doc != NULL); Inkscape::XML::Node *repr = sp_document_repr_root(doc); @@ -397,6 +537,7 @@ void dump_ustr(Glib::ustring const &ustr) /** * Display an file Open selector. Open a document if OK is pressed. * Can select single or multiple files for opening. + * NOTE1 */ void sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/) @@ -521,7 +662,7 @@ sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d open_path.append(G_DIR_SEPARATOR_S); prefs->setString("/dialogs/open/path", open_path); - sp_file_open(fileName, selection); + sp_file_open_uri(Inkscape::URI(fileName.c_str()), selection); } return; @@ -540,7 +681,7 @@ sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d void sp_file_vacuum() { - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; unsigned int diff = vacuum_document (doc); @@ -572,7 +713,7 @@ sp_file_vacuum() * document; is true for normal save, false for temporary saves */ static bool -file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, +file_save(Gtk::Window &parentWindow, Document *doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key, bool saveas, bool official) { if (!doc || uri.size()<1) //Safety check @@ -614,7 +755,7 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp. */ bool -file_save_remote(SPDocument */*doc*/, +file_save_remote(Document */*doc*/, #ifdef WITH_GNOME_VFS const Glib::ustring &uri, #else @@ -702,7 +843,7 @@ file_save_remote(SPDocument */*doc*/, * \param ascopy (optional) wether to set the documents->uri to the new filename or not */ bool -sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) +sp_file_save_dialog(Gtk::Window &parentWindow, Document *doc, bool is_copy) { Inkscape::XML::Node *repr = sp_document_repr_root(doc); @@ -837,7 +978,7 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) * Save a document, displaying a SaveAs dialog if necessary. */ bool -sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) +sp_file_save_document(Gtk::Window &parentWindow, Document *doc) { bool success = true; @@ -913,13 +1054,13 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d * Import a resource. Called by sp_file_import() */ void -file_import(SPDocument *in_doc, const Glib::ustring &uri, +file_import(Document *in_doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; //DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key ); - SPDocument *doc; + Document *doc; try { doc = Inkscape::Extension::open(key, uri.c_str()); } catch (Inkscape::Extension::Input::no_extension_found &e) { @@ -1050,7 +1191,7 @@ sp_file_import(Gtk::Window &parentWindow) { static Glib::ustring import_path; - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; if (!doc) return; @@ -1133,7 +1274,7 @@ bool sp_file_export_dialog(void *widget) { //# temp hack for 'doc' until we can switch to this dialog - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; Glib::ustring export_path; Glib::ustring export_loc; @@ -1269,7 +1410,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) if (!SP_ACTIVE_DOCUMENT) return false; - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; Glib::ustring export_path; Glib::ustring export_loc; @@ -1427,7 +1568,7 @@ sp_file_import_from_ocal(Gtk::Window &parentWindow) { static Glib::ustring import_path; - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; if (!doc) return; @@ -1485,7 +1626,7 @@ sp_file_import_from_ocal(Gtk::Window &parentWindow) void sp_file_print(Gtk::Window& parentWindow) { - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; if (doc) sp_print_document(parentWindow, doc); } @@ -1498,7 +1639,7 @@ void sp_file_print_preview(gpointer /*object*/, gpointer /*data*/) { - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; if (doc) sp_print_preview_document(doc); -- cgit v1.2.3 From a68dd35a31e54a4340d54a491a8f1b45d73352f4 Mon Sep 17 00:00:00 2001 From: johnce Date: Wed, 5 Aug 2009 17:25:25 +0000 Subject: SPDocument->Document (bzr r8416) --- src/file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index afca379ca..22425547e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1070,7 +1070,7 @@ file_import(Document *in_doc, const Glib::ustring &uri, } if (doc != NULL) { - Inkscape::XML::rebase_hrefs(doc, in_doc->base, true); + Inkscape::XML::rebase_hrefs((Inkscape::XML::Document *)doc, in_doc->base, true); Inkscape::XML::Document *xml_in_doc = sp_document_repr_doc(in_doc); prevent_id_clashes(doc, in_doc); -- cgit v1.2.3 From 51c2905fd3e99955db2d823b79abb763d8097028 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Thu, 6 Aug 2009 14:17:17 +0000 Subject: Revert recent refactoring changes by johnce because they break the build, which cannot be fixed easily. (bzr r8422) --- src/file.cpp | 179 +++++++---------------------------------------------------- 1 file changed, 19 insertions(+), 160 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 22425547e..049c1acb4 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1,4 +1,3 @@ - /** @file * @brief File/Print operations */ @@ -66,14 +65,6 @@ #include "uri.h" #include "xml/rebase-hrefs.h" -#include "streams-handles.h" -#include "streams-webdav.h" -#include "streams-ftp.h" -#include "streams-http.h" - -//#include "buffersystem.h" -#include - #ifdef WITH_GNOME_VFS # include #endif @@ -128,7 +119,7 @@ sp_file_new(const Glib::ustring &templ) char *templName = NULL; if (templ.size()>0) templName = (char *)templ.c_str(); - Document *doc = sp_document_new(templName, TRUE, true); + SPDocument *doc = sp_document_new(templName, TRUE, true); g_return_val_if_fail(doc != NULL, NULL); SPDesktop *dt; @@ -210,7 +201,7 @@ sp_file_open(const Glib::ustring &uri, if (desktop) desktop->setWaitingCursor(); - Document *doc = NULL; + SPDocument *doc = NULL; try { doc = Inkscape::Extension::open(key, uri.c_str()); } catch (Inkscape::Extension::Input::no_extension_found &e) { @@ -223,7 +214,7 @@ sp_file_open(const Glib::ustring &uri, desktop->clearWaitingCursor(); if (doc) { - Document *existing = desktop ? sp_desktop_document(desktop) : NULL; + SPDocument *existing = desktop ? sp_desktop_document(desktop) : NULL; if (existing && existing->virgin && replace_empty) { // If the current desktop is empty, open the document there @@ -263,137 +254,6 @@ sp_file_open(const Glib::ustring &uri, } } - - - -//NOTE1 -bool -sp_file_open_uri(const Inkscape::URI &uri, - Inkscape::Extension::Extension *key, - bool add_to_recent, bool replace_empty) -{ - Document *doc = NULL; - try { - doc = Inkscape::Extension::open(key, uri.toNativeFilename()); - } catch (Inkscape::Extension::Input::no_extension_found &e) { - doc = NULL; - } catch (Inkscape::Extension::Input::open_failed &e) { - doc = NULL; - } - - //FIXME1 KLUDGE switch - - //WebDAV - /* - if (std::strstr(uri.toString(), "http") != NULL) - { - if (strcmp(uri.toString(), "/http") >= 5//FIXME3 skip begining '/' - || - strcmp(uri.toString(), "http") >= 4 - ) - { - - std::cout<<"+++ 'http' uri.toString->"< FTP , HTTP etc."<= 4//FIXME3 skip begining '/' - || - strcmp(uri.toString(), "ftp") >= 3 - ) - { - std::cout<<"+++ 'ftp' uri.toString->"<> buf; - std::cout<<"buf->"<= 5//FIXME3 skip begining '/' - || - strcmp(uri.toString(), "http") >= 4 - ) - { - std::cout<<"+++ 'http' uri.toString->"<> buf; - std::cout<<"buf->"<virgin && replace_empty) { - // If the current desktop is empty, open the document there - sp_document_ensure_up_to_date (doc); - desktop->change_document(doc); - sp_document_resized_signal_emit (doc, sp_document_width(doc), sp_document_height(doc)); - } else { - if (!Inkscape::NSApplication::Application::getNewGui()) { - // create a whole new desktop and window - SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); - sp_create_window(dtw, TRUE); - desktop = static_cast(dtw->view); - } else { - desktop = Inkscape::NSApplication::Editor::createDesktop (doc); - } - } - - doc->virgin = FALSE; - // everyone who cares now has a reference, get rid of ours - sp_document_unref(doc); - // resize the window to match the document properties - sp_namedview_window_from_document(desktop); - sp_namedview_update_layers_from_document(desktop); - - if (add_to_recent) { -//--tullarisc prefs_set_recent_file(SP_DOCUMENT_URI(doc), SP_DOCUMENT_NAME(doc)); - } - - return TRUE; - } else { - //FIXME 1 - //gchar *safeUri = Inkscape::IO::sanitizeString(uri.toNativeFilename()); - //gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), safeUri); - //sp_ui_error_dialog(text); - //g_free(text); - //g_free(safeUri); - return FALSE; - } -} - - /** * Handle prompting user for "do you want to revert"? Revert on "OK" */ @@ -403,7 +263,7 @@ sp_file_revert_dialog() SPDesktop *desktop = SP_ACTIVE_DESKTOP; g_assert(desktop != NULL); - Document *doc = sp_desktop_document(desktop); + SPDocument *doc = sp_desktop_document(desktop); g_assert(doc != NULL); Inkscape::XML::Node *repr = sp_document_repr_root(doc); @@ -537,7 +397,6 @@ void dump_ustr(Glib::ustring const &ustr) /** * Display an file Open selector. Open a document if OK is pressed. * Can select single or multiple files for opening. - * NOTE1 */ void sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data*/) @@ -662,7 +521,7 @@ sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d open_path.append(G_DIR_SEPARATOR_S); prefs->setString("/dialogs/open/path", open_path); - sp_file_open_uri(Inkscape::URI(fileName.c_str()), selection); + sp_file_open(fileName, selection); } return; @@ -681,7 +540,7 @@ sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d void sp_file_vacuum() { - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; unsigned int diff = vacuum_document (doc); @@ -713,7 +572,7 @@ sp_file_vacuum() * document; is true for normal save, false for temporary saves */ static bool -file_save(Gtk::Window &parentWindow, Document *doc, const Glib::ustring &uri, +file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key, bool saveas, bool official) { if (!doc || uri.size()<1) //Safety check @@ -755,7 +614,7 @@ file_save(Gtk::Window &parentWindow, Document *doc, const Glib::ustring &uri, * Used only for remote saving using VFS and a specific uri. Gets the file at the /tmp. */ bool -file_save_remote(Document */*doc*/, +file_save_remote(SPDocument */*doc*/, #ifdef WITH_GNOME_VFS const Glib::ustring &uri, #else @@ -843,7 +702,7 @@ file_save_remote(Document */*doc*/, * \param ascopy (optional) wether to set the documents->uri to the new filename or not */ bool -sp_file_save_dialog(Gtk::Window &parentWindow, Document *doc, bool is_copy) +sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) { Inkscape::XML::Node *repr = sp_document_repr_root(doc); @@ -978,7 +837,7 @@ sp_file_save_dialog(Gtk::Window &parentWindow, Document *doc, bool is_copy) * Save a document, displaying a SaveAs dialog if necessary. */ bool -sp_file_save_document(Gtk::Window &parentWindow, Document *doc) +sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) { bool success = true; @@ -1054,13 +913,13 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d * Import a resource. Called by sp_file_import() */ void -file_import(Document *in_doc, const Glib::ustring &uri, +file_import(SPDocument *in_doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; //DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key ); - Document *doc; + SPDocument *doc; try { doc = Inkscape::Extension::open(key, uri.c_str()); } catch (Inkscape::Extension::Input::no_extension_found &e) { @@ -1070,7 +929,7 @@ file_import(Document *in_doc, const Glib::ustring &uri, } if (doc != NULL) { - Inkscape::XML::rebase_hrefs((Inkscape::XML::Document *)doc, in_doc->base, true); + Inkscape::XML::rebase_hrefs(doc, in_doc->base, true); Inkscape::XML::Document *xml_in_doc = sp_document_repr_doc(in_doc); prevent_id_clashes(doc, in_doc); @@ -1191,7 +1050,7 @@ sp_file_import(Gtk::Window &parentWindow) { static Glib::ustring import_path; - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; if (!doc) return; @@ -1274,7 +1133,7 @@ bool sp_file_export_dialog(void *widget) { //# temp hack for 'doc' until we can switch to this dialog - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; Glib::ustring export_path; Glib::ustring export_loc; @@ -1410,7 +1269,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) if (!SP_ACTIVE_DOCUMENT) return false; - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; Glib::ustring export_path; Glib::ustring export_loc; @@ -1568,7 +1427,7 @@ sp_file_import_from_ocal(Gtk::Window &parentWindow) { static Glib::ustring import_path; - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; if (!doc) return; @@ -1626,7 +1485,7 @@ sp_file_import_from_ocal(Gtk::Window &parentWindow) void sp_file_print(Gtk::Window& parentWindow) { - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; if (doc) sp_print_document(parentWindow, doc); } @@ -1639,7 +1498,7 @@ void sp_file_print_preview(gpointer /*object*/, gpointer /*data*/) { - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; if (doc) sp_print_preview_document(doc); -- cgit v1.2.3 From c5b0b577134ed7c2df538ed019a6c07cb75bf38e Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Fri, 7 Aug 2009 09:31:39 +0000 Subject: 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) --- src/file.cpp | 65 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'src/file.cpp') 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::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; } -- cgit v1.2.3 From 606ebb35498c3d750bb2906954195baaa0fbcad6 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Sun, 9 Aug 2009 14:23:52 +0000 Subject: Fix remaining glitches in the behaviour of the Save dialogs (w.r.t. remembering the last file type and folder). As part of the cleanup inkscape:output_extension was removed, too. (bzr r8454) --- src/file.cpp | 157 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 69 insertions(+), 88 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index f16d87cbd..03fb7bd59 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -59,7 +59,6 @@ #include "selection.h" #include "sp-namedview.h" #include "style.h" -#include "ui/dialog/filedialog.h" #include "ui/dialog/ocaldialogs.h" #include "ui/view/view-widget.h" #include "uri.h" @@ -573,15 +572,17 @@ sp_file_vacuum() */ static bool file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, - Inkscape::Extension::Extension *key, bool saveas, bool official) + Inkscape::Extension::Extension *key, bool checkoverwrite, bool official, + Inkscape::Extension::FileSaveMethod save_method) { if (!doc || uri.size()<1) //Safety check return false; try { Inkscape::Extension::save(key, doc, uri.c_str(), - false, - saveas, official); + false, + checkoverwrite, official, + save_method); } 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); @@ -602,7 +603,7 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); return FALSE; } catch (Inkscape::Extension::Output::no_overwrite &e) { - return sp_file_save_dialog(parentWindow, doc); + return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); @@ -698,85 +699,58 @@ file_save_remote(SPDocument */*doc*/, /** * 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(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) +sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extension::FileSaveMethod save_method) { - - Inkscape::XML::Node *repr = sp_document_repr_root(doc); Inkscape::Extension::Output *extension = 0; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool is_copy = (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY); - //# Get the default extension name + // Note: default_extension has the format "org.inkscape.output.svg.inkscape", whereas + // filename_extension only uses ".svg" Glib::ustring default_extension; - char *attr = (char *)repr->attribute(is_copy ? "inkscape:output_extension_copy" : "inkscape:output_extension"); - if (!attr) { - 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; - } + Glib::ustring filename_extension = ".svg"; + + default_extension= Inkscape::Extension::get_file_save_extension(save_method); //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension); + extension = dynamic_cast + (Inkscape::Extension::db.get(default_extension.c_str())); + + if (extension) + filename_extension = extension->get_extension(); + Glib::ustring save_path; Glib::ustring save_loc; - if (!default_extension.empty()) { - extension = dynamic_cast - (Inkscape::Extension::db.get(default_extension.c_str())); - } else { - g_warning ("No default extension!!!! What to do?\n"); - } + save_path = Inkscape::Extension::get_file_save_path(doc, save_method); - 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(); + if (!Inkscape::IO::file_test(save_path.c_str(), + (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) + save_path = ""; - Glib::ustring attr3 = prefs->getString(is_copy ? "/dialogs/save_copy/path" : "/dialogs/save_as/path"); - if (!attr3.empty()) - save_path = attr3; - - if (!Inkscape::IO::file_test(save_path.c_str(), - (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) - save_path = ""; + if (save_path.size()<1) + save_path = g_get_home_dir(); - if (save_path.size()<1) - save_path = g_get_home_dir(); + save_loc = save_path; + save_loc.append(G_DIR_SEPARATOR_S); - save_loc = save_path; - save_loc.append(G_DIR_SEPARATOR_S); + 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); - 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()); + 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); - - 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 { + snprintf(formatBuf, 255, _("%s"), Glib::path_get_basename(doc->uri).c_str()); + save_loc.append(formatBuf); } // convert save_loc from utf-8 to locale @@ -803,7 +777,7 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) dialog_title, default_extension, doc_title ? doc_title : "", - is_copy + save_method ); saveDialog->setSelectionType(extension); @@ -834,15 +808,15 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, bool is_copy) else g_warning( "Error converting save filename to UTF-8." ); - success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy); + // FIXME: does the argument !is_copy really convey the correct meaning here? + success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy, save_method); if (success && SP_DOCUMENT_URI(doc)) { sp_file_add_recent(SP_DOCUMENT_URI(doc)); } save_path = Glib::path_get_dirname(fileName); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(is_copy ? "/dialogs/save_copy/path" : "/dialogs/save_as/path", save_path); + Inkscape::Extension::store_save_path_in_prefs(save_path, save_method); return success; } @@ -861,16 +835,26 @@ sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) bool success = true; if (doc->isModifiedSinceSave()) { - Inkscape::XML::Node *repr = sp_document_repr_root(doc); - if ( doc->uri == NULL - || repr->attribute("inkscape:output_extension") == NULL ) + if ( doc->uri == NULL ) { - return sp_file_save_dialog(parentWindow, doc, FALSE); + // Hier sollte in Argument mitgegeben werden, das anzeigt, daß das Dokument das erste + // Mal gespeichert wird, so daß als default .svg ausgewählt wird und nicht die zuletzt + // benutzte "Save as ..."-Endung + return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); } else { - gchar const *fn = g_strdup(doc->uri); - gchar const *ext = repr->attribute("inkscape:output_extension"); - success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext), FALSE, TRUE); - g_free((void *) fn); + Glib::ustring extension = Inkscape::Extension::get_file_save_extension(Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + Glib::ustring fn = g_strdup(doc->uri); + // Try to determine the extension from the uri; this may not lead to a valid extension, + // but this case is caught in the file_save method below (or rather in Extension::save() + // further down the line). + Glib::ustring ext = ""; + Glib::ustring::size_type pos = fn.rfind('.'); + if (pos != Glib::ustring::npos) { + // FIXME: this could/should be more sophisticated (see FileSaveDialog::appendExtension()), + // but hopefully it's a reasonable workaround for now + ext = fn.substr( pos ); + } + success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext.c_str()), FALSE, TRUE, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } } else { SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved.")); @@ -906,7 +890,7 @@ sp_file_save_as(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*data* if (!SP_ACTIVE_DOCUMENT) return false; sp_namedview_document_from_window(SP_ACTIVE_DESKTOP); - return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, FALSE); + return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } @@ -920,7 +904,7 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d if (!SP_ACTIVE_DOCUMENT) return false; sp_namedview_document_from_window(SP_ACTIVE_DESKTOP); - return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, TRUE); + return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY); } @@ -1162,13 +1146,10 @@ sp_file_export_dialog(void *widget) Inkscape::Extension::Output *extension; //# Get the default extension name - Glib::ustring default_extension; - char *attr = (char *)repr->attribute("inkscape:output_extension_export"); - if (!attr) { - Glib::ustring attr2 = prefs->getString("/dialogs/save_export/default"); - if(!attr2.empty()) default_extension = attr2; - } else { - default_extension = attr; + Glib::ustring default_extension = prefs->getString("/dialogs/save_export/default"); + if(default_extension.empty()) { + // FIXME: Is this a good default? Should there be a macro for the string? + default_extension = "org.inkscape.output.png.cairo"; } //g_message("%s: extension name: '%s'", __FUNCTION__, default_extension); @@ -1360,7 +1341,7 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) fileName = filePath; - success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE); + success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE, Inkscape::Extension::FILE_SAVE_METHOD_EXPORT); if (!success){ gchar *text = g_strdup_printf(_("Error saving a temporary copy")); -- cgit v1.2.3 From 39559f543f4034819b2ccc3fccac1ef8c1b1b049 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Sun, 9 Aug 2009 16:43:14 +0000 Subject: Cleanup (remove unused variable; use generic function to determine the file extension) (bzr r8455) --- src/file.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 03fb7bd59..8f40d7e4b 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1141,7 +1141,6 @@ sp_file_export_dialog(void *widget) Glib::ustring export_path; Glib::ustring export_loc; - Inkscape::XML::Node *repr = sp_document_repr_root(doc); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::Extension::Output *extension; -- cgit v1.2.3 From 9289c1726bbd97cb2befcfa19f21a79dd6a45d78 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Sun, 9 Aug 2009 16:43:39 +0000 Subject: Put #ifdefs around all code related to the so-called "new" ExportDialog (whatever that is) (bzr r8456) --- src/file.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 8f40d7e4b..420eaec63 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1123,9 +1123,6 @@ sp_file_import(Gtk::Window &parentWindow) ## E X P O R T ######################*/ -//#define NEW_EXPORT_DIALOG - - #ifdef NEW_EXPORT_DIALOG @@ -1192,7 +1189,7 @@ sp_file_export_dialog(void *widget) if ( export_path_local.size() > 0) export_path = export_path_local; - //# Show the SaveAs dialog + //# Show the Export dialog Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance = Inkscape::UI::Dialog::FileExportDialog::create( export_path, -- cgit v1.2.3 From 13fc2f2a9f44e43e79e698612993d4d8e63ccb94 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Sun, 9 Aug 2009 16:43:57 +0000 Subject: Fix compile when NEW_EXPORT_DIALOG is defined (however, the dialog crashes when trying to export files, dunno why) (bzr r8457) --- src/file.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 420eaec63..fd1438eb6 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1130,7 +1130,7 @@ sp_file_import(Gtk::Window &parentWindow) * Display an Export dialog, export as the selected type if OK pressed */ bool -sp_file_export_dialog(void *widget) +sp_file_export_dialog(Gtk::Window &parentWindow) { //# temp hack for 'doc' until we can switch to this dialog SPDocument *doc = SP_ACTIVE_DOCUMENT; @@ -1192,6 +1192,7 @@ sp_file_export_dialog(void *widget) //# Show the Export dialog Inkscape::UI::Dialog::FileExportDialog *exportDialogInstance = Inkscape::UI::Dialog::FileExportDialog::create( + parentWindow, export_path, Inkscape::UI::Dialog::EXPORT_TYPES, (char const *) _("Select file to export to"), @@ -1220,7 +1221,7 @@ sp_file_export_dialog(void *widget) else g_warning( "Error converting save filename to UTF-8." ); - success = file_save(doc, fileName, selectionType, TRUE, FALSE); + success = file_save(parentWindow, doc, fileName, selectionType, TRUE, FALSE, Inkscape::Extension::FILE_SAVE_METHOD_EXPORT); if (success) { Glib::RefPtr recent = Gtk::RecentManager::get_default(); @@ -1243,7 +1244,7 @@ sp_file_export_dialog(void *widget) * */ bool -sp_file_export_dialog(void */*widget*/) +sp_file_export_dialog(Gtk::Window &/*parentWindow*/) { sp_export_dialog(); return true; -- cgit v1.2.3 From 1807c74cbec5204385b71b3a120ebcd40f80c18e Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Wed, 16 Sep 2009 02:04:50 +0000 Subject: Fix by Adib for 353847 (bzr r8601) --- src/file.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index fd1438eb6..924ddc53d 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -591,6 +591,14 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, g_free(text); g_free(safeUri); return FALSE; + } catch (Inkscape::Extension::Output::file_read_only &e) { + gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str()); + gchar *text = g_strdup_printf(_("File %s is write protected. Please remove write protection and try again."), safeUri); + SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); + sp_ui_error_dialog(text); + g_free(text); + g_free(safeUri); + return FALSE; } catch (Inkscape::Extension::Output::save_failed &e) { gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str()); gchar *text = g_strdup_printf(_("File %s could not be saved."), safeUri); @@ -604,6 +612,9 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri, return FALSE; } catch (Inkscape::Extension::Output::no_overwrite &e) { return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + } catch (...) { + SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); + return FALSE; } SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); @@ -837,8 +848,8 @@ sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) if (doc->isModifiedSinceSave()) { if ( doc->uri == NULL ) { - // Hier sollte in Argument mitgegeben werden, das anzeigt, daß das Dokument das erste - // Mal gespeichert wird, so daß als default .svg ausgewählt wird und nicht die zuletzt + // Hier sollte in Argument mitgegeben werden, das anzeigt, da� das Dokument das erste + // Mal gespeichert wird, so da� als default .svg ausgew�hlt wird und nicht die zuletzt // benutzte "Save as ..."-Endung return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); } else { -- cgit v1.2.3 From e4943dbbb7588a780b1cce6fc412a92e00b92d6c Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Sun, 27 Sep 2009 21:36:48 +0000 Subject: Updated buildtool's files to undefine whiteboard. Comment out OCAL Export dialog. Also commented out verbs & file related functions for both as a precaution for command-line usage. (bzr r8661) --- src/file.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 924ddc53d..ef9706c33 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -68,9 +68,9 @@ # include #endif -#ifdef WITH_INKBOARD -#include "jabber_whiteboard/session-manager.h" -#endif +//#ifdef WITH_INKBOARD +//#include "jabber_whiteboard/session-manager.h" +//#endif #ifdef WIN32 #include @@ -1270,6 +1270,7 @@ sp_file_export_dialog(Gtk::Window &/*parentWindow*/) /** * Display an Export dialog, export as the selected type if OK pressed */ +/* bool sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) { @@ -1406,10 +1407,11 @@ sp_file_export_to_ocal_dialog(Gtk::Window &parentWindow) return success; } - +*/ /** * Export the current document to OCAL */ +/* void sp_file_export_to_ocal(Gtk::Window &parentWindow) { @@ -1421,7 +1423,7 @@ sp_file_export_to_ocal(Gtk::Window &parentWindow) if (success) SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Document exported...")); } - +*/ /*###################### ## I M P O R T F R O M O C A L -- cgit v1.2.3 From 6793d0aeee098a4141883649c044df7bdc8614ae Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Tue, 29 Sep 2009 03:07:09 +0000 Subject: Fixed leaking memory and added proper name fallback. Applies modified patch and addresses bug #436151. (bzr r8672) --- src/file.cpp | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index ef9706c33..4964d30d5 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -138,31 +138,48 @@ sp_file_new(const Glib::ustring &templ) return dt; } -SPDesktop* -sp_file_new_default() +SPDesktop* sp_file_new_default() { std::list sources; sources.push_back( profile_path("templates") ); // first try user's local dir sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir - - while (!sources.empty()) { - gchar *dirname = sources.front(); - if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) { - - // TRANSLATORS: default.svg is localizable - this is the name of the default document - // template. This way you can localize the default pagesize, translate the name of - // the default layer, etc. If you wish to localize this file, please create a - // localized share/templates/default.xx.svg file, where xx is your language code. - char *default_template = g_build_filename(dirname, _("default.svg"), NULL); - if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) { - return sp_file_new(default_template); + std::list baseNames; + gchar const* localized = _("default.svg"); + if (strcmp("default.svg", localized) != 0) { + baseNames.push_back(localized); + } + baseNames.push_back("default.svg"); + gchar *foundTemplate = 0; + + for (std::list::iterator nameIt = baseNames.begin(); (nameIt != baseNames.end()) && !foundTemplate; ++nameIt) { + for (std::list::iterator it = sources.begin(); (it != sources.end()) && !foundTemplate; ++it) { + gchar *dirname = *it; + if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) { + + // TRANSLATORS: default.svg is localizable - this is the name of the default document + // template. This way you can localize the default pagesize, translate the name of + // the default layer, etc. If you wish to localize this file, please create a + // localized share/templates/default.xx.svg file, where xx is your language code. + char *tmp = g_build_filename(dirname, *nameIt, NULL); + if (Inkscape::IO::file_test(tmp, G_FILE_TEST_IS_REGULAR)) { + foundTemplate = tmp; + } else { + g_free(tmp); + } } } - g_free(dirname); - sources.pop_front(); } - return sp_file_new(""); + for (std::list::iterator it = sources.begin(); it != sources.end(); ++it) { + g_free(*it); + } + + SPDesktop* desk = sp_file_new(foundTemplate ? foundTemplate : ""); + if (foundTemplate) { + g_free(foundTemplate); + foundTemplate = 0; + } + return desk; } -- cgit v1.2.3 From 62696234b51b95b6da2b2612162cc4f185481a47 Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Sun, 18 Oct 2009 19:17:16 +0000 Subject: Patch by Adib for 429529 (bzr r8792) --- src/file.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 4964d30d5..e0ecd5084 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -883,6 +883,10 @@ sp_file_save_document(Gtk::Window &parentWindow, SPDocument *doc) ext = fn.substr( pos ); } success = file_save(parentWindow, doc, fn, Inkscape::Extension::db.get(ext.c_str()), FALSE, TRUE, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + if (success == false) { + // give the user the chance to change filename or extension + return sp_file_save_dialog(parentWindow, doc, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); + } } } else { SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved.")); -- cgit v1.2.3