From 6a26fa643d13e46319bc96ede55bfd7581bff239 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sat, 10 Aug 2019 23:31:37 +0200 Subject: Templates: Remove unused "long_description" ("inkscape:_long" tag) Probably fine to bring back, but it needs proper documentation. --- src/ui/dialog/template-load-tab.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/ui/dialog/template-load-tab.cpp') diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 6c17a9a96..9ca93910d 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -170,8 +170,7 @@ void TemplateLoadTab::_refreshTemplatesList() if (it.second.keywords.count(_current_keyword.lowercase()) != 0 || it.second.display_name.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || it.second.author.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || - it.second.short_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || - it.second.long_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos ) + it.second.short_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos) { Gtk::TreeModel::iterator iter = _tlist_store->append(); Gtk::TreeModel::Row row = *iter; @@ -286,8 +285,6 @@ void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateDa data.author = currentData->firstChild()->content(); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != nullptr) data.short_description = _( currentData->firstChild()->content()); - if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_long") )!= nullptr) - data.long_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) -- cgit v1.2.3 From b3949ea33b9145a8c285ff835a61a9f92188fbe7 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sat, 10 Aug 2019 23:35:54 +0200 Subject: Templates: Accept non-underscored variants of "inkscape:templateinfo" --- src/ui/dialog/template-load-tab.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/ui/dialog/template-load-tab.cpp') 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::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(); -- cgit v1.2.3 From c6e8c1efdf2395580c261da2f29b26e40f97d726 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 11 Aug 2019 00:29:46 +0200 Subject: Templates: Translate metadata within extension contexts (i.e. implement "translationdomain" for procedural templates) --- src/ui/dialog/template-load-tab.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/ui/dialog/template-load-tab.cpp') diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 083513f4b..f290dcab7 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -19,6 +19,7 @@ #include #include +#include "extension/extension.h" #include "extension/db.h" #include "inkscape.h" #include "file.h" @@ -273,29 +274,39 @@ void TemplateLoadTab::_getProceduralTemplates() result.path = ""; result.tpl_effect = *it; - _getDataFromNode(templateinfo, result); + _getDataFromNode(templateinfo, result, *it); _tdata[result.display_name] = result; } ++it; } } +// if the template data comes from a procedural template (aka Effect extension), +// attempt to translate within the extension's context (which might use a different gettext textdomain) +const char *_translate(const char* msgid, Extension::Extension *extension) +{ + if (extension) { + return extension->get_translation(msgid); + } else { + return _(msgid); + } +} -void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data) +void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data, Extension::Extension *extension) { Inkscape::XML::Node *currentData; if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:name")) != nullptr) - data.display_name = _(currentData->firstChild()->content()); + data.display_name = _translate(currentData->firstChild()->content(), extension); else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != nullptr) // backwards-compatibility - data.display_name = _(currentData->firstChild()->content()); + data.display_name = _translate(currentData->firstChild()->content(), extension); 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) - data.short_description = _( currentData->firstChild()->content()); + data.short_description = _translate(currentData->firstChild()->content(), extension); else if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != nullptr) // backwards-compatibility - data.short_description = _( currentData->firstChild()->content()); + data.short_description = _translate(currentData->firstChild()->content(), extension); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != nullptr) data.preview_name = currentData->firstChild()->content(); @@ -304,7 +315,7 @@ void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateDa data.creation_date = currentData->firstChild()->content(); if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_keywords")) != nullptr){ - Glib::ustring tplKeywords = _(currentData->firstChild()->content()); + Glib::ustring tplKeywords = _translate(currentData->firstChild()->content(), extension); while (!tplKeywords.empty()){ std::size_t pos = tplKeywords.find_first_of(" "); if (pos == Glib::ustring::npos) -- cgit v1.2.3