diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-01-15 12:37:25 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-01-15 12:37:25 +0000 |
| commit | fdead58322deb6228f83b7ee9896c0b82ef709d9 (patch) | |
| tree | fc0545c342f07c4bff2b38c835658dbf3f5052fd /src/file.cpp | |
| parent | Update error messages. (diff) | |
| download | inkscape-fdead58322deb6228f83b7ee9896c0b82ef709d9.tar.gz inkscape-fdead58322deb6228f83b7ee9896c0b82ef709d9.zip | |
Use ink_file_open in sp_file_open.
Diffstat (limited to 'src/file.cpp')
| -rw-r--r-- | src/file.cpp | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/src/file.cpp b/src/file.cpp index 903795071..bdcde3c0e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -56,6 +56,7 @@ #include "helper/png-write.h" +#include "io/file.h" #include "io/resource.h" #include "io/resource-manager.h" #include "io/sys.h" @@ -215,37 +216,37 @@ bool sp_file_open(const Glib::ustring &uri, bool add_to_recent, bool replace_empty) { + if (!INKSCAPE.use_gui()) { + std::cerr << "sp_file_open requires GUI, use ink_file_open() instead." << std::endl; + return false; + } + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { desktop->setWaitingCursor(); } - SPDocument *doc = nullptr; + bool cancelled = false; - try { - doc = Inkscape::Extension::open(key, uri.c_str()); - } catch (Inkscape::Extension::Input::no_extension_found &e) { - doc = nullptr; - } catch (Inkscape::Extension::Input::open_failed &e) { - doc = nullptr; - } catch (Inkscape::Extension::Input::open_cancelled &e) { - doc = nullptr; - cancelled = true; - } + Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(uri); + SPDocument* doc = ink_file_open(file, cancelled); if (desktop) { desktop->clearWaitingCursor(); } if (doc) { + SPDocument *existing = desktop ? desktop->getDocument() : nullptr; if (existing && existing->virgin && replace_empty) { + // If the current desktop is empty, open the document there doc->ensureUpToDate(); // TODO this will trigger broken link warnings, etc. desktop->change_document(doc); doc->emitResizedSignal(doc->getWidth().value("px"), doc->getHeight().value("px")); } else { - // create a whole new desktop and window + + // Create a whole new desktop and window SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, nullptr)); // TODO this will trigger broken link warnings, etc. sp_create_window(dtw, TRUE); desktop = static_cast<SPDesktop*>(dtw->view); @@ -253,58 +254,56 @@ bool sp_file_open(const Glib::ustring &uri, doc->virgin = FALSE; - SPRoot *root = doc->getRoot(); - - // This is the only place original values should be set. - root->original.inkscape = root->version.inkscape; - root->original.svg = root->version.svg; - - if (INKSCAPE.use_gui()) { - if (sp_version_inside_range(root->version.inkscape, 0, 1, 0, 92)) { - sp_file_convert_dpi(doc); - } - } // If use_gui - - - // 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) { sp_file_add_recent( doc->getURI() ); } - if ( INKSCAPE.use_gui() ) { + // --------------- Fix up document ---------------- - SPNamedView *nv = desktop->namedview; - if (nv->lockguides) { - nv->lockGuides(); - } - // Perform a fixup pass for hrefs. - if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { - Glib::ustring msg = _("Broken links have been changed to point to existing files."); - desktop->showInfoDialog(msg); - } + // Fix DPI (90->96) + if (sp_version_inside_range(doc->getRoot()->version.inkscape, 0, 1, 0, 92)) { + sp_file_convert_dpi(doc); + } - // Check for font substitutions - Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); + // Perform a fixup pass for hrefs. + if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(doc) ) { + Glib::ustring msg = _("Broken links have been changed to point to existing files."); + desktop->showInfoDialog(msg); } - // Related bug:#1769679 #18 + + // Check for font substitutions + Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(doc); + + // Update LPE's See: Related bug:#1769679 #18 SPDefs * defs = dynamic_cast<SPDefs *>(doc->getDefs()); if (defs && !existing) { defs->emitModified(SP_OBJECT_MODIFIED_CASCADE); } - return TRUE; + + // ------------------ Window options --------------- + + // Resize the window to match the document properties + sp_namedview_window_from_document(desktop); + sp_namedview_update_layers_from_document(desktop); + + // Lock Guides + SPNamedView *nv = desktop->namedview; + if (nv->lockguides) { + nv->lockGuides(); + } + + return true; + } else if (!cancelled) { gchar *safeUri = Inkscape::IO::sanitizeString(uri.c_str()); 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; + return false; } - return FALSE; + return false; } /** @@ -524,7 +523,7 @@ sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d //# User selected something. Get name and type Glib::ustring fileName = openDialogInstance->getFilename(); - Inkscape::Extension::Extension *selection = + Inkscape::Extension::Extension *fileType = openDialogInstance->getSelectionType(); //# Code to check & open if multiple files. @@ -550,7 +549,7 @@ sp_file_open_dialog(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d #ifdef INK_DUMP_FILENAME_CONV g_message("Opening File %s\n", fileName.c_str()); #endif - sp_file_open(fileName, selection); + sp_file_open(fileName, fileType); } return; @@ -570,7 +569,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(fileName, fileType); } return; |
