From: joncruz Date: Sat, 24 May 2008 13:43:22 +0000 (+0000) Subject: Added an 'appearance' hint to .inx optiongroups to allow for dropdowns instead of... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b6a93271fbf673132b6cbbe2d65437a1de9c2aec;p=inkscape.git Added an 'appearance' hint to .inx optiongroups to allow for dropdowns instead of radio buttons. --- diff --git a/share/extensions/polyhedron_3d.inx b/share/extensions/polyhedron_3d.inx index 6a6d4010d..3ef24399e 100644 --- a/share/extensions/polyhedron_3d.inx +++ b/share/extensions/polyhedron_3d.inx @@ -6,7 +6,7 @@ inkex.py - + <_option value="cube">Cube <_option value="t_cube">Truncated Cube <_option value="sn_cube">Snub Cube @@ -26,38 +26,38 @@ <_option value="from_file">Load From File great_rhombicuboct.obj - + <_option value="face">Face-Specified <_option value="edge">Edge-Specified 0 - + <_option value="x">X-Axis <_option value="y">Y-Axis <_option value="z">Z-Axis 0 - + <_option value="x">X-Axis <_option value="y">Y-Axis <_option value="z">Z-Axis 0 - + <_option value="x">X-Axis <_option value="y">Y-Axis <_option value="z">Z-Axis 0 - + <_option value="x">X-Axis <_option value="y">Y-Axis <_option value="z">Z-Axis 0 - + <_option value="x">X-Axis <_option value="y">Y-Axis <_option value="z">Z-Axis 0 - + <_option value="x">X-Axis <_option value="y">Y-Axis <_option value="z">Z-Axis @@ -75,12 +75,12 @@ 1 1 -2 - + <_option value="vtx">Vertices <_option value="edg">Edges <_option value="fce">Faces 0 - + <_option value="max">Maximum <_option value="min">Minimum <_option value="mean">Mean diff --git a/src/extension/param/parameter.cpp b/src/extension/param/parameter.cpp index b356c297e..6d1a1570c 100644 --- a/src/extension/param/parameter.cpp +++ b/src/extension/param/parameter.cpp @@ -103,6 +103,7 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * } /* else stays false */ } + const gchar* appearance = in_repr->attribute("appearance"); /* In this case we just don't have enough information */ if (name == NULL || type == NULL) { @@ -140,7 +141,11 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * } else if (!strcmp(type, "notebook")) { param = new ParamNotebook(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); } else if (!strcmp(type, "optiongroup")) { - param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + if (appearance && !strcmp(appearance, "minimal")) { + param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::MINIMAL); + } else { + param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, 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); } diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index ba9648618..76c3506af 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -9,6 +9,7 @@ * Johan Engelen * * Copyright (C) 2006-2007 Johan Engelen + * Copyright (C) 2008 Jon A. Cruz * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -19,6 +20,7 @@ #include +#include #include #include #include @@ -59,12 +61,20 @@ public: Glib::ustring * guitext; }; -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) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) +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), + choices(0) { - choices = NULL; - _value = NULL; - // Read XML tree to add enumeration items: // printf("Extension Constructor: "); if (xml != NULL) { @@ -79,14 +89,14 @@ ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, c // don't translate when 'option' but do translate when '_option' newguitext = new Glib::ustring( !strcmp(chname, "_option") ? _(contents) : contents ); else - continue; - + continue; + const char * val = child_repr->attribute("value"); if (val != NULL) newvalue = new Glib::ustring(val); else 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) ); } @@ -219,6 +229,28 @@ ParamRadioButtonWdg::changed (void) } +class ComboWdg : public Gtk::ComboBoxText { +public: + ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node) : + Gtk::ComboBoxText(), + base(base), + doc(doc), + node(node) + { + } + virtual ~ComboWdg() {} + +protected: + ParamRadioButton* base; + SPDocument* doc; + Inkscape::XML::Node* node; + + virtual void on_changed() { + if ( base ) { + base->set(get_active_text().c_str(), doc, node); + } + } +}; /** \brief Creates a combobox widget for an enumeration parameter @@ -226,7 +258,7 @@ ParamRadioButtonWdg::changed (void) Gtk::Widget * ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) return NULL; Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox(false, 0)); @@ -235,28 +267,48 @@ ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc label->show(); hbox->pack_start(*label, false, false); + Gtk::ComboBoxText* cbt = 0; + bool comboSet = false; + if (_mode == MINIMAL) { + cbt = Gtk::manage(new ComboWdg(this, doc, node)); + cbt->show(); + vbox->pack_start(*cbt, false, false); + } + // add choice strings as radiobuttons // and select last selected option (_value) - bool first = true; - ParamRadioButtonWdg * radio; Gtk::RadioButtonGroup group; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { optionentry * entr = reinterpret_cast(list->data); Glib::ustring * text = entr->guitext; - if (first) { - radio = Gtk::manage(new ParamRadioButtonWdg(*text, this, doc, node, changeSignal)); - group = radio->get_group(); - first = false; - } else { - radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); - } - radio->show(); - vbox->pack_start(*radio, true, true); - if (!entr->value->compare(_value)) { - radio->set_active(); + switch ( _mode ) { + case MINIMAL: + { + cbt->append_text(*text); + if (!entr->value->compare(_value)) { + cbt->set_active_text(*text); + comboSet = true; + } + } + break; + case COMPACT: + case FULL: + { + ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); + radio->show(); + vbox->pack_start(*radio, true, true); + if (!entr->value->compare(_value)) { + radio->set_active(); + } + } + break; } } + if ( (_mode == MINIMAL) && !comboSet) { + cbt->set_active(0); + } + vbox->show(); hbox->pack_end(*vbox, false, false); hbox->show(); @@ -269,3 +321,13 @@ ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc } /* 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 : diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index 4bf596e4f..ea8440de2 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -28,22 +28,36 @@ namespace Extension { // \brief A class to represent a radiobutton parameter of an extension class ParamRadioButton : public Parameter { +public: + enum AppearanceMode { + FULL, COMPACT, MINIMAL + }; + + 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); + virtual ~ParamRadioButton(void); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + void string (std::string &string); + + const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + private: /** \brief Internal value. This should point to a string that has been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; + AppearanceMode _mode; GSList * choices; /**< A table to store the choice strings */ -public: - 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); - virtual ~ParamRadioButton(void); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - void string (std::string &string); - - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); }; /* class ParamRadioButton */