summaryrefslogtreecommitdiffstats
path: root/src/file.cpp
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-07-09 12:42:10 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-07-09 12:42:10 +0000
commit241554b7ad311b5868ba284c7a4e6a410432b9bd (patch)
tree8bf6fed572d27e9b97ca60b90ae1684ba4856eeb /src/file.cpp
parentUse .xml when exporting shortcuts by default (diff)
parentShortcuts: Fix for 7d248fbba5b0c24d9a24cda8c3f2e79f96395553 (is_user_set was ... (diff)
downloadinkscape-241554b7ad311b5868ba284c7a4e6a410432b9bd.tar.gz
inkscape-241554b7ad311b5868ba284c7a4e6a410432b9bd.zip
Merge branch 'master' into shortcuts
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp159
1 files changed, 108 insertions, 51 deletions
diff --git a/src/file.cpp b/src/file.cpp
index 43a9c6f5b..549ed7d6e 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -50,6 +50,7 @@
#include "inkscape-version.h"
#include "ui/interface.h"
#include "io/sys.h"
+#include "io/resource.h"
#include "message-stack.h"
#include "path-prefix.h"
#include "print.h"
@@ -67,6 +68,8 @@
using Inkscape::DocumentUndo;
+using Inkscape::IO::Resource::TEMPLATES;
+using Inkscape::IO::Resource::USER;
#ifdef WITH_GNOME_VFS
# include <libgnomevfs/gnome-vfs.h>
@@ -120,7 +123,7 @@ SPDesktop *sp_file_new(const std::string &templ)
{
SPDocument *doc = SPDocument::createNewDoc( !templ.empty() ? templ.c_str() : 0 , TRUE, true );
g_return_val_if_fail(doc != NULL, NULL);
-
+
// 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");
@@ -130,11 +133,11 @@ SPDesktop *sp_file_new(const std::string &templ)
delete nodeToRemove;
DocumentUndo::setUndoSensitive(doc, true);
}
-
+
SPDesktop *olddesktop = SP_ACTIVE_DESKTOP;
if (olddesktop)
olddesktop->setWaitingCursor();
-
+
SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
g_return_val_if_fail(dtw != NULL, NULL);
sp_create_window(dtw, TRUE);
@@ -143,12 +146,12 @@ SPDesktop *sp_file_new(const std::string &templ)
doc->doUnref();
sp_namedview_window_from_document(desktop);
- sp_namedview_update_layers_from_document(desktop);
+ sp_namedview_update_layers_from_document(desktop);
#ifdef WITH_DBUS
Inkscape::Extension::Dbus::dbus_init_desktop_interface(desktop);
#endif
-
+
if (olddesktop)
olddesktop->clearWaitingCursor();
if (desktop)
@@ -159,48 +162,7 @@ SPDesktop *sp_file_new(const std::string &templ)
Glib::ustring sp_file_default_template_uri()
{
- std::list<gchar *> sources;
- sources.push_back( Inkscape::Application::profile_path("templates") ); // first try user's local dir
- sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
- std::list<gchar const*> 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<gchar *>::iterator it = sources.begin(); (it != sources.end()) && !foundTemplate; ++it) {
- for (std::list<gchar const*>::iterator nameIt = baseNames.begin(); (nameIt != baseNames.end()) && !foundTemplate; ++nameIt) {
- 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);
- }
- }
- }
- }
-
- for (std::list<gchar *>::iterator it = sources.begin(); it != sources.end(); ++it) {
- g_free(*it);
- }
-
- Glib::ustring templateUri = foundTemplate ? foundTemplate : "";
-
- if (foundTemplate) {
- g_free(foundTemplate);
- foundTemplate = 0;
- }
-
- return templateUri;
+ return Inkscape::IO::Resource::get_filename(TEMPLATES, "default.svg", _("default.svg"));
}
SPDesktop* sp_file_new_default()
@@ -1045,6 +1007,101 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d
return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY);
}
+/**
+ * Save a copy of a document as template.
+ */
+void
+sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name,
+ Glib::ustring author, Glib::ustring description, Glib::ustring keywords,
+ bool isDefault)
+{
+
+ if (!SP_ACTIVE_DOCUMENT || name.length() == 0)
+ return;
+
+ auto document = SP_ACTIVE_DOCUMENT;
+
+ DocumentUndo::setUndoSensitive(document, false);
+
+ auto root = document->getReprRoot();
+ auto xml_doc = document->getReprDoc();
+
+ auto templateinfo_node = xml_doc->createElement("inkscape:_templateinfo");
+ Inkscape::GC::release(templateinfo_node);
+
+ auto element_node = xml_doc->createElement("inkscape:_name");
+ Inkscape::GC::release(element_node);
+
+ element_node->appendChild(xml_doc->createTextNode(name.c_str()));
+ templateinfo_node->appendChild(element_node);
+
+ if (author.length() != 0) {
+
+ element_node = xml_doc->createElement("inkscape:author");
+ Inkscape::GC::release(element_node);
+
+ element_node->appendChild(xml_doc->createTextNode(author.c_str()));
+ templateinfo_node->appendChild(element_node);
+ }
+
+ if (description.length() != 0) {
+
+ element_node = xml_doc->createElement("inkscape:_shortdesc");
+ Inkscape::GC::release(element_node);
+
+ element_node->appendChild(xml_doc->createTextNode(description.c_str()));
+ templateinfo_node->appendChild(element_node);
+
+ }
+
+ element_node = xml_doc->createElement("inkscape:date");
+ Inkscape::GC::release(element_node);
+
+ element_node->appendChild(xml_doc->createTextNode(
+ Glib::DateTime::create_now_local().format("%F").c_str()));
+ templateinfo_node->appendChild(element_node);
+
+ if (keywords.length() != 0) {
+
+ element_node = xml_doc->createElement("inkscape:_keywords");
+ Inkscape::GC::release(element_node);
+
+ element_node->appendChild(xml_doc->createTextNode(keywords.c_str()));
+ templateinfo_node->appendChild(element_node);
+
+ }
+
+ root->appendChild(templateinfo_node);
+
+ if (isDefault) {
+
+ auto filename = Inkscape::IO::Resource::get_path_ustring(USER,
+ TEMPLATES, "default.svg");
+ file_save(parentWindow, document, filename,
+ Inkscape::Extension::db.get(".svg"), false, false,
+ Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG);
+ }
+
+ name.append(".svg");
+
+ auto filename = Inkscape::IO::Resource::get_path_ustring(USER, TEMPLATES,
+ name.c_str());
+ file_save(parentWindow, document, filename,
+ Inkscape::Extension::db.get(".svg"), false, false,
+ Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG);
+
+ auto nodeToRemove = sp_repr_lookup_name(root, "inkscape:_templateinfo");
+
+ if (nodeToRemove != NULL){
+
+ sp_repr_unparent(nodeToRemove);
+ delete nodeToRemove;
+ }
+
+ DocumentUndo::setUndoSensitive(document, true);
+}
+
+
/*######################
## I M P O R T
@@ -1108,7 +1165,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place)
SPLPEItem * pasted_lpe_item = dynamic_cast<SPLPEItem *>(pasted);
if (pasted_lpe_item){
pasted_lpe_item->forkPathEffectsIfNecessary(1);
- }
+ }
pasted_objects_not.push_back(obj_copy);
}
Inkscape::Selection *selection = desktop->getSelection();
@@ -1166,7 +1223,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri,
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
bool cancelled = false;
-
+
//DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
SPDocument *doc;
try {
@@ -1699,7 +1756,7 @@ Inkscape::UI::Dialog::OCAL::ImportDialog* import_ocal_dialog = NULL;
void on_import_from_ocal_response(Glib::ustring filename)
{
SPDocument *doc = SP_ACTIVE_DOCUMENT;
-
+
if (!filename.empty()) {
Inkscape::Extension::Extension *selection = import_ocal_dialog->get_selection_type();
file_import(doc, filename, selection);
@@ -1725,7 +1782,7 @@ sp_file_import_from_ocal(Gtk::Window &parent_window)
import_ocal_dialog->signal_response().connect(
sigc::ptr_fun(&on_import_from_ocal_response));
}
-
+
import_ocal_dialog->show_all();
}