summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/extension/prefdialog/parameter-notebook.h2
-rw-r--r--src/extension/prefdialog/parameter-optiongroup.cpp1
-rw-r--r--src/extension/prefdialog/parameter.cpp66
-rw-r--r--src/extension/prefdialog/parameter.h2
4 files changed, 41 insertions, 30 deletions
diff --git a/src/extension/prefdialog/parameter-notebook.h b/src/extension/prefdialog/parameter-notebook.h
index 7a76520d4..f5a313b49 100644
--- a/src/extension/prefdialog/parameter-notebook.h
+++ b/src/extension/prefdialog/parameter-notebook.h
@@ -52,8 +52,6 @@ private:
// ParamNotebookPage is not a real parameter (it has no value), so make sure it does not return one
std::string value_to_string() const override { return ""; };
-
- const char *get_text() { return _text; };
}; /* class ParamNotebookPage */
/** A table to store the pages with parameters for this notebook.
diff --git a/src/extension/prefdialog/parameter-optiongroup.cpp b/src/extension/prefdialog/parameter-optiongroup.cpp
index a1b3e0a52..e3f655dde 100644
--- a/src/extension/prefdialog/parameter-optiongroup.cpp
+++ b/src/extension/prefdialog/parameter-optiongroup.cpp
@@ -45,6 +45,7 @@ ParamOptionGroup::ParamOptionGroup(Inkscape::XML::Node *xml, Inkscape::Extension
!strcmp(chname, INKSCAPE_EXTENSION_NS "item") ||
!strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) ) {
child_repr->setAttribute("name", "option"); // TODO: hack to allow options to be parameters
+ child_repr->setAttribute("gui-text", "option"); // TODO: hack to allow options to be parameters
ParamOptionGroupOption *param = new ParamOptionGroupOption(child_repr, ext, this);
choices.push_back(param);
} else if (child_repr->type() == XML::ELEMENT_NODE) {
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");
diff --git a/src/extension/prefdialog/parameter.h b/src/extension/prefdialog/parameter.h
index a5f58c922..7776851dc 100644
--- a/src/extension/prefdialog/parameter.h
+++ b/src/extension/prefdialog/parameter.h
@@ -112,7 +112,7 @@ public:
/** An error class for when a parameter is called on a type it is not */
class param_no_name {};
- class param_no_type {};
+ class param_no_text {};
class param_not_bool_param {};
class param_not_color_param {};
class param_not_float_param {};