diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-03-15 14:21:30 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-03-15 14:21:30 +0000 |
| commit | 1602477dfd4371a17639b0b6e4f59f5a5ea9565a (patch) | |
| tree | 6f4561f58d15f8b6608897e232b37658143d46e6 /src/io/file.cpp | |
| parent | Improve deb generation and install scripts (diff) | |
| download | inkscape-1602477dfd4371a17639b0b6e4f59f5a5ea9565a.tar.gz inkscape-1602477dfd4371a17639b0b6e4f59f5a5ea9565a.zip | |
Make InkscapeApplication responsible for managing documents and windows.
Any change from previous behavior is a bug.
Diffstat (limited to 'src/io/file.cpp')
| -rw-r--r-- | src/io/file.cpp | 105 |
1 files changed, 67 insertions, 38 deletions
diff --git a/src/io/file.cpp b/src/io/file.cpp index 5877e2727..294707464 100644 --- a/src/io/file.cpp +++ b/src/io/file.cpp @@ -2,7 +2,7 @@ /* * File operations (independent of GUI) * - * Copyright (C) 2018 Tavmjong Bah + * Copyright (C) 2018, 2019 Tavmjong Bah * * The contents of this file may be used under the GNU General Public License Version 2 or later. * @@ -14,6 +14,7 @@ #include "file.h" #include "document.h" +#include "document-undo.h" #include "extension/system.h" // Extension::open() #include "extension/extension.h" @@ -23,58 +24,86 @@ #include "object/sp-root.h" -// SPDocument* -// ink_file_new(const std::string &Template) -// { -// SPDocument *doc = SPDocument::createNewDoc( Template, true, true ); -// return doc; -// } +/** + * Create a blank document, remove any template data. + * Input: Empty string or template file name. + */ +SPDocument* +ink_file_new(const std::string &Template) +{ + SPDocument *doc = SPDocument::createNewDoc ((Template.empty() ? nullptr : Template.c_str()), true, true ); + + if (doc) { + // Remove all the template info from xml tree + Inkscape::XML::Node *myRoot = doc->getReprRoot(); + Inkscape::XML::Node *nodeToRemove = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); + if (nodeToRemove != nullptr) { + Inkscape::DocumentUndo::ScopedInsensitive no_undo(doc); + sp_repr_unparent(nodeToRemove); + delete nodeToRemove; + } + } else { + std::cout << "ink_file_new: Did not create new document!" << std::endl; + } + + return doc; +} SPDocument* ink_file_open(const Glib::RefPtr<Gio::File>& file, bool &cancelled) { - cancelled = false; + cancelled = false; - SPDocument *doc = nullptr; + SPDocument *doc = nullptr; - std::string path = file->get_path(); + std::string path = file->get_path(); - try { - doc = Inkscape::Extension::open(nullptr, path.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) { - cancelled = true; - doc = nullptr; - } - - // Try to open explicitly as SVG. - if (doc == nullptr && !cancelled) { try { - doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), path.c_str()); + doc = Inkscape::Extension::open(nullptr, path.c_str()); } catch (Inkscape::Extension::Input::no_extension_found &e) { - doc = nullptr; + doc = nullptr; } catch (Inkscape::Extension::Input::open_failed &e) { - doc = nullptr; + doc = nullptr; } catch (Inkscape::Extension::Input::open_cancelled &e) { - cancelled = true; - doc = nullptr; + cancelled = true; + doc = nullptr; } - } - if (doc == nullptr) { - std::cerr << "ink_file_open: '" << path << "' cannot be opened!" << std::endl; - } else { + // Try to open explicitly as SVG. + if (doc == nullptr && !cancelled) { + try { + doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), path.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) { + cancelled = true; + doc = nullptr; + } + } - // This is the only place original values should be set. - SPRoot *root = doc->getRoot(); - root->original.inkscape = root->version.inkscape; - root->original.svg = root->version.svg; - } + if (doc == nullptr) { + std::cerr << "ink_file_open: '" << path << "' cannot be opened!" << std::endl; + } else { - return doc; + // This is the only place original values should be set. + SPRoot *root = doc->getRoot(); + root->original.inkscape = root->version.inkscape; + root->original.svg = root->version.svg; + } + + return doc; } +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : |
