summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6c2fb74)
raw | patch | inline | side by side (parent: 6c2fb74)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Sat, 27 Jan 2007 21:23:50 +0000 (21:23 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Sat, 27 Jan 2007 21:23:50 +0000 (21:23 +0000) |
share/extensions/radiobutton_example.inx | patch | blob | history | |
src/extension/paramradiobutton.cpp | patch | blob | history | |
src/extension/paramradiobutton.h | patch | blob | history |
index 0195ed211d268d7c3bd93705bdcdaf19131b190f..8d2e5e3fd2409f6648b4ccc0c0b98cb907eba652 100644 (file)
<_name>RadioButton example</_name>
<id>org.inkscape.effect.radiobuttontest</id>
<param name="radio1" type="optiongroup" _gui-text="Select option: ">
- <option>string 1</option>
- <option>string 2</option>
- <option>test 3!</option>
+ <option value="string1">translatable string 1</option>
+ <option value="string2">string 2</option>
+ <option value="string3">test 3!</option>
</param>
<param name="radio2" type="optiongroup" _gui-text="Select second option: ">
- <option>string1</option>
- <option>string2</option>
+ <option value="string11">string1</option>
+ <option value="string22">string2</option>
<option>test3!</option>
</param>
<effect>
index b1eef0e5d7fe2afbf29fbbb5aa0aa562d3e091a2..794abed94ac6e30157a4eb9f8d7696551e489fd2 100644 (file)
/** \file\r
- * extension parameter for radiobuttons. \r
+ * extension parameter for radiobuttons.\r
*\r
* It uses a Gtk:ComboBoxText widget in the extension UI.\r
*/\r
* Author:\r
* Johan Engelen <johan@shouraizou.nl>\r
*\r
- * Copyright (C) 2006 Author\r
+ * Copyright (C) 2006-2007 Johan Engelen\r
*\r
* Released under GNU GPL, read the file 'COPYING' for more information\r
*/\r
namespace Inkscape {\r
namespace Extension {\r
\r
+/* For internal use only.\r
+ 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. */\r
+class optionentry {\r
+public:\r
+ optionentry (Glib::ustring * val, Glib::ustring * text) {\r
+ value = val;\r
+ guitext = text;\r
+ }\r
+ ~optionentry() {\r
+ delete value;\r
+ delete guitext;\r
+ }\r
+\r
+ Glib::ustring * value;\r
+ Glib::ustring * guitext;\r
+};\r
+\r
ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :\r
Parameter(name, guitext, desc, scope, ext)\r
-{ \r
+{\r
choices = NULL;\r
_value = NULL;\r
- \r
+\r
// Read XML tree to add enumeration items:\r
// printf("Extension Constructor: ");\r
if (xml != NULL) {\r
@@ -55,23 +72,29 @@ ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, c
while (child_repr != NULL) {\r
char const * chname = child_repr->name();\r
if (!strcmp(chname, "option")) {\r
- Glib::ustring * newitem = NULL;\r
+ Glib::ustring * newguitext = NULL;\r
+ Glib::ustring * newvalue = NULL;\r
const char * contents = sp_repr_children(child_repr)->content();\r
if (contents != NULL)\r
- newitem = new Glib::ustring(contents);\r
- if (newitem != NULL) choices = g_slist_append(choices, newitem);\r
+ newguitext = new Glib::ustring(contents);\r
+ const char * val = child_repr->attribute("value");\r
+ if (val != NULL)\r
+ newvalue = new Glib::ustring(val);\r
+ if ( (newguitext) && (newvalue) ) {\r
+ choices = g_slist_append( choices, new optionentry(newvalue, newguitext) );\r
+ }\r
}\r
child_repr = sp_repr_next(child_repr);\r
}\r
}\r
- \r
+\r
// Initialize _value with the default value from xml\r
// for simplicity : default to the contents of the first xml-child\r
const char * defaultval = NULL;\r
if (sp_repr_children(sp_repr_children(xml)) != NULL)\r
- defaultval = sp_repr_children(sp_repr_children(xml))->content();\r
- \r
- gchar * pref_name = this->pref_name();\r
+ defaultval = sp_repr_children(xml)->attribute("value");\r
+\r
+ gchar * pref_name = this->pref_name();\r
const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name);\r
g_free(pref_name);\r
\r
@@ -79,16 +102,15 @@ ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, c
defaultval = paramval;\r
if (defaultval != NULL)\r
_value = g_strdup(defaultval); // allocate space for _value\r
- \r
+\r
return;\r
}\r
\r
ParamRadioButton::~ParamRadioButton (void)\r
-{ \r
+{\r
//destroy choice strings\r
for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {\r
- Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);\r
- delete text;\r
+ delete (reinterpret_cast<optionentry *>(list->data));\r
}\r
g_slist_free(choices);\r
\r
@@ -114,13 +136,21 @@ ParamRadioButton::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node *
{\r
if (in == NULL) return NULL; /* Can't have NULL string */\r
\r
- if (_value != NULL)\r
- g_free(_value);\r
- _value = g_strdup(in);\r
-\r
- gchar * prefname = this->pref_name();\r
- prefs_set_string_attribute(PREF_DIR, prefname, _value);\r
- g_free(prefname);\r
+ Glib::ustring * settext = NULL;\r
+ for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {\r
+ optionentry * entr = reinterpret_cast<optionentry *>(list->data);\r
+ if ( !entr->guitext->compare(in) ) {\r
+ settext = entr->value;\r
+ break; // break out of for loop\r
+ }\r
+ }\r
+ if (settext) {\r
+ if (_value != NULL) g_free(_value);\r
+ _value = g_strdup(settext->c_str());\r
+ gchar * prefname = this->pref_name();\r
+ prefs_set_string_attribute(PREF_DIR, prefname, _value);\r
+ g_free(prefname);\r
+ }\r
\r
return _value;\r
}\r
/** \brief Build a string preference for the given parameter\r
\param pref Where to put the radiobutton's string when it is selected.\r
*/\r
- ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label, \r
+ ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label,\r
ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node ) :\r
Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node) {\r
add_changesignal();\r
};\r
- ParamRadioButtonWdg ( const Glib::ustring& label, \r
+ ParamRadioButtonWdg ( const Glib::ustring& label,\r
ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node ) :\r
Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node) {\r
add_changesignal();\r
ParamRadioButtonWdg * radio;\r
Gtk::RadioButtonGroup group;\r
for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {\r
- Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);\r
+ optionentry * entr = reinterpret_cast<optionentry *>(list->data);\r
+ Glib::ustring * text = entr->guitext;\r
if (first) {\r
radio = Gtk::manage(new ParamRadioButtonWdg(*text, this, doc, node));\r
group = radio->get_group();\r
first = false;\r
} else {\r
radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node));\r
- } \r
+ }\r
radio->show();\r
vbox->pack_start(*radio, true, true);\r
- if (!strcmp(text->c_str(), _value)) {\r
+ if (!entr->value->compare(_value)) {\r
radio->set_active();\r
- } \r
+ }\r
}\r
+\r
vbox->show();\r
hbox->pack_end(*vbox, false, false);\r
hbox->show();\r
- \r
+\r
\r
return dynamic_cast<Gtk::Widget *>(hbox);\r
}\r
index bf0cd21435f45d9f3c31c75e63cc6f5930d100a5..04c4e58468baf04833a528efd11ff6350f260743 100644 (file)
* Author:\r
* Johan Engelen <johan@shouraizou.nl>\r
*\r
- * Copyright (C) 2006 Author\r
+ * Copyright (C) 2006-2007 Johan Engelen\r
*\r
* Released under GNU GPL, read the file 'COPYING' for more information\r
*/\r