summaryrefslogtreecommitdiffstats
path: root/src/file.cpp
diff options
context:
space:
mode:
authorChristophe Lebras <christophe.lebras@gmail.com>2017-07-02 02:50:06 +0000
committerChristophe Lebras <christophe.lebras@gmail.com>2017-07-02 03:11:49 +0000
commit8f96d83587c2409c431754a08fb4b79cc19fc8c2 (patch)
treea4f11d3fd03dd35478ae76a8ddd0993384590f70 /src/file.cpp
parentAdd function to save template (diff)
downloadinkscape-8f96d83587c2409c431754a08fb4b79cc19fc8c2.tar.gz
inkscape-8f96d83587c2409c431754a08fb4b79cc19fc8c2.zip
Manage template informations
Template informations are added to the saved file. File name is is the same as template name Template is saved as default.svg only if requested by user.
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp77
1 files changed, 73 insertions, 4 deletions
diff --git a/src/file.cpp b/src/file.cpp
index 958d2b620..47385c53e 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -1011,14 +1011,83 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d
* Save a copy of a document as template.
*/
void
-sp_file_save_template(Gtk::Window &parentWindow)
+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)
return;
- ///auto filename = Inkscape::IO::Resource::get_filename(TEMPLATES, "default.svg");
- auto filename = Inkscape::IO::Resource::get_path_ustring(USER, TEMPLATES, "default.svg");
- file_save(parentWindow, SP_ACTIVE_DOCUMENT, filename, Inkscape::Extension::db.get(".svg"), false, false, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG);
+ 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);
+
+ 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);
+
+ 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);
+
+ 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 += ".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);
}