diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-10 21:35:54 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-31 14:50:39 +0000 |
| commit | b3949ea33b9145a8c285ff835a61a9f92188fbe7 (patch) | |
| tree | ad64121b2e4bf52f6fa8ed2ac45c28ce769b5fe4 | |
| parent | Templates: Remove unused "long_description" ("inkscape:_long" tag) (diff) | |
| download | inkscape-b3949ea33b9145a8c285ff835a61a9f92188fbe7.tar.gz inkscape-b3949ea33b9145a8c285ff835a61a9f92188fbe7.zip | |
Templates: Accept non-underscored variants of "inkscape:templateinfo"
| -rw-r--r-- | src/file.cpp | 10 | ||||
| -rw-r--r-- | src/io/file.cpp | 10 | ||||
| -rw-r--r-- | src/object/sp-factory.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.cpp | 37 |
4 files changed, 40 insertions, 19 deletions
diff --git a/src/file.cpp b/src/file.cpp index 6b8e52c45..a8ff49cb6 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -827,10 +827,10 @@ sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, auto root = document->getReprRoot(); auto xml_doc = document->getReprDoc(); - auto templateinfo_node = xml_doc->createElement("inkscape:_templateinfo"); + auto templateinfo_node = xml_doc->createElement("inkscape:templateinfo"); Inkscape::GC::release(templateinfo_node); - auto element_node = xml_doc->createElement("inkscape:_name"); + auto element_node = xml_doc->createElement("inkscape:name"); Inkscape::GC::release(element_node); element_node->appendChild(xml_doc->createTextNode(name.c_str())); @@ -847,7 +847,7 @@ sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, if (description.length() != 0) { - element_node = xml_doc->createElement("inkscape:_shortdesc"); + element_node = xml_doc->createElement("inkscape:shortdesc"); Inkscape::GC::release(element_node); element_node->appendChild(xml_doc->createTextNode(description.c_str())); @@ -864,7 +864,7 @@ sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, if (keywords.length() != 0) { - element_node = xml_doc->createElement("inkscape:_keywords"); + element_node = xml_doc->createElement("inkscape:keywords"); Inkscape::GC::release(element_node); element_node->appendChild(xml_doc->createTextNode(keywords.c_str())); @@ -888,7 +888,7 @@ sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); if (isDefault) { - // save as "default.svg" by default (so it works intependent of UI language)unless + // save as "default.svg" by default (so it works independently of UI language), unless // a localized template like "default.de.svg" is already present (which overrides "default.svg") Glib::ustring default_svg_localized = Glib::ustring("default.") + _("en") + ".svg"; filename = Inkscape::IO::Resource::get_path_ustring(USER, TEMPLATES, default_svg_localized.c_str()); diff --git a/src/io/file.cpp b/src/io/file.cpp index 877429d26..6317622bb 100644 --- a/src/io/file.cpp +++ b/src/io/file.cpp @@ -39,7 +39,15 @@ ink_file_new(const std::string &Template) 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"); + Inkscape::XML::Node *nodeToRemove; + + nodeToRemove = sp_repr_lookup_name(myRoot, "inkscape:templateinfo"); + if (nodeToRemove != nullptr) { + Inkscape::DocumentUndo::ScopedInsensitive no_undo(doc); + sp_repr_unparent(nodeToRemove); + delete nodeToRemove; + } + nodeToRemove = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); // backwards-compatibility if (nodeToRemove != nullptr) { Inkscape::DocumentUndo::ScopedInsensitive no_undo(doc); sp_repr_unparent(nodeToRemove); diff --git a/src/object/sp-factory.cpp b/src/object/sp-factory.cpp index cc635752e..e773354f2 100644 --- a/src/object/sp-factory.cpp +++ b/src/object/sp-factory.cpp @@ -315,7 +315,7 @@ SPObject *SPFactory::createObject(std::string const& id) {} else if (id == "inkscape:clipboard") // SP node not necessary {} - else if (id == "inkscape:_templateinfo") // ? + else if (id == "inkscape:templateinfo" || id == "inkscape:_templateinfo") // metadata for templates {} else if (id.empty()) // comments {} diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 9ca93910d..083513f4b 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -235,16 +235,19 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::s Inkscape::XML::Document *rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI); if (rdoc){ - Inkscape::XML::Node *myRoot = rdoc->root(); - if (strcmp(myRoot->name(), "svg:svg") != 0){ // Wrong file format + Inkscape::XML::Node *root = rdoc->root(); + if (strcmp(root->name(), "svg:svg") != 0){ // Wrong file format return result; } - myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); + Inkscape::XML::Node *templateinfo = sp_repr_lookup_name(root, "inkscape:templateinfo"); + if (!templateinfo) { + templateinfo = sp_repr_lookup_name(root, "inkscape:_templateinfo"); // backwards-compatibility + } - if (myRoot == nullptr) // No template info + if (templateinfo == nullptr) // No template info return result; - _getDataFromNode(myRoot, result); + _getDataFromNode(templateinfo, result); } return result; @@ -257,18 +260,20 @@ void TemplateLoadTab::_getProceduralTemplates() std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin(); while (it != effects.end()){ - Inkscape::XML::Node *myRoot; - myRoot = (*it)->get_repr(); - myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); + Inkscape::XML::Node *repr = (*it)->get_repr(); + Inkscape::XML::Node *templateinfo = sp_repr_lookup_name(repr, "inkscape:templateinfo"); + if (!templateinfo) { + templateinfo = sp_repr_lookup_name(repr, "inkscape:_templateinfo"); // backwards-compatibility + } - if (myRoot){ + if (templateinfo){ TemplateData result; result.display_name = (*it)->get_name(); result.is_procedural = true; result.path = ""; result.tpl_effect = *it; - _getDataFromNode(myRoot, result); + _getDataFromNode(templateinfo, result); _tdata[result.display_name] = result; } ++it; @@ -279,14 +284,22 @@ void TemplateLoadTab::_getProceduralTemplates() void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data) { Inkscape::XML::Node *currentData; - if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != nullptr) + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:name")) != nullptr) data.display_name = _(currentData->firstChild()->content()); + else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != nullptr) // backwards-compatibility + data.display_name = _(currentData->firstChild()->content()); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:author")) != nullptr) data.author = currentData->firstChild()->content(); - if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != nullptr) + + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:shortdesc")) != nullptr) + data.short_description = _( currentData->firstChild()->content()); + else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != nullptr) // backwards-compatibility data.short_description = _( currentData->firstChild()->content()); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != nullptr) data.preview_name = currentData->firstChild()->content(); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:date")) != nullptr) data.creation_date = currentData->firstChild()->content(); |
