diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-04 22:53:57 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-31 14:50:38 +0000 |
| commit | 40df9f6ef495c4577958502ffb4f23a4a4e1092f (patch) | |
| tree | c8d16021ba5a2305687b02cd62385f6889e8f01c /src/extension/prefdialog | |
| parent | Translatable enum can be protected (diff) | |
| download | inkscape-40df9f6ef495c4577958502ffb4f23a4a4e1092f.tar.gz inkscape-40df9f6ef495c4577958502ffb4f23a4a4e1092f.zip | |
Switch Inkscape::Extension to use InxWidgets instead of InxParameters
Diffstat (limited to 'src/extension/prefdialog')
| -rw-r--r-- | src/extension/prefdialog/parameter.h | 2 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget.cpp | 25 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget.h | 8 |
3 files changed, 34 insertions, 1 deletions
diff --git a/src/extension/prefdialog/parameter.h b/src/extension/prefdialog/parameter.h index 7db7b9a3f..c7e6acb86 100644 --- a/src/extension/prefdialog/parameter.h +++ b/src/extension/prefdialog/parameter.h @@ -108,7 +108,7 @@ public: */ static InxParameter *make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext); - const gchar *get_tooltip() const { return _description; } + const gchar *get_tooltip() const override { return _description; } virtual void string(std::list <std::string> &list) const; diff --git a/src/extension/prefdialog/widget.cpp b/src/extension/prefdialog/widget.cpp index 1297edb1c..ae85b9fbd 100644 --- a/src/extension/prefdialog/widget.cpp +++ b/src/extension/prefdialog/widget.cpp @@ -10,9 +10,12 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ +#include "parameter.h" #include "widget.h" #include "widget-label.h" +#include <algorithm> + #include <sigc++/sigc++.h> #include "extension/extension.h" @@ -28,11 +31,20 @@ InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex InxWidget *widget = nullptr; const char *name = in_repr->name(); + if (!strncmp(name, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { + name += strlen(INKSCAPE_EXTENSION_NS); + } + if (name[0] == '_') { // allow leading underscore in tag names for backwards-compatibility + name++; + } + if (!name) { // we can't create a widget without name g_warning("InxWidget without name in extension '%s'.", in_ext->get_id()); } else if (!strcmp(name, "description")) { widget = new WidgetLabel(in_repr, in_ext); + } else if (!strcmp(name, "param")) { + widget = InxParameter::make(in_repr, in_ext); } else { g_warning("Unknown widget name ('%s') in extension '%s'", name, in_ext->get_id()); } @@ -41,6 +53,19 @@ InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex return widget; } +bool InxWidget::is_valid_widget_name(const char *name) +{ + // keep in sync with names supported in InxWidget::make() above + static const std::vector<std::string> valid_names = {"description", "param"}; + + if (std::find(valid_names.begin(), valid_names.end(), name) != valid_names.end()) { + return true; + } else { + return false; + } +} + + InxWidget::InxWidget (Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) : _extension(ext) { diff --git a/src/extension/prefdialog/widget.h b/src/extension/prefdialog/widget.h index 31fe957f1..95285e2d6 100644 --- a/src/extension/prefdialog/widget.h +++ b/src/extension/prefdialog/widget.h @@ -14,6 +14,7 @@ #define SEEN_INK_EXTENSION_WIDGET_H #include <string> +#include <vector> #include <sigc++/sigc++.h> #include <glibmm/ustring.h> @@ -57,8 +58,14 @@ public: */ static InxWidget *make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext); + /** Checks if name is a valid widget name, i.e. a widget can be constructed from it using make() */ + static bool is_valid_widget_name(const char *name); + + virtual Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal); + virtual const gchar *get_tooltip() const { return nullptr; } // tool-tips are exclusive to InxParameters for now + /** Indicates if the widget is hidden or not */ bool get_hidden() const { return _hidden; } @@ -66,6 +73,7 @@ public: int get_indent() const { return _indent; } + /** Recommended margin of boxes containing multiple Widgets (in px) */ const static int GUI_BOX_MARGIN = 10; /** Recommended spacing between multiple Widgets packed into a box (in px) */ |
