summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <juanpablougarte@gmail.com>2018-07-26 16:58:42 -0300
committerJuan Pablo Ugarte <juanpablougarte@gmail.com>2018-07-26 17:00:27 -0300
commit225f6f39699331d7fcc52768cd4da93173363f52 (patch)
tree21c6c6213d9dff8257081a8eee9b715bb5cc600c /plugins
parent02e660484d1553d74e8f41cd6f19b17a331117c3 (diff)
downloadglade-225f6f39699331d7fcc52768cd4da93173363f52.tar.gz
GladeGtkBox: improve children sort function
If the are two children with the same position, sort alphabetically by name.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gtk+/glade-gtk-box.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/plugins/gtk+/glade-gtk-box.c b/plugins/gtk+/glade-gtk-box.c
index 7074b54d..01758f14 100644
--- a/plugins/gtk+/glade-gtk-box.c
+++ b/plugins/gtk+/glade-gtk-box.c
@@ -98,9 +98,7 @@ sort_box_children (GtkWidget * widget_a, GtkWidget * widget_b, GtkWidget *box)
{
GladeWidget *gwidget_a, *gwidget_b;
gint position_a, position_b;
-
- gwidget_a = glade_widget_get_from_gobject (widget_a);
- gwidget_b = glade_widget_get_from_gobject (widget_b);
+ GtkWidget *center;
/* Indirect children might be internal children, sort internal children before any other children */
if (box != gtk_widget_get_parent (widget_a))
@@ -108,24 +106,31 @@ sort_box_children (GtkWidget * widget_a, GtkWidget * widget_b, GtkWidget *box)
if (box != gtk_widget_get_parent (widget_b))
return 1;
- if (gtk_box_get_center_widget (GTK_BOX (box)) == widget_a)
- return -1;
- if (gtk_box_get_center_widget (GTK_BOX (box)) == widget_b)
+ center = gtk_box_get_center_widget (GTK_BOX (box));
+ if (center == widget_a)
return -1;
+ if (center == widget_b)
+ return 1;
- /* XXX Sometimes the packing "position" property doesnt exist here, why ?
- */
- if (gwidget_a)
- glade_widget_pack_property_get (gwidget_a, "position", &position_a);
- else
- gtk_container_child_get (GTK_CONTAINER (box),
- widget_a, "position", &position_a, NULL);
+ if ((gwidget_a = glade_widget_get_from_gobject (widget_a)) &&
+ (gwidget_b = glade_widget_get_from_gobject (widget_b)))
+ {
+ glade_widget_pack_property_get (gwidget_a, "position", &position_a);
+ glade_widget_pack_property_get (gwidget_b, "position", &position_b);
- if (gwidget_b)
- glade_widget_pack_property_get (gwidget_b, "position", &position_b);
+ /* If position is the same, try to give an stable order */
+ if (position_a == position_b)
+ return g_strcmp0 (glade_widget_get_name (gwidget_a),
+ glade_widget_get_name (gwidget_b));
+ }
else
- gtk_container_child_get (GTK_CONTAINER (box),
- widget_b, "position", &position_b, NULL);
+ {
+ gtk_container_child_get (GTK_CONTAINER (box),
+ widget_a, "position", &position_a, NULL);
+ gtk_container_child_get (GTK_CONTAINER (box),
+ widget_b, "position", &position_b, NULL);
+ }
+
return position_a - position_b;
}