diff options
| author | Michael Soegtrop <MSoegtrop@yahoo.de> | 2017-06-05 13:01:17 +0000 |
|---|---|---|
| committer | Michael Soegtrop <MSoegtrop@yahoo.de> | 2017-06-05 13:01:17 +0000 |
| commit | e7248b2fa042f42a5c4dd14cd86ab6a5b4524059 (patch) | |
| tree | 9097520c54e355ded9bd0b4d6618af4e8dacdd91 /src/extension/param | |
| parent | updated to latest trunk (diff) | |
| parent | [Bug #1695016] Xaml export misses some radialGradients. (diff) | |
| download | inkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.tar.gz inkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.zip | |
updated to latest trunk
(bzr r14876.2.4)
Diffstat (limited to 'src/extension/param')
| -rw-r--r-- | src/extension/param/bool.cpp | 29 | ||||
| -rw-r--r-- | src/extension/param/bool.h | 9 | ||||
| -rw-r--r-- | src/extension/param/color.cpp | 18 | ||||
| -rw-r--r-- | src/extension/param/color.h | 9 | ||||
| -rw-r--r-- | src/extension/param/description.cpp | 116 | ||||
| -rw-r--r-- | src/extension/param/description.h | 14 | ||||
| -rw-r--r-- | src/extension/param/enum.cpp | 60 | ||||
| -rw-r--r-- | src/extension/param/enum.h | 14 | ||||
| -rw-r--r-- | src/extension/param/float.cpp | 51 | ||||
| -rw-r--r-- | src/extension/param/float.h | 19 | ||||
| -rw-r--r-- | src/extension/param/int.cpp | 51 | ||||
| -rw-r--r-- | src/extension/param/int.h | 18 | ||||
| -rw-r--r-- | src/extension/param/notebook.cpp | 107 | ||||
| -rw-r--r-- | src/extension/param/notebook.h | 9 | ||||
| -rw-r--r-- | src/extension/param/parameter.cpp | 154 | ||||
| -rw-r--r-- | src/extension/param/parameter.h | 62 | ||||
| -rw-r--r-- | src/extension/param/radiobutton.cpp | 67 | ||||
| -rw-r--r-- | src/extension/param/radiobutton.h | 11 | ||||
| -rw-r--r-- | src/extension/param/string.cpp | 25 | ||||
| -rw-r--r-- | src/extension/param/string.h | 11 |
20 files changed, 446 insertions, 408 deletions
diff --git a/src/extension/param/bool.cpp b/src/extension/param/bool.cpp index d64f798ba..2c7e32480 100644 --- a/src/extension/param/bool.cpp +++ b/src/extension/param/bool.cpp @@ -23,9 +23,15 @@ namespace Inkscape { namespace Extension { -ParamBool::ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(false), _indent(0) +ParamBool::ParamBool(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml) + : Parameter(name, text, description, hidden, indent, ext) + , _value(false) { const char * defaultval = NULL; if (xml->firstChild() != NULL) { @@ -38,11 +44,6 @@ ParamBool::ParamBool(const gchar * name, const gchar * guitext, const gchar * de _value = false; } - const char * indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; - } - gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getBool(extension_pref_root + pref_name, _value); @@ -65,7 +66,7 @@ bool ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node bool ParamBool::get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { - return _value; + return _value; } /** @@ -125,16 +126,12 @@ void ParamBool::string(std::string &string) const Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } -#if WITH_GTKMM_3_0 - Gtk::Box * hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 4)); + auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); hbox->set_homogeneous(false); -#else - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); -#endif Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); @@ -142,7 +139,7 @@ Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, ParamBoolCheckButton * checkbox = Gtk::manage(new ParamBoolCheckButton(this, doc, node, changeSignal)); checkbox->show(); - hbox->pack_start(*checkbox, false, false, _indent); + hbox->pack_start(*checkbox, false, false); hbox->show(); diff --git a/src/extension/param/bool.h b/src/extension/param/bool.h index 5d190b9d3..826a98927 100644 --- a/src/extension/param/bool.h +++ b/src/extension/param/bool.h @@ -32,7 +32,13 @@ public: /** * Use the superclass' allocator and set the \c _value. */ - ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ParamBool(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); /** * Returns the current state/value. @@ -69,7 +75,6 @@ public: private: /** Internal value. */ bool _value; - int _indent; }; } // namespace Extension diff --git a/src/extension/param/color.cpp b/src/extension/param/color.cpp index 0b58c5011..035c43ba8 100644 --- a/src/extension/param/color.cpp +++ b/src/extension/param/color.cpp @@ -52,9 +52,15 @@ guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * return in; } -ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _changeSignal(0) +ParamColor::ParamColor(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml) + : Parameter(name, text, description, hidden, indent, ext) + , _changeSignal(0) { const char * defaulthex = NULL; if (xml->firstChild() != NULL) @@ -86,7 +92,7 @@ Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * { using Inkscape::UI::Widget::ColorNotebook; - if (_gui_hidden) return NULL; + if (_hidden) return NULL; if (changeSignal) { _changeSignal = new sigc::signal<void>(*changeSignal); @@ -98,9 +104,9 @@ Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * _color_changed.block(false); } - Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, 4)); + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); Gtk::Widget *selector = Gtk::manage(new ColorNotebook(_color)); - hbox->pack_start (*selector, true, true, 0); + hbox->pack_start(*selector, true, true, 0); selector->show(); hbox->show(); return hbox; diff --git a/src/extension/param/color.h b/src/extension/param/color.h index ed2e57ceb..890f5ba5f 100644 --- a/src/extension/param/color.h +++ b/src/extension/param/color.h @@ -31,8 +31,13 @@ private: Inkscape::UI::SelectedColor _color; sigc::connection _color_changed; public: - ParamColor(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - + ParamColor(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); virtual ~ParamColor(void); /** Returns \c _value, with a \i const to protect it. */ diff --git a/src/extension/param/description.cpp b/src/extension/param/description.cpp index 326e75e4a..cf94918f7 100644 --- a/src/extension/param/description.cpp +++ b/src/extension/param/description.cpp @@ -16,6 +16,8 @@ #include <gtkmm/box.h> #include <gtkmm/label.h> #include <glibmm/i18n.h> +#include <glibmm/markup.h> +#include <glibmm/regex.h> #include "xml/node.h" #include "extension/extension.h" @@ -26,35 +28,61 @@ namespace Extension { /** \brief Initialize the object, to do that, copy the data. */ -ParamDescription::ParamDescription (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(NULL), _mode(mode), _indent(0) +ParamDescription::ParamDescription(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) + : Parameter(name, text, description, hidden, indent, ext) + , _value(NULL) + , _mode(mode) { - // printf("Building Description\n"); - const char * defaultval = NULL; - if (xml->firstChild() != NULL) { - defaultval = xml->firstChild()->content(); + // construct the text content by concatenating all (non-empty) text nodes, + // removing all other nodes (e.g. comment nodes) and replacing <extension:br> elements with "<br/>" + Glib::ustring value; + Inkscape::XML::Node * cur_child = xml->firstChild(); + while (cur_child != NULL) { + if (cur_child->type() == XML::TEXT_NODE && cur_child->content() != NULL) { + value += cur_child->content(); + } else if (cur_child->type() == XML::ELEMENT_NODE && !g_strcmp0(cur_child->name(), "extension:br")) { + value += "<br/>"; + } + cur_child = cur_child->next(); } - if (defaultval != NULL) { - _value = g_strdup(defaultval); + // if there is no text content we can return immediately (the description will be invisible) + if (value == Glib::ustring("")) { + return; } - _context = xml->attribute("msgctxt"); + // do replacements in the source string to account for the attribute xml:space="preserve" + // (those should match replacements potentially performed by xgettext to allow for proper translation) + if (g_strcmp0(xml->attribute("xml:space"), "preserve") == 0) { + // xgettext copies the source string verbatim in this case, so no changes needed + } else { + // remove all whitespace from start/end of string and replace intermediate whitespace with a single space + value = Glib::Regex::create("^\\s+|\\s+$")->replace_literal(value, 0, "", (Glib::RegexMatchFlags)0); + value = Glib::Regex::create("\\s+")->replace_literal(value, 0, " ", (Glib::RegexMatchFlags)0); + } - const char * indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; + // translate if underscored version (_param) was used + if (g_str_has_prefix(xml->name(), "extension:_")) { + const gchar * context = xml->attribute("msgctxt"); + if (context != NULL) { + value = g_dpgettext2(NULL, context, value.c_str()); + } else { + value = _(value.c_str()); + } } + // finally replace all remaining <br/> with a real newline character + value = Glib::Regex::create("<br/>")->replace_literal(value, 0, "\n", (Glib::RegexMatchFlags)0); + + _value = g_strdup(value.c_str()); + return; } @@ -62,36 +90,48 @@ ParamDescription::ParamDescription (const gchar * name, Gtk::Widget * ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/) { - if (_gui_hidden) { + if (_hidden) { return NULL; } if (_value == NULL) { return NULL; } - Glib::ustring newguitext; + Glib::ustring newtext = _value; - if (_context != NULL) { - newguitext = g_dpgettext2(NULL, _context, _value); - } else { - newguitext = _(_value); - } - - Gtk::Label * label; - int padding = 12 + _indent; + Gtk::Label * label = Gtk::manage(new Gtk::Label()); if (_mode == HEADER) { - label = Gtk::manage(new Gtk::Label(Glib::ustring("<b>") +newguitext + Glib::ustring("</b>"), Gtk::ALIGN_START)); - label->set_padding(0,5); - label->set_use_markup(true); - padding = _indent; + label->set_markup(Glib::ustring("<b>") + Glib::Markup::escape_text(newtext) + Glib::ustring("</b>")); + label->set_margin_top(5); + label->set_margin_bottom(5); + } else if (_mode == URL) { + Glib::ustring escaped_url = Glib::Markup::escape_text(newtext); + label->set_markup(Glib::ustring::compose("<a href='%1'>%1</a>", escaped_url)); } else { - label = Gtk::manage(new Gtk::Label(newguitext, Gtk::ALIGN_START)); + label->set_text(newtext); } label->set_line_wrap(); +#if (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 16) + label->set_xalign(0); +#else + label->set_alignment(Gtk::ALIGN_START); +#endif + + // TODO: Ugly "fix" for gtk3 width/height calculation of labels. + // - If not applying any limits long labels will make the window grow horizontally until it uses up + // most of the available space (i.e. most of the screen area) which is ridicously wide + // - By using "set_default_size(0,0)" in prefidalog.cpp we tell the window to shrink as much as possible, + // however this can result in a much to narrow dialog instead and much unnecessary wrapping + // - Here we set a lower limit of GUI_MAX_LINE_LENGTH characters per line that long texts will always use + // This means texts can not shrink anymore (they can still grow, though) and it's also necessary + // to prevent https://bugzilla.gnome.org/show_bug.cgi?id=773572 + int len = newtext.length(); + label->set_width_chars(len > Parameter::GUI_MAX_LINE_LENGTH ? Parameter::GUI_MAX_LINE_LENGTH : len); + label->show(); - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - hbox->pack_start(*label, true, true, padding); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + hbox->pack_start(*label, true, true); hbox->show(); return hbox; diff --git a/src/extension/param/description.h b/src/extension/param/description.h index 3a72c4112..599c4db78 100644 --- a/src/extension/param/description.h +++ b/src/extension/param/description.h @@ -27,24 +27,22 @@ namespace Extension { class ParamDescription : public Parameter { public: enum AppearanceMode { - DESC, HEADER + DESCRIPTION, HEADER, URL }; ParamDescription(const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, + const gchar * text, + const gchar * description, + bool hidden, + int indent, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml, AppearanceMode mode); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); private: /** \brief Internal value. */ gchar * _value; AppearanceMode _mode; - int _indent; - const gchar* _context; }; } /* namespace Extension */ diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 4e7420807..7cd860465 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -33,25 +33,28 @@ namespace Inkscape { namespace Extension { /* For internal use only. - Note that value and guitext MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ + Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ class enumentry { public: enumentry (Glib::ustring &val, Glib::ustring &text) : value(val), - guitext(text) + text(text) {} Glib::ustring value; - Glib::ustring guitext; + Glib::ustring text; }; -ParamComboBox::ParamComboBox(const gchar *name, const gchar *guitext, const gchar *desc, - const Parameter::_scope_t scope, bool gui_hidden, const gchar *gui_tip, - Inkscape::Extension::Extension *ext, Inkscape::XML::Node *xml) - : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) +ParamComboBox::ParamComboBox(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml) + : Parameter(name, text, description, hidden, indent, ext) , _value(NULL) - , _indent(0) , choices(NULL) { const char *xmlval = NULL; // the value stored in XML @@ -61,7 +64,7 @@ ParamComboBox::ParamComboBox(const gchar *name, const gchar *guitext, const gcha for (Inkscape::XML::Node *node = xml->firstChild(); node; node = node->next()) { char const * chname = node->name(); if (!strcmp(chname, INKSCAPE_EXTENSION_NS "item") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { - Glib::ustring newguitext, newvalue; + Glib::ustring newtext, newvalue; const char * contents = NULL; if (node->firstChild()) { contents = node->firstChild()->content(); @@ -72,12 +75,12 @@ ParamComboBox::ParamComboBox(const gchar *name, const gchar *guitext, const gcha // still need to include if are to be localized if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { if (node->attribute("msgctxt") != NULL) { - newguitext = g_dpgettext2(NULL, node->attribute("msgctxt"), contents); + newtext = g_dpgettext2(NULL, node->attribute("msgctxt"), contents); } else { - newguitext = _(contents); + newtext = _(contents); } } else { - newguitext = contents; + newtext = contents; } } else continue; @@ -89,22 +92,17 @@ ParamComboBox::ParamComboBox(const gchar *name, const gchar *guitext, const gcha newvalue = contents; } - if ( (!newguitext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here - choices = g_slist_append( choices, new enumentry(newvalue, newguitext) ); + if ( (!newtext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here + choices = g_slist_append( choices, new enumentry(newvalue, newtext) ); } } } - + // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child if (xml->firstChild() && xml->firstChild()->firstChild()) { xmlval = xml->firstChild()->attribute("value"); } - - const char *indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; - } } gchar * pref_name = this->pref_name(); @@ -155,7 +153,7 @@ const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape Glib::ustring settext; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { enumentry * entr = reinterpret_cast<enumentry *>(list->data); - if ( !entr->guitext.compare(in) ) { + if ( !entr->text.compare(in) ) { settext = entr->value; break; // break out of for loop } @@ -175,20 +173,20 @@ const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape } /** - * function to test if \c guitext is selectable + * function to test if \c text is selectable */ -bool ParamComboBox::contains(const gchar * guitext, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const +bool ParamComboBox::contains(const gchar * text, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const { - if (guitext == NULL) { + if (text == NULL) { return false; /* Can't have NULL string */ } for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { enumentry * entr = reinterpret_cast<enumentry *>(list->data); - if ( !entr->guitext.compare(guitext) ) + if ( !entr->text.compare(text) ) return true; } - // if we did not find the guitext in this ParamComboBox: + // if we did not find the text in this ParamComboBox: return false; } @@ -246,25 +244,25 @@ ParamComboBoxEntry::changed (void) */ Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); - hbox->pack_start(*label, false, false, _indent); + hbox->pack_start(*label, false, false); ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: Glib::ustring settext; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { enumentry * entr = reinterpret_cast<enumentry *>(list->data); - Glib::ustring text = entr->guitext; + Glib::ustring text = entr->text; combo->append(text); if ( _value && !entr->value.compare(_value) ) { - settext = entr->guitext; + settext = entr->text; } } if (!settext.empty()) { diff --git a/src/extension/param/enum.h b/src/extension/param/enum.h index 52e018469..143a648d7 100644 --- a/src/extension/param/enum.h +++ b/src/extension/param/enum.h @@ -34,12 +34,18 @@ private: been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - int _indent; GSList * choices; /**< A table to store the choice strings */ public: - ParamComboBox(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ParamComboBox(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); virtual ~ParamComboBox(void); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); // Explicitly call superclass version to avoid method being hidden. @@ -52,9 +58,9 @@ public: const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); /** - * @returns true if guitext is part of this enum + * @returns true if text is part of this enum */ - bool contains(const gchar * guitext, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const; + bool contains(const gchar * text, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const; void changed (void); }; /* class ParamComboBox */ diff --git a/src/extension/param/float.cpp b/src/extension/param/float.cpp index dff7cbf46..69283a572 100644 --- a/src/extension/param/float.cpp +++ b/src/extension/param/float.cpp @@ -26,17 +26,19 @@ namespace Extension { /** Use the superclass' allocator and set the \c _value. */ -ParamFloat::ParamFloat (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(0.0), _mode(mode), _indent(0), _min(0.0), _max(10.0) +ParamFloat::ParamFloat(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) + : Parameter(name, text, description, hidden, indent, ext) + , _value(0.0) + , _mode(mode) + , _min(0.0) + , _max(10.0) { const gchar * defaultval = NULL; if (xml->firstChild() != NULL) { @@ -68,11 +70,6 @@ ParamFloat::ParamFloat (const gchar * name, _min = 0.0; } - const char * indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; - } - gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getDouble(extension_pref_root + pref_name, _value); @@ -170,38 +167,30 @@ void ParamFloatAdjustment::val_changed(void) */ Gtk::Widget * ParamFloat::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); -#if WITH_GTKMM_3_0 - ParamFloatAdjustment * pfa = new ParamFloatAdjustment(this, doc, node, changeSignal); + auto pfa = new ParamFloatAdjustment(this, doc, node, changeSignal); Glib::RefPtr<Gtk::Adjustment> fadjust(pfa); -#else - ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal)); -#endif - + if (_mode == FULL) { UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(_text, fadjust, _precision); scale->set_size_request(400, -1); scale->show(); - hbox->pack_start(*scale, false, false); + hbox->pack_start(*scale, true, true); } else if (_mode == MINIMAL) { Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); - hbox->pack_start(*label, true, true, _indent); + hbox->pack_start(*label, true, true); -#if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton * spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 0.1, _precision)); -#else - Inkscape::UI::Widget::SpinButton * spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(*fadjust, 0.1, _precision)); -#endif + auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 0.1, _precision)); spin->show(); hbox->pack_start(*spin, false, false); } diff --git a/src/extension/param/float.h b/src/extension/param/float.h index 42b1698b1..d58253ccb 100644 --- a/src/extension/param/float.h +++ b/src/extension/param/float.h @@ -29,15 +29,15 @@ public: enum AppearanceMode { FULL, MINIMAL }; - ParamFloat (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); + ParamFloat(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + /** Returns \c _value. */ float get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } @@ -60,7 +60,6 @@ private: /** Internal value. */ float _value; AppearanceMode _mode; - int _indent; float _min; float _max; int _precision; diff --git a/src/extension/param/int.cpp b/src/extension/param/int.cpp index dda801282..357f98590 100644 --- a/src/extension/param/int.cpp +++ b/src/extension/param/int.cpp @@ -26,17 +26,19 @@ namespace Extension { /** Use the superclass' allocator and set the \c _value. */ -ParamInt::ParamInt (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(0), _mode(mode), _indent(0), _min(0), _max(10) +ParamInt::ParamInt(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) + : Parameter(name, text, description, hidden, indent, ext) + , _value(0) + , _mode(mode) + , _min(0) + , _max(10) { const char * defaultval = NULL; if (xml->firstChild() != NULL) { @@ -61,11 +63,6 @@ ParamInt::ParamInt (const gchar * name, _min = 0; } - const char * indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; - } - gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getInt(extension_pref_root + pref_name, _value); @@ -151,38 +148,28 @@ void ParamIntAdjustment::val_changed(void) Gtk::Widget * ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); -#if WITH_GTKMM_3_0 - ParamIntAdjustment * pia = new ParamIntAdjustment(this, doc, node, changeSignal); + auto pia = new ParamIntAdjustment(this, doc, node, changeSignal); Glib::RefPtr<Gtk::Adjustment> fadjust(pia); -#else - ParamIntAdjustment * fadjust = Gtk::manage(new ParamIntAdjustment(this, doc, node, changeSignal)); -#endif if (_mode == FULL) { UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(_text, fadjust, 0); scale->set_size_request(400, -1); scale->show(); - hbox->pack_start(*scale, false, false); + hbox->pack_start(*scale, true, true); } else if (_mode == MINIMAL) { - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); - hbox->pack_start(*label, true, true, _indent); + hbox->pack_start(*label, true, true); -#if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton * spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 1.0, 0)); -#else - Inkscape::UI::Widget::SpinButton * spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(*fadjust, 1.0, 0)); -#endif + auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 1.0, 0)); spin->show(); hbox->pack_start(*spin, false, false); } diff --git a/src/extension/param/int.h b/src/extension/param/int.h index 3fd6cea9b..fcb1ef3f1 100644 --- a/src/extension/param/int.h +++ b/src/extension/param/int.h @@ -29,15 +29,14 @@ public: enum AppearanceMode { FULL, MINIMAL }; - ParamInt (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); + ParamInt(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); /** Returns \c _value. */ int get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } @@ -59,7 +58,6 @@ private: /** Internal value. */ int _value; AppearanceMode _mode; - int _indent; int _min; int _max; }; diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index 20c8e8481..4e94b5216 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -54,17 +54,28 @@ private: public: static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - ParamNotebookPage(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ParamNotebookPage(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); ~ParamNotebookPage(void); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); void paramString (std::list <std::string> &list); - gchar * get_guitext (void) {return _text;}; + gchar * get_text (void) {return _text;}; Parameter * get_param (const gchar * name); }; /* class ParamNotebookPage */ -ParamNotebookPage::ParamNotebookPage (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) +ParamNotebookPage::ParamNotebookPage(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml) + : Parameter(name, text, description, hidden, /*indent*/ 0, ext) { parameters = NULL; @@ -136,30 +147,23 @@ ParamNotebookPage * ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) { const char * name; - const char * guitext; - const char * desc; - const char * scope_str; - Parameter::_scope_t scope = Parameter::SCOPE_USER; - bool gui_hidden = false; - const char * gui_hide; - const char * gui_tip; + const char * text; + const char * description; + bool hidden = false; + const char * hide; name = in_repr->attribute("name"); - guitext = in_repr->attribute("gui-text"); - if (guitext == NULL) - guitext = in_repr->attribute("_gui-text"); - gui_tip = in_repr->attribute("gui-tip"); - if (gui_tip == NULL) - gui_tip = in_repr->attribute("_gui-tip"); - desc = in_repr->attribute("gui-description"); - if (desc == NULL) - desc = in_repr->attribute("_gui-description"); - scope_str = in_repr->attribute("scope"); - gui_hide = in_repr->attribute("gui-hidden"); - if (gui_hide != NULL) { - if (strcmp(gui_hide, "1") == 0 || - strcmp(gui_hide, "true") == 0) { - gui_hidden = true; + text = in_repr->attribute("gui-text"); + if (text == NULL) + text = in_repr->attribute("_gui-text"); + description = in_repr->attribute("gui-description"); + if (description == NULL) + description = in_repr->attribute("_gui-description"); + hide = in_repr->attribute("gui-hidden"); + if (hide != NULL) { + if (strcmp(hide, "1") == 0 || + strcmp(hide, "true") == 0) { + hidden = true; } /* else stays false */ } @@ -169,17 +173,7 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: return NULL; } - if (scope_str != NULL) { - if (!strcmp(scope_str, "user")) { - scope = Parameter::SCOPE_USER; - } else if (!strcmp(scope_str, "document")) { - scope = Parameter::SCOPE_DOCUMENT; - } else if (!strcmp(scope_str, "node")) { - scope = Parameter::SCOPE_NODE; - } - } - - ParamNotebookPage * page = new ParamNotebookPage(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + ParamNotebookPage * page = new ParamNotebookPage(name, text, description, hidden, in_ext, in_repr); /* Note: page could equal NULL */ return page; @@ -194,23 +188,30 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: */ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); - vbox->set_border_width(5); + vbox->set_border_width(Parameter::GUI_BOX_MARGIN); + vbox->set_spacing(Parameter::GUI_BOX_SPACING); // add parameters onto page (if any) for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = reinterpret_cast<Parameter *>(list->data); Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); if (widg) { + int indent = param->get_indent(); +#if GTK_CHECK_VERSION(3,12,0) + widg->set_margin_start(indent * Parameter::GUI_INDENTATION); +#else + widg->set_margin_left(indent * Parameter::GUI_INDENTATION); +#endif + vbox->pack_start(*widg, false, false, 0); + gchar const * tip = param->get_tooltip(); - // printf("Tip: '%s'\n", tip); - vbox->pack_start(*widg, false, false, 2); if (tip) { - widg->set_tooltip_text(_(tip)); + widg->set_tooltip_text(tip); } else { widg->set_tooltip_text(""); widg->set_has_tooltip(false); @@ -224,8 +225,14 @@ Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Nod } -ParamNotebook::ParamNotebook (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) +ParamNotebook::ParamNotebook(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml) + : Parameter(name, text, description, hidden, indent, ext) { pages = NULL; @@ -353,11 +360,7 @@ public: // hook function this->signal_switch_page().connect(sigc::mem_fun(this, &ParamNotebookWdg::changed_page)); }; -#if WITH_GTKMM_3_0 void changed_page(Gtk::Widget *page, guint pagenum); -#else - void changed_page(GtkNotebookPage *page, guint pagenum); -#endif bool activated; }; @@ -368,11 +371,7 @@ public: * is actually visible. This to exclude 'fake' changes when the * notebookpages are added or removed. */ -#if WITH_GTKMM_3_0 void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) -#else -void ParamNotebookWdg::changed_page(GtkNotebookPage * /*page*/, guint pagenum) -#endif { if (get_visible()) { _pref->set((int)pagenum, _doc, _node); @@ -424,7 +423,7 @@ Parameter *ParamNotebookPage::get_param(const gchar * name) */ Gtk::Widget * ParamNotebook::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } @@ -437,7 +436,7 @@ Gtk::Widget * ParamNotebook::get_widget(SPDocument * doc, Inkscape::XML::Node * i++; ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); Gtk::Widget * widg = page->get_widget(doc, node, changeSignal); - nb->append_page(*widg, _(page->get_guitext())); + nb->append_page(*widg, _(page->get_text())); if (!strcmp(_value, page->name())) { pagenr = i; // this is the page to be displayed? } diff --git a/src/extension/param/notebook.h b/src/extension/param/notebook.h index 3c90964fd..8475de61d 100644 --- a/src/extension/param/notebook.h +++ b/src/extension/param/notebook.h @@ -41,8 +41,15 @@ private: This only gets created if there are pages in this notebook */ public: - ParamNotebook(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ParamNotebook(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); virtual ~ParamNotebook(void); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); /** diff --git a/src/extension/param/parameter.cpp b/src/extension/param/parameter.cpp index e4a614667..5c4fe591f 100644 --- a/src/extension/param/parameter.cpp +++ b/src/extension/param/parameter.cpp @@ -50,100 +50,112 @@ Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex const char *name = in_repr->attribute("name"); const char *type = in_repr->attribute("type"); - // In this case we just don't have enough information - if (!name || !type) { + // we can't create a parameter without type + if (!type) { return NULL; } + // also require name unless it's a pure UI element that does not store its value + if (!name) { + static std::vector<std::string> ui_elements = {"description"}; + if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { + return NULL; + } + } - const char *guitext = in_repr->attribute("gui-text"); - if (guitext == NULL) { - guitext = in_repr->attribute("_gui-text"); - if (guitext == NULL) { - // guitext = ""; // propably better to require devs to explicitly set an empty gui-text if this is what they want + const char *text = in_repr->attribute("gui-text"); + if (text == NULL) { + text = in_repr->attribute("_gui-text"); + if (text == NULL) { + // text = ""; // propably 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 != NULL) { - guitext = g_dpgettext2(NULL, context, guitext); + text = g_dpgettext2(NULL, context, text); } else { - guitext = _(guitext); + text = _(text); } } } - const char *gui_tip = in_repr->attribute("gui-tip"); - if (gui_tip == NULL) { - gui_tip = in_repr->attribute("_gui-tip"); - } - const char *desc = in_repr->attribute("gui-description"); - if (desc == NULL) { - desc = in_repr->attribute("_gui-description"); + const char *description = in_repr->attribute("gui-description"); + if (description == NULL) { + description = in_repr->attribute("_gui-description"); + if (description != NULL) { + const char *context = in_repr->attribute("msgctxt"); + if (context != NULL) { + description = g_dpgettext2(NULL, context, description); + } else { + description = _(description); + } + } } - bool gui_hidden = false; + bool hidden = false; { const char *gui_hide = in_repr->attribute("gui-hidden"); if (gui_hide != NULL) { if (strcmp(gui_hide, "1") == 0 || strcmp(gui_hide, "true") == 0) { - gui_hidden = true; + hidden = true; } /* else stays false */ } } - const gchar* appearance = in_repr->attribute("appearance"); - - Parameter::_scope_t scope = Parameter::SCOPE_USER; + int indent = 0; { - const char *scope_str = in_repr->attribute("scope"); - if (scope_str != NULL) { - if (!strcmp(scope_str, "user")) { - scope = Parameter::SCOPE_USER; - } else if (!strcmp(scope_str, "document")) { - scope = Parameter::SCOPE_DOCUMENT; - } else if (!strcmp(scope_str, "node")) { - scope = Parameter::SCOPE_NODE; + const char *indent_attr = in_repr->attribute("indent"); + if (indent_attr != NULL) { + if (strcmp(indent_attr, "true") == 0) { + indent = 1; + } else { + indent = atoi(indent_attr); } } } + const gchar* appearance = in_repr->attribute("appearance"); Parameter * param = NULL; if (!strcmp(type, "boolean")) { - param = new ParamBool(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + 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, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamInt::FULL); + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); } else { - param = new ParamInt(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamInt::MINIMAL); + 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, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamFloat::FULL); + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); } else { - param = new ParamFloat(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamFloat::MINIMAL); + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); } } else if (!strcmp(type, "string")) { - param = new ParamString(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); gchar const * max_length = in_repr->attribute("max_length"); if (max_length != NULL) { ParamString * ps = dynamic_cast<ParamString *>(param); ps->setMaxLength(atoi(max_length)); } } else if (!strcmp(type, "description")) { - if (appearance && !strcmp(appearance, "header")) { - param = new ParamDescription(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamDescription::HEADER); - } else { - param = new ParamDescription(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamDescription::DESC); - } + 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, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); } else if (!strcmp(type, "notebook")) { - param = new ParamNotebook(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + 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, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::MINIMAL); + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); } else { - param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::FULL); + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); } } else if (!strcmp(type, "color")) { - param = new ParamColor(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); } // Note: param could equal NULL @@ -290,28 +302,24 @@ Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) /** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter(gchar const * name, gchar const * guitext, gchar const * desc, const Parameter::_scope_t scope, bool gui_hidden, gchar const * gui_tip, Inkscape::Extension::Extension * ext) : - _desc(0), - _scope(scope), +Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : + _description(0), _text(0), - _gui_hidden(gui_hidden), - _gui_tip(0), - extension(ext), + _hidden(hidden), + _indent(indent), + _extension(ext), _name(0) { if (name != NULL) { _name = g_strdup(name); } - if (desc != NULL) { - _desc = g_strdup(desc); -// printf("Adding description: '%s' on '%s'\n", _desc, _name); - } - if (gui_tip != NULL) { - _gui_tip = g_strdup(gui_tip); + + if (description != NULL) { + _description = g_strdup(description); } - if (guitext != NULL) { - _text = g_strdup(guitext); + if (text != NULL) { + _text = g_strdup(text); } else { _text = g_strdup(name); } @@ -320,20 +328,19 @@ Parameter::Parameter(gchar const * name, gchar const * guitext, gchar const * de } /** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter (gchar const * name, gchar const * guitext, Inkscape::Extension::Extension * ext) : - _desc(0), - _scope(Parameter::SCOPE_USER), +Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : + _description(0), _text(0), - _gui_hidden(false), - _gui_tip(0), - extension(ext), + _hidden(false), + _indent(0), + _extension(ext), _name(0) { if (name != NULL) { _name = g_strdup(name); } - if (guitext != NULL) { - _text = g_strdup(guitext); + if (text != NULL) { + _text = g_strdup(text); } else { _text = g_strdup(name); } @@ -349,16 +356,13 @@ Parameter::~Parameter(void) g_free(_text); _text = 0; - g_free(_gui_tip); - _gui_tip = 0; - - g_free(_desc); - _desc = 0; + g_free(_description); + _description = 0; } gchar *Parameter::pref_name(void) const { - return g_strdup_printf("%s.%s", extension->get_id(), _name); + return g_strdup_printf("%s.%s", _extension->get_id(), _name); } Inkscape::XML::Node * @@ -391,7 +395,7 @@ Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) child != NULL; child = child->next()) { if ((GQuark)child->code() == name_quark && - !strcmp(child->attribute("extension"), extension->get_id())) { + !strcmp(child->attribute("extension"), _extension->get_id())) { params = child; break; } @@ -399,7 +403,7 @@ Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) if (params == NULL) { params = xml_doc->createElement("inkscape:extension-param"); - params->setAttribute("extension", extension->get_id()); + params->setAttribute("extension", _extension->get_id()); defs->appendChild(params); Inkscape::GC::release(params); } diff --git a/src/extension/param/parameter.h b/src/extension/param/parameter.h index 5e1e3897f..96cc055d8 100644 --- a/src/extension/param/parameter.h +++ b/src/extension/param/parameter.h @@ -37,7 +37,7 @@ class Extension; */ extern Glib::ustring const extension_pref_root; -/** +/** * A class to represent the parameter of an extension. * * This is really a super class that allows them to abstract all @@ -47,25 +47,16 @@ extern Glib::ustring const extension_pref_root; */ class Parameter { -protected: - /** List of possible scopes. */ - typedef enum { - SCOPE_USER, /**< Parameter value is saved in the user's configuration file. (default) */ - SCOPE_DOCUMENT, /**< Parameter value is saved in the document. */ - SCOPE_NODE /**< Parameter value is attached to the node. */ - } _scope_t; - public: Parameter(gchar const *name, - gchar const *guitext, - gchar const *desc, - const Parameter::_scope_t scope, - bool gui_hidden, - gchar const *gui_tip, + gchar const *text, + gchar const *description, + bool hidden, + int indent, Inkscape::Extension::Extension * ext); Parameter(gchar const *name, - gchar const *guitext, + gchar const *text, Inkscape::Extension::Extension * ext); virtual ~Parameter(void); @@ -139,10 +130,13 @@ public: virtual Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - gchar const * get_tooltip(void) const { return _desc; } + gchar const * get_tooltip(void) const { return _description; } /** Indicates if the GUI for this parameter is hidden or not */ - bool get_gui_hidden() const { return _gui_hidden; } + bool get_hidden() const { return _hidden; } + + /** Indentation level of the parameter */ + int get_indent() const { return _indent; } virtual void string(std::list <std::string> &list) const; @@ -155,21 +149,31 @@ public: /** All the code in Notebook::get_param to get the notebook content. */ virtual Parameter *get_param(gchar const *name); -protected: - /** Description of the parameter. */ - gchar * _desc; - /** Scope of the parameter. */ - _scope_t _scope; + /** Recommended margin of boxes containing multiple Parameters (in px) */ + const static int GUI_BOX_MARGIN = 10; + /** Recommended spacing between multiple Parameters packed into a box (in px) */ + const static int GUI_BOX_SPACING = 4; + /** Recommended spacing between the widgets making up a signle Parameter (e.g. label and input) (in px) */ + const static int GUI_PARAM_WIDGETS_SPACING = 4; + /** Recommended indentation width of parameters (in px) */ + const static int GUI_INDENTATION = 12; + /** Recommended maximum line lenght for wrapping textual parameters (in chars) */ + const static int GUI_MAX_LINE_LENGTH = 60; + + +protected: + /** Parameter text to show as the GUI label. */ + gchar * _text; - /** Text for the GUI selection of this. */ - gchar * _text; + /** Extended description of the parameter (crrently shown as tooltip on hover). */ + gchar * _description; - /** Whether the GUI is visible. */ - bool _gui_hidden; + /** Whether the parameter is visible. */ + bool _hidden; - /** A tip for the GUI if there is one. */ - gchar * _gui_tip; + /** Indentation level of the parameter. */ + int _indent; /* **** funcs **** */ @@ -187,7 +191,7 @@ protected: private: /** Which extension is this parameter attached to. */ - Inkscape::Extension::Extension *extension; + Inkscape::Extension::Extension *_extension; /** The name of this parameter. */ gchar *_name; diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index 1d1b860c6..a08ba6860 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -41,33 +41,34 @@ namespace Inkscape { namespace Extension { /* For internal use only. - Note that value and guitext MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ + Note that value and text MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ class optionentry { public: - optionentry (Glib::ustring * val, Glib::ustring * text) { + optionentry (Glib::ustring * val, Glib::ustring * txt) { value = val; - guitext = text; + text = txt; } ~optionentry() { delete value; - delete guitext; + delete text; } Glib::ustring * value; - Glib::ustring * guitext; + Glib::ustring * text; }; -ParamRadioButton::ParamRadioButton (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(0), _mode(mode), _indent(0), choices(0) +ParamRadioButton::ParamRadioButton(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) + : Parameter(name, text, description, hidden, indent, ext) + , _value(0) + , _mode(mode) + , choices(0) { // Read XML tree to add enumeration items: // printf("Extension Constructor: "); @@ -76,7 +77,7 @@ ParamRadioButton::ParamRadioButton (const gchar * name, while (child_repr != NULL) { char const * chname = child_repr->name(); if (!strcmp(chname, INKSCAPE_EXTENSION_NS "option") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { - Glib::ustring * newguitext = NULL; + Glib::ustring * newtext = NULL; Glib::ustring * newvalue = NULL; const char * contents = child_repr->firstChild()->content(); @@ -84,12 +85,12 @@ ParamRadioButton::ParamRadioButton (const gchar * name, // don't translate when 'item' but do translate when '_option' if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { if (child_repr->attribute("msgctxt") != NULL) { - newguitext = new Glib::ustring(g_dpgettext2(NULL, child_repr->attribute("msgctxt"), contents)); + newtext = new Glib::ustring(g_dpgettext2(NULL, child_repr->attribute("msgctxt"), contents)); } else { - newguitext = new Glib::ustring(_(contents)); + newtext = new Glib::ustring(_(contents)); } } else { - newguitext = new Glib::ustring(contents); + newtext = new Glib::ustring(contents); } } else { continue; @@ -103,8 +104,8 @@ ParamRadioButton::ParamRadioButton (const gchar * name, newvalue = new Glib::ustring(contents); } - if ( (newguitext) && (newvalue) ) { // logical error if this is not true here - choices = g_slist_append( choices, new optionentry(newvalue, newguitext) ); + if ( (newtext) && (newvalue) ) { // logical error if this is not true here + choices = g_slist_append( choices, new optionentry(newvalue, newtext) ); } } child_repr = child_repr->next(); @@ -118,11 +119,6 @@ ParamRadioButton::ParamRadioButton (const gchar * name, defaultval = (static_cast<optionentry*> (choices->data))->value->c_str(); } - const char *indent = xml ? xml->attribute("indent") : NULL; - if (indent != NULL) { - _indent = atoi(indent) * 12; - } - gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); @@ -284,7 +280,7 @@ Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { optionentry * entr = reinterpret_cast<optionentry *>(list->data); - if ( !entr->guitext->compare(label) ) { + if ( !entr->text->compare(label) ) { value = *(entr->value); break; } @@ -299,23 +295,18 @@ Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) */ Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } -#if WITH_GTKMM_3_0 - Gtk::Box * hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 4)); + auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); hbox->set_homogeneous(false); - Gtk::Box * vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); + auto vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); vbox->set_homogeneous(false); -#else - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox(false, 0)); -#endif Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START, Gtk::ALIGN_START)); label->show(); - hbox->pack_start(*label, false, false, _indent); + hbox->pack_start(*label, false, false); Gtk::ComboBoxText* cbt = 0; bool comboSet = false; @@ -330,7 +321,7 @@ Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node Gtk::RadioButtonGroup group; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { optionentry * entr = reinterpret_cast<optionentry *>(list->data); - Glib::ustring * text = entr->guitext; + Glib::ustring * text = entr->text; switch ( _mode ) { case MINIMAL: { diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index 0e0f643c9..b91b11ea3 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -35,15 +35,15 @@ public: }; ParamRadioButton(const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, + const gchar * text, + const gchar * description, + bool hidden, + int indent, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml, AppearanceMode mode); virtual ~ParamRadioButton(void); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); // Explicitly call superclass version to avoid method being hidden. @@ -63,7 +63,6 @@ private: It is the value of the current selected string */ gchar * _value; AppearanceMode _mode; - int _indent; GSList * choices; /**< A table to store the choice strings */ }; /* class ParamRadioButton */ diff --git a/src/extension/param/string.cpp b/src/extension/param/string.cpp index 6b082b133..51b5dfdf3 100644 --- a/src/extension/param/string.cpp +++ b/src/extension/param/string.cpp @@ -24,7 +24,7 @@ namespace Inkscape { namespace Extension { - + /** Free the allocated data. */ ParamString::~ParamString(void) @@ -76,20 +76,21 @@ void ParamString::string(std::string &string) const } /** Initialize the object, to do that, copy the data. */ -ParamString::ParamString (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(NULL), _indent(0) +ParamString::ParamString(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml) + : Parameter(name, text, description, hidden, indent, ext) + , _value(NULL) { const char * defaultval = NULL; if (xml->firstChild() != NULL) { defaultval = xml->firstChild()->content(); } - const char * indent = xml->attribute("indent"); - if (indent != NULL) { - _indent = atoi(indent) * 12; - } - gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); @@ -161,14 +162,14 @@ void ParamStringEntry::changed_text(void) */ Gtk::Widget * ParamString::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) { + if (_hidden) { return NULL; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); - hbox->pack_start(*label, false, false, _indent); + hbox->pack_start(*label, false, false); ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); textbox->show(); diff --git a/src/extension/param/string.h b/src/extension/param/string.h index 3b137aeac..d338f83b9 100644 --- a/src/extension/param/string.h +++ b/src/extension/param/string.h @@ -19,12 +19,17 @@ private: /** \brief Internal value. This should point to a string that has been allocated in memory. And should be free'd. */ gchar * _value; - /** \brief Internal value. This indicates the maximum leght of the string. Zero meaning unlimited. + /** \brief Internal value. This indicates the maximum lenth of the string. Zero meaning unlimited. */ - int _indent; gint _max_length; public: - ParamString(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ParamString(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); virtual ~ParamString(void); /** \brief Returns \c _value, with a \i const to protect it. */ |
