diff options
| author | Christophe Lebras <christophe.lebras@gmail.com> | 2017-07-02 02:50:06 +0000 |
|---|---|---|
| committer | Christophe Lebras <christophe.lebras@gmail.com> | 2017-07-02 03:11:49 +0000 |
| commit | 8f96d83587c2409c431754a08fb4b79cc19fc8c2 (patch) | |
| tree | a4f11d3fd03dd35478ae76a8ddd0993384590f70 /src | |
| parent | Add function to save template (diff) | |
| download | inkscape-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')
| -rw-r--r-- | src/file.cpp | 77 | ||||
| -rw-r--r-- | src/file.h | 4 | ||||
| -rw-r--r-- | src/ui/dialog/save-template-dialog.cpp | 26 |
3 files changed, 83 insertions, 24 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); } diff --git a/src/file.h b/src/file.h index 010bff94f..9cd22d744 100644 --- a/src/file.h +++ b/src/file.h @@ -114,7 +114,9 @@ bool sp_file_save_a_copy (Gtk::Window &parentWindow, void* object, void* data); * 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); /** * Saves the given document. Displays a file select dialog diff --git a/src/ui/dialog/save-template-dialog.cpp b/src/ui/dialog/save-template-dialog.cpp index e60648fd5..cf37feb3b 100644 --- a/src/ui/dialog/save-template-dialog.cpp +++ b/src/ui/dialog/save-template-dialog.cpp @@ -14,7 +14,8 @@ namespace UI { namespace Dialog { //TODO: Tooltips - //TODO: Save data +//TODO: Sanitize filename +//TODO: Check empty fields SaveTemplate::SaveTemplate() : Gtk::Dialog(_("Save Document as Template")), @@ -72,15 +73,9 @@ void SaveTemplate::on_name_changed() { void SaveTemplate::save_template(Gtk::Window &parentWindow) { - // std::cout - // << "Save template: " - // << name_text.get_text() << " " - // << author_text.get_text() << " " - // << description_text.get_text() << " " - // << keywords_text.get_text() << " " - // << is_default_template.get_active() << std::endl; - - sp_file_save_template(parentWindow); + sp_file_save_template(parentWindow, name_text.get_text(), + author_text.get_text(), description_text.get_text(), + keywords_text.get_text(), is_default_template.get_active()); } void SaveTemplate::save_document_as_template(Gtk::Window &parentWindow) { @@ -89,17 +84,10 @@ void SaveTemplate::save_document_as_template(Gtk::Window &parentWindow) { auto result = dialog.run(); - switch (result) { - - case Gtk::RESPONSE_OK: + if (result == Gtk::RESPONSE_OK){ - dialog.save_template(parentWindow); - break; - - default: - break; + dialog.save_template(parentWindow); } - } } |
