forked from AuroraMiddleware/gtk
builder-tool: Replace radio buttons by check buttons
For --3to4, replace GtkRadioButton by either GtkCheckButton or GtkToggleButton, depending on the value of :draw-indicator. Update the testsuite to cover this.
This commit is contained in:
parent
b98352de3e
commit
bb6045f02d
@ -1718,6 +1718,58 @@ rewrite_bin_child (Element *element,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
remove_boolean_prop (Element *element,
|
||||
MyParserData *data,
|
||||
const char *prop_name,
|
||||
gboolean *value)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = element->children; l; l = l->next)
|
||||
{
|
||||
Element *child = l->data;
|
||||
|
||||
if (g_str_equal (child->element_name, "property") &&
|
||||
has_attribute (child, "name", prop_name))
|
||||
{
|
||||
*value = strcmp (canonical_boolean_value (data, child->data), "1") == 0;
|
||||
element->children = g_list_remove (element->children, child);
|
||||
free_element (child);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
rewrite_radio_button (Element *element,
|
||||
MyParserData *data)
|
||||
{
|
||||
int i;
|
||||
gboolean draw_indicator = TRUE;
|
||||
const char *new_class;
|
||||
|
||||
if (!remove_boolean_prop (element, data, "draw-indicator", &draw_indicator))
|
||||
remove_boolean_prop (element, data, "draw_indicator", &draw_indicator);
|
||||
|
||||
if (draw_indicator)
|
||||
new_class = "GtkCheckButton";
|
||||
else
|
||||
new_class = "GtkToggleButton";
|
||||
|
||||
for (i = 0; element->attribute_names[i]; i++)
|
||||
{
|
||||
if (strcmp (element->attribute_names[i], "class") == 0)
|
||||
{
|
||||
g_free (element->attribute_values[i]);
|
||||
element->attribute_values[i] = g_strdup (new_class);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* returns TRUE to remove the element from the parent */
|
||||
static gboolean
|
||||
simplify_element (Element *element,
|
||||
@ -1863,6 +1915,10 @@ rewrite_element (Element *element,
|
||||
g_str_equal (get_class_name (element), "GtkWindow")))
|
||||
rewrite_bin_child (element, data);
|
||||
|
||||
if (element_is_object_or_template (element) &&
|
||||
g_str_equal (get_class_name (element), "GtkRadioButton"))
|
||||
rewrite_radio_button (element, data);
|
||||
|
||||
if (g_str_equal (element->element_name, "property"))
|
||||
maybe_rename_property (element, data);
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="button3">
|
||||
<object class="GtkCheckButton" id="button3">
|
||||
<property name="label" translatable="yes">Hello World!</property>
|
||||
<property name="receives_default">1</property>
|
||||
<layout>
|
||||
@ -41,7 +41,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="button4">
|
||||
<object class="GtkCheckButton" id="button4">
|
||||
<property name="label" translatable="yes">Hello World!</property>
|
||||
<property name="active">1</property>
|
||||
<property name="group">button3</property>
|
||||
@ -52,6 +52,17 @@
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="button4a">
|
||||
<property name="label" translatable="yes">Hello World!</property>
|
||||
<property name="group">button4</property>
|
||||
<property name="receives_default">1</property>
|
||||
<layout>
|
||||
<property name="column">3</property>
|
||||
<property name="row">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="button5">
|
||||
<property name="active">1</property>
|
||||
|
@ -57,6 +57,19 @@
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="button4a">
|
||||
<property name="label" translatable="yes">Hello World!</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="group">button4</property>
|
||||
<property name="draw-indicator">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="button5">
|
||||
<property name="visible">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user