[gnome-builder/wip/chergert/perspective] libide: sort perspectives by their priority
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] libide: sort perspectives by their priority
- Date: Tue, 17 Nov 2015 07:02:26 +0000 (UTC)
commit cc28a6ff6447a42419dadefd06ee3f8fbd354f51
Author: Christian Hergert <chergert redhat com>
Date: Mon Nov 16 23:02:00 2015 -0800
libide: sort perspectives by their priority
libide/ide-workbench.c | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-workbench.c b/libide/ide-workbench.c
index 268b49f..2e76a9b 100644
--- a/libide/ide-workbench.c
+++ b/libide/ide-workbench.c
@@ -65,6 +65,41 @@ ide_workbench_notify_visible_child (IdeWorkbench *self,
}
}
+static gint
+ide_workbench_compare_perspective (gconstpointer a,
+ gconstpointer b)
+{
+ IdePerspective *perspective_a = (IdePerspective *)a;
+ IdePerspective *perspective_b = (IdePerspective *)b;
+
+ return (ide_perspective_get_priority (perspective_a) -
+ ide_perspective_get_priority (perspective_b));
+}
+
+static void
+ide_workbench_resort_perspectives (IdeWorkbench *self)
+{
+ GList *children;
+ const GList *iter;
+ gint i = 0;
+
+ g_assert (IDE_IS_WORKBENCH (self));
+
+ children = gtk_container_get_children (GTK_CONTAINER (self->perspectives_stack));
+ children = g_list_sort (children, ide_workbench_compare_perspective);
+
+ for (iter = children; iter; iter = iter->next, i++)
+ {
+ GtkWidget *child = iter->data;
+
+ gtk_container_child_set (GTK_CONTAINER (self->perspectives_stack), child,
+ "position", i,
+ NULL);
+ }
+
+ g_list_free (children);
+}
+
static void
ide_workbench_finalize (GObject *object)
{
@@ -400,6 +435,8 @@ ide_workbench_add_perspective (IdeWorkbench *self,
gtk_container_add_with_properties (GTK_CONTAINER (self->titlebar_stack), titlebar,
"name", id,
NULL);
+
+ ide_workbench_resort_perspectives (self);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]