diff --git a/gtk/tools/gtk-builder-tool-simplify.c b/gtk/tools/gtk-builder-tool-simplify.c index 449a367aff..4287c1631a 100644 --- a/gtk/tools/gtk-builder-tool-simplify.c +++ b/gtk/tools/gtk-builder-tool-simplify.c @@ -721,15 +721,19 @@ maybe_rename_property (Element *element, MyParserData *data) struct _Prop { const char *class; const char *property; + GType type; PropKind kind; const char *new_name; + const char *alt_names[3]; } props[] = { - { "GtkPopover", "modal", PROP_KIND_OBJECT, "autohide" }, + { "GtkPopover", "modal", GTK_TYPE_POPOVER, PROP_KIND_OBJECT, "autohide", { NULL, NULL, NULL } }, + { "GtkWidget", "expand", GTK_TYPE_WIDGET, PROP_KIND_OBJECT, "hexpand", { "vexpand", NULL, NULL } }, + { "GtkWidget", "margin", GTK_TYPE_WIDGET, PROP_KIND_OBJECT, "margin-left", { "margin-top", "margin-right", "margin-bottom" } }, }; - char *canonical_name; - int i, k; + int i, k, l; PropKind kind; int prop_name_index = 0; + GParamSpec *pspec; kind = get_prop_kind (element); @@ -748,22 +752,41 @@ maybe_rename_property (Element *element, MyParserData *data) if (property_name == NULL) return; - canonical_name = g_strdup (property_name); - g_strdelimit (canonical_name, "_", '-'); + pspec = get_property_pspec (data, class_name, property_name, kind); + if (pspec == NULL) + return; for (k = 0; k < G_N_ELEMENTS (props); k++) { - if (strcmp (class_name, props[k].class) == 0 && - strcmp (canonical_name, props[k].property) == 0 && + if (pspec->owner_type == props[k].type && + strcmp (pspec->name, props[k].property) == 0 && kind == props[k].kind) { g_free (element->attribute_values[prop_name_index]); element->attribute_values[prop_name_index] = g_strdup (props[k].new_name); + for (l = 0; l < 3 && props[k].alt_names[l]; l++) + { + Element *elt; + GList *sibling; + + elt = g_new0 (Element, 1); + elt->parent = element->parent; + elt->element_name = g_strdup (element->element_name); + elt->attribute_names = g_strdupv ((char **)element->attribute_names); + elt->attribute_values = g_strdupv ((char **)element->attribute_values); + elt->data = g_strdup (element->data); + + g_free (elt->attribute_values[prop_name_index]); + elt->attribute_values[prop_name_index] = g_strdup (props[k].alt_names[l]); + + sibling = g_list_find (element->parent->children, element); + element->parent->children = g_list_insert_before (element->parent->children, + sibling, + elt); + } break; } } - - g_free (canonical_name); } static Element *