From 664b20d7da3629cfa0a1d6e9449881b5e9f59be9 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 16:48:54 +0200 Subject: Rename parameter source files to avoid name conflicts --- src/extension/prefdialog/parameter.cpp | 415 +++++++++++++++++++++++++++++++++ 1 file changed, 415 insertions(+) create mode 100644 src/extension/prefdialog/parameter.cpp (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp new file mode 100644 index 000000000..159f54b9c --- /dev/null +++ b/src/extension/prefdialog/parameter.cpp @@ -0,0 +1,415 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Parameters for extensions. + */ +/* Author: + * Ted Gould + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2005-2007 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifdef linux // does the dollar sign need escaping when passed as string parameter? +# define ESCAPE_DOLLAR_COMMANDLINE +#endif + +#include +#include + +#include +#include + +#include "parameter.h" +#include "parameter-bool.h" +#include "parameter-color.h" +#include "parameter-description.h" +#include "parameter-enum.h" +#include "parameter-float.h" +#include "parameter-int.h" +#include "parameter-notebook.h" +#include "parameter-radiobutton.h" +#include "parameter-string.h" + +#include "extension/extension.h" + +#include "object/sp-defs.h" + +#include "ui/widget/color-notebook.h" + +#include "xml/node.h" + + +namespace Inkscape { +namespace Extension { + +Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) +{ + const char *name = in_repr->attribute("name"); + const char *type = in_repr->attribute("type"); + + // we can't create a parameter without type + if (!type) { + return nullptr; + } + // also require name unless it's a pure UI element that does not store its value + if (!name) { + static std::vector ui_elements = {"description"}; + if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { + return nullptr; + } + } + + const char *text = in_repr->attribute("gui-text"); + if (text == nullptr) { + text = in_repr->attribute("_gui-text"); + if (text == nullptr) { + // text = ""; // probably better to require devs to explicitly set an empty gui-text if this is what they want + } else { + const char *context = in_repr->attribute("msgctxt"); + if (context != nullptr) { + text = g_dpgettext2(nullptr, context, text); + } else { + text = _(text); + } + } + } + const char *description = in_repr->attribute("gui-description"); + if (description == nullptr) { + description = in_repr->attribute("_gui-description"); + if (description != nullptr) { + const char *context = in_repr->attribute("msgctxt"); + if (context != nullptr) { + description = g_dpgettext2(nullptr, context, description); + } else { + description = _(description); + } + } + } + bool hidden = false; + { + const char *gui_hide = in_repr->attribute("gui-hidden"); + if (gui_hide != nullptr) { + if (strcmp(gui_hide, "1") == 0 || + strcmp(gui_hide, "true") == 0) { + hidden = true; + } + /* else stays false */ + } + } + int indent = 0; + { + const char *indent_attr = in_repr->attribute("indent"); + if (indent_attr != nullptr) { + if (strcmp(indent_attr, "true") == 0) { + indent = 1; + } else { + indent = atoi(indent_attr); + } + } + } + const gchar* appearance = in_repr->attribute("appearance"); + + Parameter * param = nullptr; + if (!strcmp(type, "boolean")) { + param = new ParamBool(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "int")) { + if (appearance && !strcmp(appearance, "full")) { + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); + } else { + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::MINIMAL); + } + } else if (!strcmp(type, "float")) { + if (appearance && !strcmp(appearance, "full")) { + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); + } else { + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); + } + } else if (!strcmp(type, "string")) { + param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); + gchar const * max_length = in_repr->attribute("max_length"); + if (max_length != nullptr) { + ParamString * ps = dynamic_cast(param); + ps->setMaxLength(atoi(max_length)); + } + } else if (!strcmp(type, "description")) { + ParamDescription::AppearanceMode appearance_mode = ParamDescription::DESCRIPTION; + if (appearance) { + if (!strcmp(appearance, "header")) { + appearance_mode = ParamDescription::HEADER; + } else if (!strcmp(appearance, "url")) { + appearance_mode = ParamDescription::URL; + } + } + param = new ParamDescription(name, text, description, hidden, indent, in_ext, in_repr, appearance_mode); + } else if (!strcmp(type, "enum")) { + param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "notebook")) { + param = new ParamNotebook(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "optiongroup")) { + if (appearance && !strcmp(appearance, "minimal")) { + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); + } else { + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); + } + } else if (!strcmp(type, "color")) { + param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); + } + + // Note: param could equal NULL + return param; +} + +bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamBool const *boolpntr = dynamic_cast(this); + if (!boolpntr) { + throw Extension::param_not_bool_param(); + } + return boolpntr->get(doc, node); +} + +int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamInt const *intpntr = dynamic_cast(this); + if (!intpntr) { + throw Extension::param_not_int_param(); + } + return intpntr->get(doc, node); +} + +float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamFloat const *floatpntr = dynamic_cast(this); + if (!floatpntr) { + throw Extension::param_not_float_param(); + } + return floatpntr->get(doc, node); +} + +gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamString const *stringpntr = dynamic_cast(this); + if (!stringpntr) { + throw Extension::param_not_string_param(); + } + return stringpntr->get(doc, node); +} + +gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->get(doc, node); +} + +bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->contains(value, doc, node); +} + +gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const +{ + ParamRadioButton const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_optiongroup_param(); + } + return param->get(doc, node); +} + +guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const +{ + ParamColor const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_color_param(); + } + return param->get(doc, node); +} + +bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamBool * boolpntr = dynamic_cast(this); + if (boolpntr == nullptr) + throw Extension::param_not_bool_param(); + return boolpntr->set(in, doc, node); +} + +int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamInt * intpntr = dynamic_cast(this); + if (intpntr == nullptr) + throw Extension::param_not_int_param(); + return intpntr->set(in, doc, node); +} + +/** Wrapper to cast to the object and use it's function. */ +float +Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamFloat * floatpntr; + floatpntr = dynamic_cast(this); + if (floatpntr == nullptr) + throw Extension::param_not_float_param(); + return floatpntr->set(in, doc, node); +} + +/** Wrapper to cast to the object and use it's function. */ +gchar const * +Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamString * stringpntr = dynamic_cast(this); + if (stringpntr == nullptr) + throw Extension::param_not_string_param(); + return stringpntr->set(in, doc, node); +} + +gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamRadioButton *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_optiongroup_param(); + } + return param->set(in, doc, node); +} + +gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamComboBox *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->set(in, doc, node); +} + + +/** Wrapper to cast to the object and use it's function. */ +guint32 +Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamColor* param = dynamic_cast(this); + if (param == nullptr) + throw Extension::param_not_color_param(); + return param->set(in, doc, node); +} + + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : + _description(nullptr), + _text(nullptr), + _hidden(hidden), + _indent(indent), + _extension(ext), + _name(nullptr) +{ + if (name != nullptr) { + _name = g_strdup(name); + } + + if (description != nullptr) { + _description = g_strdup(description); + } + + if (text != nullptr) { + _text = g_strdup(text); + } else { + _text = g_strdup(name); + } + + return; +} + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : + _description(nullptr), + _text(nullptr), + _hidden(false), + _indent(0), + _extension(ext), + _name(nullptr) +{ + if (name != nullptr) { + _name = g_strdup(name); + } + if (text != nullptr) { + _text = g_strdup(text); + } else { + _text = g_strdup(name); + } + + return; +} + +Parameter::~Parameter() +{ + g_free(_name); + _name = nullptr; + + g_free(_text); + _text = nullptr; + + g_free(_description); + _description = nullptr; +} + +gchar *Parameter::pref_name() const +{ + return g_strdup_printf("%s.%s", _extension->get_id(), _name); +} + +/** Basically, if there is no widget pass a NULL. */ +Gtk::Widget * +Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) +{ + return nullptr; +} + +/** If I'm not sure which it is, just don't return a value. */ +void Parameter::string(std::string &/*string*/) const +{ + // TODO investigate clearing the target string. +} + +void Parameter::string(std::list &list) const +{ + std::string value; + string(value); + if (!value.empty()) { + std::string final; + final += "--"; + final += name(); + final += "="; + final += value; + + list.insert(list.end(), final); + } +} + +Parameter *Parameter::get_param(gchar const * /*name*/) +{ + return nullptr; +} + +Glib::ustring const extension_pref_root = "/extensions/"; + +} // namespace Extension +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From b666a19dafd98235907cfa9408405f06b9555765 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 17:16:06 +0200 Subject: Remove unused define ESCAPE_DOLLAR_COMMANDLINE --- src/extension/prefdialog/parameter.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 159f54b9c..abda73e18 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - #include #include -- cgit v1.2.3 From ef97e481b40f407f1328ecda471704750bd7e2a2 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 23:58:51 +0200 Subject: Move error classes to Parameter where they belong --- src/extension/prefdialog/parameter.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index abda73e18..7a3748100 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -162,7 +162,7 @@ bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) { ParamBool const *boolpntr = dynamic_cast(this); if (!boolpntr) { - throw Extension::param_not_bool_param(); + throw param_not_bool_param(); } return boolpntr->get(doc, node); } @@ -171,7 +171,7 @@ int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) c { ParamInt const *intpntr = dynamic_cast(this); if (!intpntr) { - throw Extension::param_not_int_param(); + throw param_not_int_param(); } return intpntr->get(doc, node); } @@ -180,7 +180,7 @@ float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *nod { ParamFloat const *floatpntr = dynamic_cast(this); if (!floatpntr) { - throw Extension::param_not_float_param(); + throw param_not_float_param(); } return floatpntr->get(doc, node); } @@ -189,7 +189,7 @@ gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node co { ParamString const *stringpntr = dynamic_cast(this); if (!stringpntr) { - throw Extension::param_not_string_param(); + throw param_not_string_param(); } return stringpntr->get(doc, node); } @@ -198,7 +198,7 @@ gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node cons { ParamComboBox const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_enum_param(); + throw param_not_enum_param(); } return param->get(doc, node); } @@ -207,7 +207,7 @@ bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, In { ParamComboBox const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_enum_param(); + throw param_not_enum_param(); } return param->contains(value, doc, node); } @@ -216,7 +216,7 @@ gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::No { ParamRadioButton const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_optiongroup_param(); + throw param_not_optiongroup_param(); } return param->get(doc, node); } @@ -225,7 +225,7 @@ guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *n { ParamColor const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_color_param(); + throw param_not_color_param(); } return param->get(doc, node); } @@ -234,7 +234,7 @@ bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) { ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == nullptr) - throw Extension::param_not_bool_param(); + throw param_not_bool_param(); return boolpntr->set(in, doc, node); } @@ -242,7 +242,7 @@ int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) { ParamInt * intpntr = dynamic_cast(this); if (intpntr == nullptr) - throw Extension::param_not_int_param(); + throw param_not_int_param(); return intpntr->set(in, doc, node); } @@ -253,7 +253,7 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) ParamFloat * floatpntr; floatpntr = dynamic_cast(this); if (floatpntr == nullptr) - throw Extension::param_not_float_param(); + throw param_not_float_param(); return floatpntr->set(in, doc, node); } @@ -263,7 +263,7 @@ Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * { ParamString * stringpntr = dynamic_cast(this); if (stringpntr == nullptr) - throw Extension::param_not_string_param(); + throw param_not_string_param(); return stringpntr->set(in, doc, node); } @@ -271,7 +271,7 @@ gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, In { ParamRadioButton *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_optiongroup_param(); + throw param_not_optiongroup_param(); } return param->set(in, doc, node); } @@ -280,7 +280,7 @@ gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape:: { ParamComboBox *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_enum_param(); + throw param_not_enum_param(); } return param->set(in, doc, node); } @@ -292,7 +292,7 @@ Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) { ParamColor* param = dynamic_cast(this); if (param == nullptr) - throw Extension::param_not_color_param(); + throw param_not_color_param(); return param->set(in, doc, node); } -- cgit v1.2.3 From 8f7a3a637f6a465e78e88490a03f539f0d8fdc1a Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Tue, 23 Jul 2019 01:06:21 +0200 Subject: Refactor a lot of the parameter handling code Many fixes, improvements and simplifications to existing code. Implements the first part of the changes discussed in https://gitlab.com/inkscape/inkscape/issues/333 --- src/extension/prefdialog/parameter.cpp | 288 ++++++++++++++++----------------- 1 file changed, 135 insertions(+), 153 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 7a3748100..d3293a0db 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -22,11 +22,10 @@ #include "parameter-bool.h" #include "parameter-color.h" #include "parameter-description.h" -#include "parameter-enum.h" #include "parameter-float.h" #include "parameter-int.h" #include "parameter-notebook.h" -#include "parameter-radiobutton.h" +#include "parameter-optiongroup.h" #include "parameter-string.h" #include "extension/extension.h" @@ -43,118 +42,36 @@ namespace Extension { Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) { - const char *name = in_repr->attribute("name"); - const char *type = in_repr->attribute("type"); + Parameter *param = nullptr; - // we can't create a parameter without type + const char *type = in_repr->attribute("type"); if (!type) { - return nullptr; - } - // also require name unless it's a pure UI element that does not store its value - if (!name) { - static std::vector ui_elements = {"description"}; - if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { - return nullptr; - } - } - - const char *text = in_repr->attribute("gui-text"); - if (text == nullptr) { - text = in_repr->attribute("_gui-text"); - if (text == nullptr) { - // text = ""; // probably better to require devs to explicitly set an empty gui-text if this is what they want - } else { - const char *context = in_repr->attribute("msgctxt"); - if (context != nullptr) { - text = g_dpgettext2(nullptr, context, text); - } else { - text = _(text); - } - } - } - const char *description = in_repr->attribute("gui-description"); - if (description == nullptr) { - description = in_repr->attribute("_gui-description"); - if (description != nullptr) { - const char *context = in_repr->attribute("msgctxt"); - if (context != nullptr) { - description = g_dpgettext2(nullptr, context, description); - } else { - description = _(description); - } - } - } - bool hidden = false; - { - const char *gui_hide = in_repr->attribute("gui-hidden"); - if (gui_hide != nullptr) { - if (strcmp(gui_hide, "1") == 0 || - strcmp(gui_hide, "true") == 0) { - hidden = true; - } - /* else stays false */ - } - } - int indent = 0; - { - const char *indent_attr = in_repr->attribute("indent"); - if (indent_attr != nullptr) { - if (strcmp(indent_attr, "true") == 0) { - indent = 1; - } else { - indent = atoi(indent_attr); - } - } - } - const gchar* appearance = in_repr->attribute("appearance"); - - Parameter * param = nullptr; - if (!strcmp(type, "boolean")) { - param = new ParamBool(name, text, description, hidden, indent, in_ext, in_repr); + // we can't create a parameter without type + g_warning("Parameter without type in extension '%s'.", in_ext->get_id()); + } else if(!strcmp(type, "boolean")) { + param = new ParamBool(in_repr, in_ext); } else if (!strcmp(type, "int")) { - if (appearance && !strcmp(appearance, "full")) { - param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); - } else { - param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::MINIMAL); - } + param = new ParamInt(in_repr, in_ext); } else if (!strcmp(type, "float")) { - if (appearance && !strcmp(appearance, "full")) { - param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); - } else { - param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); - } + param = new ParamFloat(in_repr, in_ext); } else if (!strcmp(type, "string")) { - param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); - gchar const * max_length = in_repr->attribute("max_length"); - if (max_length != nullptr) { - ParamString * ps = dynamic_cast(param); - ps->setMaxLength(atoi(max_length)); - } + param = new ParamString(in_repr, in_ext); } else if (!strcmp(type, "description")) { - ParamDescription::AppearanceMode appearance_mode = ParamDescription::DESCRIPTION; - if (appearance) { - if (!strcmp(appearance, "header")) { - appearance_mode = ParamDescription::HEADER; - } else if (!strcmp(appearance, "url")) { - appearance_mode = ParamDescription::URL; - } - } - param = new ParamDescription(name, text, description, hidden, indent, in_ext, in_repr, appearance_mode); - } else if (!strcmp(type, "enum")) { - param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); + param = new ParamDescription(in_repr, in_ext); } else if (!strcmp(type, "notebook")) { - param = new ParamNotebook(name, text, description, hidden, indent, in_ext, in_repr); + param = new ParamNotebook(in_repr, in_ext); } else if (!strcmp(type, "optiongroup")) { - if (appearance && !strcmp(appearance, "minimal")) { - param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); - } else { - param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); - } + param = new ParamOptionGroup(in_repr, in_ext); + } else if (!strcmp(type, "enum")) { // support deprecated "enum" for backwards-compatibilty + in_repr->setAttribute("appearance", "combo"); + param = new ParamOptionGroup(in_repr, in_ext); } else if (!strcmp(type, "color")) { - param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); + param = new ParamColor(in_repr, in_ext); + } else { + g_warning("Unknown parameter type ('%s') in extension '%s'", type, in_ext->get_id()); } - // Note: param could equal NULL + // Note: param could equal nullptr return param; } @@ -185,40 +102,31 @@ float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *nod return floatpntr->get(doc, node); } -gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const +const char *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamString const *stringpntr = dynamic_cast(this); if (!stringpntr) { throw param_not_string_param(); } - return stringpntr->get(doc, node); + return stringpntr->get(doc, node).c_str(); } -gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const +const char *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamComboBox const *param = dynamic_cast(this); + ParamOptionGroup const *param = dynamic_cast(this); if (!param) { - throw param_not_enum_param(); - } - return param->get(doc, node); -} - -bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamComboBox const *param = dynamic_cast(this); - if (!param) { - throw param_not_enum_param(); + throw param_not_optiongroup_param(); } - return param->contains(value, doc, node); + return param->get(doc, node).c_str(); } -gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const +bool Parameter::get_optiongroup_contains(const char *value, SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamRadioButton const *param = dynamic_cast(this); + ParamOptionGroup const *param = dynamic_cast(this); if (!param) { throw param_not_optiongroup_param(); } - return param->get(doc, node); + return param->contains(value, doc, node); } guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const @@ -230,7 +138,7 @@ guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *n return param->get(doc, node); } -bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) +bool Parameter::set_bool(bool in, SPDocument *doc, Inkscape::XML::Node *node) { ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == nullptr) @@ -238,17 +146,15 @@ bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) return boolpntr->set(in, doc, node); } -int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) +int Parameter::set_int(int in, SPDocument *doc, Inkscape::XML::Node *node) { - ParamInt * intpntr = dynamic_cast(this); + ParamInt *intpntr = dynamic_cast(this); if (intpntr == nullptr) throw param_not_int_param(); return intpntr->set(in, doc, node); } -/** Wrapper to cast to the object and use it's function. */ -float -Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) +float Parameter::set_float(float in, SPDocument *doc, Inkscape::XML::Node *node) { ParamFloat * floatpntr; floatpntr = dynamic_cast(this); @@ -257,48 +163,33 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) return floatpntr->set(in, doc, node); } -/** Wrapper to cast to the object and use it's function. */ -gchar const * -Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * node) +const char *Parameter::set_string(const char *in, SPDocument *doc, Inkscape::XML::Node *node) { ParamString * stringpntr = dynamic_cast(this); if (stringpntr == nullptr) throw param_not_string_param(); - return stringpntr->set(in, doc, node); + return stringpntr->set(in, doc, node).c_str(); } -gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +const char *Parameter::set_optiongroup(const char *in, SPDocument *doc, Inkscape::XML::Node *node) { - ParamRadioButton *param = dynamic_cast(this); + ParamOptionGroup *param = dynamic_cast(this); if (!param) { throw param_not_optiongroup_param(); } - return param->set(in, doc, node); + return param->set(in, doc, node).c_str(); } -gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +guint32 Parameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *node) { - ParamComboBox *param = dynamic_cast(this); - if (!param) { - throw param_not_enum_param(); - } - return param->set(in, doc, node); -} - - -/** Wrapper to cast to the object and use it's function. */ -guint32 -Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamColor* param = dynamic_cast(this); + ParamColor*param = dynamic_cast(this); if (param == nullptr) throw param_not_color_param(); return param->set(in, doc, node); } -/** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : +Parameter::Parameter(gchar const *name, gchar const *text, gchar const *description, bool hidden, int indent, Inkscape::Extension::Extension *ext) : _description(nullptr), _text(nullptr), _hidden(hidden), @@ -323,8 +214,7 @@ Parameter::Parameter(gchar const * name, gchar const * text, gchar const * descr return; } -/** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : +Parameter::Parameter (gchar const *name, gchar const *text, Inkscape::Extension::Extension *ext) : _description(nullptr), _text(nullptr), _hidden(false), @@ -344,6 +234,92 @@ Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extensio return; } +Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) + : _extension(ext) +{ + // name (mandatory for all paramters) + const char *name = in_repr->attribute("name"); + if (!name) { + throw param_no_name(); + } + _name = g_strdup(name); + + + // translatable (optional, required to translate gui-text and gui-description) + const char *translatable = in_repr->attribute("translatable"); + if (translatable) { + if (!strcmp(translatable, "yes")) { + _translatable = YES; + } else if (!strcmp(translatable, "no")) { + _translatable = NO; + } else { + g_warning("Invalid value ('%s') for translatable attribute of parameter '%s' in extension '%s'", + translatable, _name, _extension->get_id()); + } + } + + // context (optional, required to translate gui-text and gui-description) + const char *context = in_repr->attribute("context"); + if (!context) { + context = in_repr->attribute("msgctxt"); // backwards-compatibility with previous name + } + if (context) { + _context = g_strdup(context); + } + + // gui-text (TODO: should likely be mandatory for all parameters; maybe not for hidden ones?) + const char *gui_text = in_repr->attribute("gui-text"); + if (!gui_text) { + gui_text = in_repr->attribute("_gui-text"); // backwards-compatibility with underscored variants + } + if (gui_text) { + if (_translatable != NO) { // translate unless explicitly marked untranslatable + if (_context) { + gui_text = g_dpgettext2(nullptr, context, gui_text); + } else { + gui_text = _(gui_text); + } + } + _text = g_strdup(gui_text); + } + + // gui-description (optional) + const char *gui_description = in_repr->attribute("gui-description"); + if (!gui_description) { + gui_description = in_repr->attribute("_gui-description"); // backwards-compatibility with underscored variants + } + if (gui_description) { + if (_translatable != NO) { // translate unless explicitly marked untranslatable + if (_context) { + gui_description = g_dpgettext2(nullptr, context, gui_description); + } else { + gui_description = _(gui_description); + } + } + _description = g_strdup(gui_description); + } + + // gui-hidden (optional) + const char *gui_hidden = in_repr->attribute("gui-hidden"); + if (gui_hidden != nullptr) { + if (strcmp(gui_hidden, "true") == 0) { + _hidden = true; + } + } + + // indent (optional) + const char *indent = in_repr->attribute("indent"); + if (indent != nullptr) { + _indent = strtol(indent, nullptr, 0); + } + + // appearance (optional, does not apply to all parameters) + const char *appearance = in_repr->attribute("appearance"); + if (appearance) { + _appearance = g_strdup(appearance); + } +} + Parameter::~Parameter() { g_free(_name); @@ -354,6 +330,12 @@ Parameter::~Parameter() g_free(_description); _description = nullptr; + + g_free(_appearance); + _description = nullptr; + + g_free(_context); + _context = nullptr; } gchar *Parameter::pref_name() const @@ -389,7 +371,7 @@ void Parameter::string(std::list &list) const } } -Parameter *Parameter::get_param(gchar const * /*name*/) +Parameter *Parameter::get_param(const gchar */*name*/) { return nullptr; } -- cgit v1.2.3 From 532f3ff22891bd8d0710df5eb8e75f4d6d701d50 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Thu, 1 Aug 2019 20:47:35 +0200 Subject: Parameter: remove unused constructors --- src/extension/prefdialog/parameter.cpp | 45 ---------------------------------- 1 file changed, 45 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index d3293a0db..2bf83f359 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -189,51 +189,6 @@ guint32 Parameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *n } -Parameter::Parameter(gchar const *name, gchar const *text, gchar const *description, bool hidden, int indent, Inkscape::Extension::Extension *ext) : - _description(nullptr), - _text(nullptr), - _hidden(hidden), - _indent(indent), - _extension(ext), - _name(nullptr) -{ - if (name != nullptr) { - _name = g_strdup(name); - } - - if (description != nullptr) { - _description = g_strdup(description); - } - - if (text != nullptr) { - _text = g_strdup(text); - } else { - _text = g_strdup(name); - } - - return; -} - -Parameter::Parameter (gchar const *name, gchar const *text, Inkscape::Extension::Extension *ext) : - _description(nullptr), - _text(nullptr), - _hidden(false), - _indent(0), - _extension(ext), - _name(nullptr) -{ - if (name != nullptr) { - _name = g_strdup(name); - } - if (text != nullptr) { - _text = g_strdup(text); - } else { - _text = g_strdup(name); - } - - return; -} - Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) : _extension(ext) { -- cgit v1.2.3 From 62f20457cf5ee85ac42dcd24b564ea68c1b3441d Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Thu, 1 Aug 2019 22:15:48 +0200 Subject: Add function to get proper translation within context of Parameter --- src/extension/prefdialog/parameter.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 2bf83f359..18d2a40ec 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -229,11 +229,7 @@ Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extensi } if (gui_text) { if (_translatable != NO) { // translate unless explicitly marked untranslatable - if (_context) { - gui_text = g_dpgettext2(nullptr, context, gui_text); - } else { - gui_text = _(gui_text); - } + gui_text = get_translation(gui_text); } _text = g_strdup(gui_text); } @@ -245,11 +241,7 @@ Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extensi } if (gui_description) { if (_translatable != NO) { // translate unless explicitly marked untranslatable - if (_context) { - gui_description = g_dpgettext2(nullptr, context, gui_description); - } else { - gui_description = _(gui_description); - } + gui_description = get_translation(gui_description); } _description = g_strdup(gui_description); } @@ -331,6 +323,17 @@ Parameter *Parameter::get_param(const gchar */*name*/) return nullptr; } + +const char *Parameter::get_translation(const char* msgid) { + // TODO: translation domain + + if (_context) { + return g_dpgettext2(nullptr, _context, msgid); + } else { + return _(msgid); + } +} + Glib::ustring const extension_pref_root = "/extensions/"; } // namespace Extension -- cgit v1.2.3 From ea05ba3338bec1517826614f27935a36c3b0f0f8 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 4 Aug 2019 01:34:27 +0200 Subject: Implement "translationdomain" attribute for extensions Will allow extensions to ship their own message catalog used for translation of the extension#s strings. Needs to be set on the root element of the .inx Currently supported values: - unset: use default textdomain (which happens to be 'inkscape') - 'inkscape': use Inkscape's message catalog - 'none': disable translation for the extension's strings --- src/extension/prefdialog/parameter.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 18d2a40ec..5716a3be8 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -325,13 +325,7 @@ Parameter *Parameter::get_param(const gchar */*name*/) const char *Parameter::get_translation(const char* msgid) { - // TODO: translation domain - - if (_context) { - return g_dpgettext2(nullptr, _context, msgid); - } else { - return _(msgid); - } + return _extension->get_translation(msgid, _context); } Glib::ustring const extension_pref_root = "/extensions/"; -- cgit v1.2.3 From 33c31cdcdb285b20ed0286f2ec6f87e39d666666 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 4 Aug 2019 20:21:06 +0200 Subject: Create new InxWidget base class for extension widgets. --- src/extension/prefdialog/parameter.cpp | 64 ++-------------------------------- 1 file changed, 2 insertions(+), 62 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 5716a3be8..c60928752 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -27,6 +27,7 @@ #include "parameter-notebook.h" #include "parameter-optiongroup.h" #include "parameter-string.h" +#include "widget.h" #include "extension/extension.h" @@ -190,7 +191,7 @@ guint32 Parameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *n Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) - : _extension(ext) + : InxWidget(in_repr, ext) { // name (mandatory for all paramters) const char *name = in_repr->attribute("name"); @@ -199,29 +200,6 @@ Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extensi } _name = g_strdup(name); - - // translatable (optional, required to translate gui-text and gui-description) - const char *translatable = in_repr->attribute("translatable"); - if (translatable) { - if (!strcmp(translatable, "yes")) { - _translatable = YES; - } else if (!strcmp(translatable, "no")) { - _translatable = NO; - } else { - g_warning("Invalid value ('%s') for translatable attribute of parameter '%s' in extension '%s'", - translatable, _name, _extension->get_id()); - } - } - - // context (optional, required to translate gui-text and gui-description) - const char *context = in_repr->attribute("context"); - if (!context) { - context = in_repr->attribute("msgctxt"); // backwards-compatibility with previous name - } - if (context) { - _context = g_strdup(context); - } - // gui-text (TODO: should likely be mandatory for all parameters; maybe not for hidden ones?) const char *gui_text = in_repr->attribute("gui-text"); if (!gui_text) { @@ -245,26 +223,6 @@ Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extensi } _description = g_strdup(gui_description); } - - // gui-hidden (optional) - const char *gui_hidden = in_repr->attribute("gui-hidden"); - if (gui_hidden != nullptr) { - if (strcmp(gui_hidden, "true") == 0) { - _hidden = true; - } - } - - // indent (optional) - const char *indent = in_repr->attribute("indent"); - if (indent != nullptr) { - _indent = strtol(indent, nullptr, 0); - } - - // appearance (optional, does not apply to all parameters) - const char *appearance = in_repr->attribute("appearance"); - if (appearance) { - _appearance = g_strdup(appearance); - } } Parameter::~Parameter() @@ -277,12 +235,6 @@ Parameter::~Parameter() g_free(_description); _description = nullptr; - - g_free(_appearance); - _description = nullptr; - - g_free(_context); - _context = nullptr; } gchar *Parameter::pref_name() const @@ -290,13 +242,6 @@ gchar *Parameter::pref_name() const return g_strdup_printf("%s.%s", _extension->get_id(), _name); } -/** Basically, if there is no widget pass a NULL. */ -Gtk::Widget * -Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) -{ - return nullptr; -} - /** If I'm not sure which it is, just don't return a value. */ void Parameter::string(std::string &/*string*/) const { @@ -323,11 +268,6 @@ Parameter *Parameter::get_param(const gchar */*name*/) return nullptr; } - -const char *Parameter::get_translation(const char* msgid) { - return _extension->get_translation(msgid, _context); -} - Glib::ustring const extension_pref_root = "/extensions/"; } // namespace Extension -- cgit v1.2.3 From 3329abac70b6326839349c6438664dbc2a4a5548 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 4 Aug 2019 21:31:05 +0200 Subject: Rename Parameter -> InxParameter for consistency --- src/extension/prefdialog/parameter.cpp | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index c60928752..6a9c744b3 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -41,9 +41,9 @@ namespace Inkscape { namespace Extension { -Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) +InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) { - Parameter *param = nullptr; + InxParameter *param = nullptr; const char *type = in_repr->attribute("type"); if (!type) { @@ -76,7 +76,7 @@ Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex return param; } -bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const +bool InxParameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamBool const *boolpntr = dynamic_cast(this); if (!boolpntr) { @@ -85,7 +85,7 @@ bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) return boolpntr->get(doc, node); } -int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const +int InxParameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamInt const *intpntr = dynamic_cast(this); if (!intpntr) { @@ -94,7 +94,7 @@ int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) c return intpntr->get(doc, node); } -float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const +float InxParameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamFloat const *floatpntr = dynamic_cast(this); if (!floatpntr) { @@ -103,7 +103,7 @@ float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *nod return floatpntr->get(doc, node); } -const char *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const +const char *InxParameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamString const *stringpntr = dynamic_cast(this); if (!stringpntr) { @@ -112,7 +112,7 @@ const char *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node con return stringpntr->get(doc, node).c_str(); } -const char *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const *node) const +const char *InxParameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamOptionGroup const *param = dynamic_cast(this); if (!param) { @@ -121,7 +121,7 @@ const char *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Nod return param->get(doc, node).c_str(); } -bool Parameter::get_optiongroup_contains(const char *value, SPDocument const *doc, Inkscape::XML::Node const *node) const +bool InxParameter::get_optiongroup_contains(const char *value, SPDocument const *doc, Inkscape::XML::Node const *node) const { ParamOptionGroup const *param = dynamic_cast(this); if (!param) { @@ -130,7 +130,7 @@ bool Parameter::get_optiongroup_contains(const char *value, SPDocument const *do return param->contains(value, doc, node); } -guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const +guint32 InxParameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const { ParamColor const *param = dynamic_cast(this); if (!param) { @@ -139,7 +139,7 @@ guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *n return param->get(doc, node); } -bool Parameter::set_bool(bool in, SPDocument *doc, Inkscape::XML::Node *node) +bool InxParameter::set_bool(bool in, SPDocument *doc, Inkscape::XML::Node *node) { ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == nullptr) @@ -147,7 +147,7 @@ bool Parameter::set_bool(bool in, SPDocument *doc, Inkscape::XML::Node *node) return boolpntr->set(in, doc, node); } -int Parameter::set_int(int in, SPDocument *doc, Inkscape::XML::Node *node) +int InxParameter::set_int(int in, SPDocument *doc, Inkscape::XML::Node *node) { ParamInt *intpntr = dynamic_cast(this); if (intpntr == nullptr) @@ -155,7 +155,7 @@ int Parameter::set_int(int in, SPDocument *doc, Inkscape::XML::Node *node) return intpntr->set(in, doc, node); } -float Parameter::set_float(float in, SPDocument *doc, Inkscape::XML::Node *node) +float InxParameter::set_float(float in, SPDocument *doc, Inkscape::XML::Node *node) { ParamFloat * floatpntr; floatpntr = dynamic_cast(this); @@ -164,7 +164,7 @@ float Parameter::set_float(float in, SPDocument *doc, Inkscape::XML::Node *node) return floatpntr->set(in, doc, node); } -const char *Parameter::set_string(const char *in, SPDocument *doc, Inkscape::XML::Node *node) +const char *InxParameter::set_string(const char *in, SPDocument *doc, Inkscape::XML::Node *node) { ParamString * stringpntr = dynamic_cast(this); if (stringpntr == nullptr) @@ -172,7 +172,7 @@ const char *Parameter::set_string(const char *in, SPDocument *doc, Inkscape::XML return stringpntr->set(in, doc, node).c_str(); } -const char *Parameter::set_optiongroup(const char *in, SPDocument *doc, Inkscape::XML::Node *node) +const char *InxParameter::set_optiongroup(const char *in, SPDocument *doc, Inkscape::XML::Node *node) { ParamOptionGroup *param = dynamic_cast(this); if (!param) { @@ -181,7 +181,7 @@ const char *Parameter::set_optiongroup(const char *in, SPDocument *doc, Inkscape return param->set(in, doc, node).c_str(); } -guint32 Parameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *node) +guint32 InxParameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *node) { ParamColor*param = dynamic_cast(this); if (param == nullptr) @@ -190,7 +190,7 @@ guint32 Parameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *n } -Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) +InxParameter::InxParameter(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) : InxWidget(in_repr, ext) { // name (mandatory for all paramters) @@ -225,7 +225,7 @@ Parameter::Parameter (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extensi } } -Parameter::~Parameter() +InxParameter::~InxParameter() { g_free(_name); _name = nullptr; @@ -237,18 +237,18 @@ Parameter::~Parameter() _description = nullptr; } -gchar *Parameter::pref_name() const +gchar *InxParameter::pref_name() const { return g_strdup_printf("%s.%s", _extension->get_id(), _name); } /** If I'm not sure which it is, just don't return a value. */ -void Parameter::string(std::string &/*string*/) const +void InxParameter::string(std::string &/*string*/) const { // TODO investigate clearing the target string. } -void Parameter::string(std::list &list) const +void InxParameter::string(std::list &list) const { std::string value; string(value); @@ -263,7 +263,7 @@ void Parameter::string(std::list &list) const } } -Parameter *Parameter::get_param(const gchar */*name*/) +InxParameter *InxParameter::get_param(const gchar */*name*/) { return nullptr; } -- cgit v1.2.3 From 9185b26e396867391d92e4ab6edf933eec77db3a Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 4 Aug 2019 22:40:14 +0200 Subject: Add WidgetLabel replacing the former ParamDescription This improves consistency, as "description" parameter were not actually parameters with a value that could be modified or saved. The old syntax is deprecated but still supported for now. --- src/extension/prefdialog/parameter.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 6a9c744b3..9bb87f7a2 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -21,13 +21,13 @@ #include "parameter.h" #include "parameter-bool.h" #include "parameter-color.h" -#include "parameter-description.h" #include "parameter-float.h" #include "parameter-int.h" #include "parameter-notebook.h" #include "parameter-optiongroup.h" #include "parameter-string.h" #include "widget.h" +#include "widget-label.h" #include "extension/extension.h" @@ -41,6 +41,24 @@ namespace Inkscape { namespace Extension { + +// Re-implement ParamDescription for backwards-compatibility, deriving from both, WidgetLabel and InxParameter. +// TODO: Should go away eventually... +class ParamDescription : public virtual WidgetLabel, public virtual InxParameter { +public: + ParamDescription(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : WidgetLabel(xml, ext) + , InxParameter(xml, ext) + {} + + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override + { + return this->WidgetLabel::get_widget(doc, node, changeSignal); + } +}; + + + InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) { InxParameter *param = nullptr; @@ -58,12 +76,13 @@ InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extensi } else if (!strcmp(type, "string")) { param = new ParamString(in_repr, in_ext); } else if (!strcmp(type, "description")) { + // support deprecated "description" for backwards-compatibility param = new ParamDescription(in_repr, in_ext); } else if (!strcmp(type, "notebook")) { param = new ParamNotebook(in_repr, in_ext); } else if (!strcmp(type, "optiongroup")) { param = new ParamOptionGroup(in_repr, in_ext); - } else if (!strcmp(type, "enum")) { // support deprecated "enum" for backwards-compatibilty + } else if (!strcmp(type, "enum")) { // support deprecated "enum" for backwards-compatibility in_repr->setAttribute("appearance", "combo"); param = new ParamOptionGroup(in_repr, in_ext); } else if (!strcmp(type, "color")) { -- cgit v1.2.3 From 299010c5b11801fa49bd52ae78c6d2cc0e069137 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Mon, 5 Aug 2019 22:13:24 +0200 Subject: More cleanup --- src/extension/prefdialog/parameter.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 9bb87f7a2..61cf8c662 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -55,6 +55,9 @@ public: { return this->WidgetLabel::get_widget(doc, node, changeSignal); } + + // Well, no, I don't have a value! That's why I should not be an InxParameter! + void string(std::string &/*string*/) const override {} }; @@ -149,7 +152,7 @@ bool InxParameter::get_optiongroup_contains(const char *value, SPDocument const return param->contains(value, doc, node); } -guint32 InxParameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const +unsigned int InxParameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const { ParamColor const *param = dynamic_cast(this); if (!param) { @@ -200,7 +203,7 @@ const char *InxParameter::set_optiongroup(const char *in, SPDocument *doc, Inksc return param->set(in, doc, node).c_str(); } -guint32 InxParameter::set_color(guint32 in, SPDocument *doc, Inkscape::XML::Node *node) +unsigned int InxParameter::set_color(unsigned int in, SPDocument *doc, Inkscape::XML::Node *node) { ParamColor*param = dynamic_cast(this); if (param == nullptr) @@ -256,15 +259,16 @@ InxParameter::~InxParameter() _description = nullptr; } -gchar *InxParameter::pref_name() const +char *InxParameter::pref_name() const { return g_strdup_printf("%s.%s", _extension->get_id(), _name); } -/** If I'm not sure which it is, just don't return a value. */ void InxParameter::string(std::string &/*string*/) const { - // TODO investigate clearing the target string. + // if we end up here we're missing a definition of ::string() in one of the subclasses + g_critical("InxParameter::string called from parameter '%s' in extension '%s'", _name, _extension->get_id()); + g_assert_not_reached(); } void InxParameter::string(std::list &list) const @@ -282,12 +286,13 @@ void InxParameter::string(std::list &list) const } } -InxParameter *InxParameter::get_param(const gchar */*name*/) + +InxParameter *InxParameter::get_param(const char */*name*/) { return nullptr; } -Glib::ustring const extension_pref_root = "/extensions/"; +const Glib::ustring InxParameter::extension_pref_root = "/extensions/"; } // namespace Extension } // namespace Inkscape -- cgit v1.2.3 From 26d8a32b7395d7bf1d1da7c32b9f2cdf5770510a Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Tue, 6 Aug 2019 00:11:54 +0200 Subject: Optimize parameter string generation Also rename overloaded string() functions, so it's clear what they actually do, as it's not the same thing at all... --- src/extension/prefdialog/parameter.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 61cf8c662..3f8f30c60 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -57,7 +57,7 @@ public: } // Well, no, I don't have a value! That's why I should not be an InxParameter! - void string(std::string &/*string*/) const override {} + std::string value_to_string() const override { return ""; } }; @@ -264,25 +264,25 @@ char *InxParameter::pref_name() const return g_strdup_printf("%s.%s", _extension->get_id(), _name); } -void InxParameter::string(std::string &/*string*/) const +std::string InxParameter::value_to_string() const { // if we end up here we're missing a definition of ::string() in one of the subclasses - g_critical("InxParameter::string called from parameter '%s' in extension '%s'", _name, _extension->get_id()); + g_critical("InxParameter::value_to_string called from parameter '%s' in extension '%s'", _name, _extension->get_id()); g_assert_not_reached(); + return ""; } -void InxParameter::string(std::list &list) const +void InxParameter::build_param_string_list(std::list &list) const { - std::string value; - string(value); - if (!value.empty()) { - std::string final; - final += "--"; - final += name(); - final += "="; - final += value; - - list.insert(list.end(), final); + std::string value_string = value_to_string(); + if (!value_string.empty()) { + std::string parameter_string; // --param=value + parameter_string += "--"; + parameter_string += name(); + parameter_string += "="; + parameter_string += value_string; + + list.insert(list.end(), parameter_string); } } -- cgit v1.2.3 From c9833638d92157b40d12e02eb934aafe5f4ad589 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Tue, 6 Aug 2019 22:29:02 +0200 Subject: Accept parameter type "bool" Seems more consistent with "int" and "float" types and should likely be preferred over the old "boolean" --- src/extension/prefdialog/parameter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 3f8f30c60..8618f434b 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -70,7 +70,7 @@ InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extensi if (!type) { // we can't create a parameter without type g_warning("Parameter without type in extension '%s'.", in_ext->get_id()); - } else if(!strcmp(type, "boolean")) { + } else if(!strcmp(type, "bool") || !strcmp(type, "boolean")) { // support "boolean" for backwards-compatibility param = new ParamBool(in_repr, in_ext); } else if (!strcmp(type, "int")) { param = new ParamInt(in_repr, in_ext); -- cgit v1.2.3 From 2bdffba8f4da0fe64d4a5b85096d057d389abef8 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Tue, 6 Aug 2019 22:30:54 +0200 Subject: Make parameter string generation a job of Inkscape::Extension For this take a first step towards properly tracking children of each parameter and provide functions to look up all widgets. --- src/extension/prefdialog/parameter.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 8618f434b..7d8751353 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -272,21 +272,6 @@ std::string InxParameter::value_to_string() const return ""; } -void InxParameter::build_param_string_list(std::list &list) const -{ - std::string value_string = value_to_string(); - if (!value_string.empty()) { - std::string parameter_string; // --param=value - parameter_string += "--"; - parameter_string += name(); - parameter_string += "="; - parameter_string += value_string; - - list.insert(list.end(), parameter_string); - } -} - - InxParameter *InxParameter::get_param(const char */*name*/) { return nullptr; -- cgit v1.2.3 From c0317efc1e86f75ee72d6f65b978bfe634bd3b2c Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Wed, 7 Aug 2019 02:28:50 +0200 Subject: Re-implement get_param() locally using get_widgets() --- src/extension/prefdialog/parameter.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 7d8751353..d0e284ea7 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -272,11 +272,6 @@ std::string InxParameter::value_to_string() const return ""; } -InxParameter *InxParameter::get_param(const char */*name*/) -{ - return nullptr; -} - const Glib::ustring InxParameter::extension_pref_root = "/extensions/"; } // namespace Extension -- cgit v1.2.3 From c5233cd683c7df4a31eb68634e8876ca900b9676 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Wed, 7 Aug 2019 23:47:00 +0200 Subject: Remove completely unused "doc" and "node" parameters --- src/extension/prefdialog/parameter.cpp | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index d0e284ea7..4c104573a 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -51,9 +51,9 @@ public: , InxParameter(xml, ext) {} - Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override + Gtk::Widget *get_widget(sigc::signal *changeSignal) override { - return this->WidgetLabel::get_widget(doc, node, changeSignal); + return this->WidgetLabel::get_widget(changeSignal); } // Well, no, I don't have a value! That's why I should not be an InxParameter! @@ -98,117 +98,117 @@ InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extensi return param; } -bool InxParameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const +bool InxParameter::get_bool() const { ParamBool const *boolpntr = dynamic_cast(this); if (!boolpntr) { throw param_not_bool_param(); } - return boolpntr->get(doc, node); + return boolpntr->get(); } -int InxParameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const +int InxParameter::get_int() const { ParamInt const *intpntr = dynamic_cast(this); if (!intpntr) { throw param_not_int_param(); } - return intpntr->get(doc, node); + return intpntr->get(); } -float InxParameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const +float InxParameter::get_float() const { ParamFloat const *floatpntr = dynamic_cast(this); if (!floatpntr) { throw param_not_float_param(); } - return floatpntr->get(doc, node); + return floatpntr->get(); } -const char *InxParameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const +const char *InxParameter::get_string() const { ParamString const *stringpntr = dynamic_cast(this); if (!stringpntr) { throw param_not_string_param(); } - return stringpntr->get(doc, node).c_str(); + return stringpntr->get().c_str(); } -const char *InxParameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const *node) const +const char *InxParameter::get_optiongroup() const { ParamOptionGroup const *param = dynamic_cast(this); if (!param) { throw param_not_optiongroup_param(); } - return param->get(doc, node).c_str(); + return param->get().c_str(); } -bool InxParameter::get_optiongroup_contains(const char *value, SPDocument const *doc, Inkscape::XML::Node const *node) const +bool InxParameter::get_optiongroup_contains(const char *value) const { ParamOptionGroup const *param = dynamic_cast(this); if (!param) { throw param_not_optiongroup_param(); } - return param->contains(value, doc, node); + return param->contains(value); } -unsigned int InxParameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const +unsigned int InxParameter::get_color() const { ParamColor const *param = dynamic_cast(this); if (!param) { throw param_not_color_param(); } - return param->get(doc, node); + return param->get(); } -bool InxParameter::set_bool(bool in, SPDocument *doc, Inkscape::XML::Node *node) +bool InxParameter::set_bool(bool in) { ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == nullptr) throw param_not_bool_param(); - return boolpntr->set(in, doc, node); + return boolpntr->set(in); } -int InxParameter::set_int(int in, SPDocument *doc, Inkscape::XML::Node *node) +int InxParameter::set_int(int in) { ParamInt *intpntr = dynamic_cast(this); if (intpntr == nullptr) throw param_not_int_param(); - return intpntr->set(in, doc, node); + return intpntr->set(in); } -float InxParameter::set_float(float in, SPDocument *doc, Inkscape::XML::Node *node) +float InxParameter::set_float(float in) { ParamFloat * floatpntr; floatpntr = dynamic_cast(this); if (floatpntr == nullptr) throw param_not_float_param(); - return floatpntr->set(in, doc, node); + return floatpntr->set(in); } -const char *InxParameter::set_string(const char *in, SPDocument *doc, Inkscape::XML::Node *node) +const char *InxParameter::set_string(const char *in) { ParamString * stringpntr = dynamic_cast(this); if (stringpntr == nullptr) throw param_not_string_param(); - return stringpntr->set(in, doc, node).c_str(); + return stringpntr->set(in).c_str(); } -const char *InxParameter::set_optiongroup(const char *in, SPDocument *doc, Inkscape::XML::Node *node) +const char *InxParameter::set_optiongroup(const char *in) { ParamOptionGroup *param = dynamic_cast(this); if (!param) { throw param_not_optiongroup_param(); } - return param->set(in, doc, node).c_str(); + return param->set(in).c_str(); } -unsigned int InxParameter::set_color(unsigned int in, SPDocument *doc, Inkscape::XML::Node *node) +unsigned int InxParameter::set_color(unsigned int in) { ParamColor*param = dynamic_cast(this); if (param == nullptr) throw param_not_color_param(); - return param->set(in, doc, node); + return param->set(in); } -- cgit v1.2.3 From 37e5d6dc66d7b98ce6716398f81eb5b0a89bded2 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Thu, 8 Aug 2019 00:50:41 +0200 Subject: Simplify pref_name() function --- src/extension/prefdialog/parameter.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 4c104573a..46e101ad1 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -259,9 +259,9 @@ InxParameter::~InxParameter() _description = nullptr; } -char *InxParameter::pref_name() const +Glib::ustring InxParameter::pref_name() const { - return g_strdup_printf("%s.%s", _extension->get_id(), _name); + return Glib::ustring::compose("/extensions/%1.%2", _extension->get_id(), _name); } std::string InxParameter::value_to_string() const @@ -272,8 +272,6 @@ std::string InxParameter::value_to_string() const return ""; } -const Glib::ustring InxParameter::extension_pref_root = "/extensions/"; - } // namespace Extension } // namespace Inkscape -- cgit v1.2.3 From bc25884ffbfc3eeba047fe49c0560083deee8ad8 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Mon, 12 Aug 2019 18:10:42 +0200 Subject: Make 'gui-text' required for visible parameters We were actually crashing for visible parameters without 'gui-text' otherwise. Also make sure we actually *do* bail out if we have parameters missing required fields and throw/catch an exception instead of producing broken instances. --- src/extension/prefdialog/parameter.cpp | 66 ++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 46e101ad1..4519f8b5d 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -66,32 +66,38 @@ InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extensi { InxParameter *param = nullptr; - const char *type = in_repr->attribute("type"); - if (!type) { - // we can't create a parameter without type - g_warning("Parameter without type in extension '%s'.", in_ext->get_id()); - } else if(!strcmp(type, "bool") || !strcmp(type, "boolean")) { // support "boolean" for backwards-compatibility - param = new ParamBool(in_repr, in_ext); - } else if (!strcmp(type, "int")) { - param = new ParamInt(in_repr, in_ext); - } else if (!strcmp(type, "float")) { - param = new ParamFloat(in_repr, in_ext); - } else if (!strcmp(type, "string")) { - param = new ParamString(in_repr, in_ext); - } else if (!strcmp(type, "description")) { - // support deprecated "description" for backwards-compatibility - param = new ParamDescription(in_repr, in_ext); - } else if (!strcmp(type, "notebook")) { - param = new ParamNotebook(in_repr, in_ext); - } else if (!strcmp(type, "optiongroup")) { - param = new ParamOptionGroup(in_repr, in_ext); - } else if (!strcmp(type, "enum")) { // support deprecated "enum" for backwards-compatibility - in_repr->setAttribute("appearance", "combo"); - param = new ParamOptionGroup(in_repr, in_ext); - } else if (!strcmp(type, "color")) { - param = new ParamColor(in_repr, in_ext); - } else { - g_warning("Unknown parameter type ('%s') in extension '%s'", type, in_ext->get_id()); + try { + const char *type = in_repr->attribute("type"); + if (!type) { + // we can't create a parameter without type + g_warning("Parameter without type in extension '%s'.", in_ext->get_id()); + } else if(!strcmp(type, "bool") || !strcmp(type, "boolean")) { // support "boolean" for backwards-compatibility + param = new ParamBool(in_repr, in_ext); + } else if (!strcmp(type, "int")) { + param = new ParamInt(in_repr, in_ext); + } else if (!strcmp(type, "float")) { + param = new ParamFloat(in_repr, in_ext); + } else if (!strcmp(type, "string")) { + param = new ParamString(in_repr, in_ext); + } else if (!strcmp(type, "description")) { + // support deprecated "description" for backwards-compatibility + in_repr->setAttribute("gui-text", "description"); // TODO: hack to allow descriptions to be parameters + param = new ParamDescription(in_repr, in_ext); + } else if (!strcmp(type, "notebook")) { + in_repr->setAttribute("gui-text", "notebook"); // notebooks have no 'gui-text' (but Parameters need one) + param = new ParamNotebook(in_repr, in_ext); + } else if (!strcmp(type, "optiongroup")) { + param = new ParamOptionGroup(in_repr, in_ext); + } else if (!strcmp(type, "enum")) { // support deprecated "enum" for backwards-compatibility + in_repr->setAttribute("appearance", "combo"); + param = new ParamOptionGroup(in_repr, in_ext); + } else if (!strcmp(type, "color")) { + param = new ParamColor(in_repr, in_ext); + } else { + g_warning("Unknown parameter type ('%s') in extension '%s'", type, in_ext->get_id()); + } + } catch (const param_no_name&) { + } catch (const param_no_text&) { } // Note: param could equal nullptr @@ -218,11 +224,12 @@ InxParameter::InxParameter(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex // name (mandatory for all paramters) const char *name = in_repr->attribute("name"); if (!name) { + g_warning("Parameter without name in extension '%s'.", _extension->get_id()); throw param_no_name(); } _name = g_strdup(name); - // gui-text (TODO: should likely be mandatory for all parameters; maybe not for hidden ones?) + // gui-text const char *gui_text = in_repr->attribute("gui-text"); if (!gui_text) { gui_text = in_repr->attribute("_gui-text"); // backwards-compatibility with underscored variants @@ -233,6 +240,11 @@ InxParameter::InxParameter(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex } _text = g_strdup(gui_text); } + if (!_text && !_hidden) { + g_warning("Parameter '%s' in extension '%s' is visible but does not have a 'gui-text'.", + _name, _extension->get_id()); + throw param_no_text(); + } // gui-description (optional) const char *gui_description = in_repr->attribute("gui-description"); -- cgit v1.2.3 From 10845e6925978cd9cf5bc9d0961802e06c9b3799 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Mon, 12 Aug 2019 22:49:30 +0200 Subject: Add new parameter of type "path" * Similar to parameter's of type "string": Has a text entry and stores a string preference * Additionally offers a button to show a file chooser dialog * The node's content is the initial (default) file path. * Relative paths will be considered relative to the extension's .inx file. This allows to reference files/folders shipped with the extension in a portable way. The stored value as well as the parameter value passed to the script interpreter will always be absolute, though. * The attribute "mode" controls what type(s) of paths the file chooser allows to select. Valid values: - 'file', 'files', 'folder', 'folder' (pick existing items) - 'file_new', 'folder_new' (create a new file/folder) * Note that manually entered values will be passed as-is without checking for existence. --- src/extension/prefdialog/parameter.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/extension/prefdialog/parameter.cpp') diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 4519f8b5d..65072f6a8 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -25,6 +25,7 @@ #include "parameter-int.h" #include "parameter-notebook.h" #include "parameter-optiongroup.h" +#include "parameter-path.h" #include "parameter-string.h" #include "widget.h" #include "widget-label.h" @@ -79,6 +80,8 @@ InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extensi param = new ParamFloat(in_repr, in_ext); } else if (!strcmp(type, "string")) { param = new ParamString(in_repr, in_ext); + } else if (!strcmp(type, "path")) { + param = new ParamPath(in_repr, in_ext); } else if (!strcmp(type, "description")) { // support deprecated "description" for backwards-compatibility in_repr->setAttribute("gui-text", "description"); // TODO: hack to allow descriptions to be parameters -- cgit v1.2.3