summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-01-27 21:23:50 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-01-27 21:23:50 +0000
commit5ac0191ea6c6dbcec3259ab7cc694e302dc0b707 (patch)
treef5597be22f95d3aa14fe20beb3cab5636da43139 /src
parentFixed: Non-translatable strings in "enum" type extensions (diff)
downloadinkscape-5ac0191ea6c6dbcec3259ab7cc694e302dc0b707.tar.gz
inkscape-5ac0191ea6c6dbcec3259ab7cc694e302dc0b707.zip
Fixed untranslatable radiobuttons in extensions
(bzr r2298)
Diffstat (limited to 'src')
-rw-r--r--src/extension/paramradiobutton.cpp90
-rw-r--r--src/extension/paramradiobutton.h2
2 files changed, 62 insertions, 30 deletions
diff --git a/src/extension/paramradiobutton.cpp b/src/extension/paramradiobutton.cpp
index b1eef0e5d..794abed94 100644
--- a/src/extension/paramradiobutton.cpp
+++ b/src/extension/paramradiobutton.cpp
@@ -1,5 +1,5 @@
/** \file
- * extension parameter for radiobuttons.
+ * extension parameter for radiobuttons.
*
* It uses a Gtk:ComboBoxText widget in the extension UI.
*/
@@ -8,7 +8,7 @@
* Author:
* Johan Engelen <johan@shouraizou.nl>
*
- * Copyright (C) 2006 Author
+ * Copyright (C) 2006-2007 Johan Engelen
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -42,12 +42,29 @@
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. */
+class optionentry {
+public:
+ optionentry (Glib::ustring * val, Glib::ustring * text) {
+ value = val;
+ guitext = text;
+ }
+ ~optionentry() {
+ delete value;
+ delete guitext;
+ }
+
+ Glib::ustring * value;
+ Glib::ustring * guitext;
+};
+
ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
Parameter(name, guitext, desc, scope, ext)
-{
+{
choices = NULL;
_value = NULL;
-
+
// Read XML tree to add enumeration items:
// printf("Extension Constructor: ");
if (xml != NULL) {
@@ -55,23 +72,29 @@ ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, c
while (child_repr != NULL) {
char const * chname = child_repr->name();
if (!strcmp(chname, "option")) {
- Glib::ustring * newitem = NULL;
+ Glib::ustring * newguitext = NULL;
+ Glib::ustring * newvalue = NULL;
const char * contents = sp_repr_children(child_repr)->content();
if (contents != NULL)
- newitem = new Glib::ustring(contents);
- if (newitem != NULL) choices = g_slist_append(choices, newitem);
+ newguitext = new Glib::ustring(contents);
+ const char * val = child_repr->attribute("value");
+ if (val != NULL)
+ newvalue = new Glib::ustring(val);
+ if ( (newguitext) && (newvalue) ) {
+ choices = g_slist_append( choices, new optionentry(newvalue, newguitext) );
+ }
}
child_repr = sp_repr_next(child_repr);
}
}
-
+
// Initialize _value with the default value from xml
// for simplicity : default to the contents of the first xml-child
const char * defaultval = NULL;
if (sp_repr_children(sp_repr_children(xml)) != NULL)
- defaultval = sp_repr_children(sp_repr_children(xml))->content();
-
- gchar * pref_name = this->pref_name();
+ defaultval = sp_repr_children(xml)->attribute("value");
+
+ gchar * pref_name = this->pref_name();
const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name);
g_free(pref_name);
@@ -79,16 +102,15 @@ ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, c
defaultval = paramval;
if (defaultval != NULL)
_value = g_strdup(defaultval); // allocate space for _value
-
+
return;
}
ParamRadioButton::~ParamRadioButton (void)
-{
+{
//destroy choice strings
for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {
- Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);
- delete text;
+ delete (reinterpret_cast<optionentry *>(list->data));
}
g_slist_free(choices);
@@ -114,13 +136,21 @@ ParamRadioButton::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node *
{
if (in == NULL) return NULL; /* Can't have NULL string */
- if (_value != NULL)
- g_free(_value);
- _value = g_strdup(in);
-
- gchar * prefname = this->pref_name();
- prefs_set_string_attribute(PREF_DIR, prefname, _value);
- g_free(prefname);
+ Glib::ustring * settext = NULL;
+ for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {
+ optionentry * entr = reinterpret_cast<optionentry *>(list->data);
+ if ( !entr->guitext->compare(in) ) {
+ settext = entr->value;
+ break; // break out of for loop
+ }
+ }
+ if (settext) {
+ if (_value != NULL) g_free(_value);
+ _value = g_strdup(settext->c_str());
+ gchar * prefname = this->pref_name();
+ prefs_set_string_attribute(PREF_DIR, prefname, _value);
+ g_free(prefname);
+ }
return _value;
}
@@ -152,12 +182,12 @@ public:
/** \brief Build a string preference for the given parameter
\param pref Where to put the radiobutton's string when it is selected.
*/
- ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label,
+ ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label,
ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node ) :
Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node) {
add_changesignal();
};
- ParamRadioButtonWdg ( const Glib::ustring& label,
+ ParamRadioButtonWdg ( const Glib::ustring& label,
ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node ) :
Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node) {
add_changesignal();
@@ -203,24 +233,26 @@ ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node)
ParamRadioButtonWdg * radio;
Gtk::RadioButtonGroup group;
for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {
- Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);
+ optionentry * entr = reinterpret_cast<optionentry *>(list->data);
+ Glib::ustring * text = entr->guitext;
if (first) {
radio = Gtk::manage(new ParamRadioButtonWdg(*text, this, doc, node));
group = radio->get_group();
first = false;
} else {
radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node));
- }
+ }
radio->show();
vbox->pack_start(*radio, true, true);
- if (!strcmp(text->c_str(), _value)) {
+ if (!entr->value->compare(_value)) {
radio->set_active();
- }
+ }
}
+
vbox->show();
hbox->pack_end(*vbox, false, false);
hbox->show();
-
+
return dynamic_cast<Gtk::Widget *>(hbox);
}
diff --git a/src/extension/paramradiobutton.h b/src/extension/paramradiobutton.h
index bf0cd2143..04c4e5846 100644
--- a/src/extension/paramradiobutton.h
+++ b/src/extension/paramradiobutton.h
@@ -9,7 +9,7 @@
* Author:
* Johan Engelen <johan@shouraizou.nl>
*
- * Copyright (C) 2006 Author
+ * Copyright (C) 2006-2007 Johan Engelen
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/