[gnome-builder/wip/chergert/layout: 54/118] editor: add priorities to sidebar sections



commit 227813128689918e6b5460320bc4a6524849e1f2
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 30 20:55:17 2017 -0700

    editor: add priorities to sidebar sections
    
    This ensures we get the proper sorting order. We also try to
    ensure the first child stays selected for when the window is
    created. Not an ideal solution, but it works.

 libide/buildui/ide-build-workbench-addin.c   |    3 +-
 libide/editor/ide-editor-sidebar.c           |   47 ++++++++++++++++++++++++-
 libide/editor/ide-editor-sidebar.h           |    3 +-
 plugins/project-tree/gb-project-tree-addin.c |    3 +-
 plugins/todo/gbp-todo-workbench-addin.c      |    3 +-
 5 files changed, 53 insertions(+), 6 deletions(-)
---
diff --git a/libide/buildui/ide-build-workbench-addin.c b/libide/buildui/ide-build-workbench-addin.c
index c5d460f..c146b5c 100644
--- a/libide/buildui/ide-build-workbench-addin.c
+++ b/libide/buildui/ide-build-workbench-addin.c
@@ -170,7 +170,8 @@ ide_build_workbench_addin_load (IdeWorkbenchAddin *addin,
                                   _("Build Issues"),
                                   "builder-build-symbolic",
                                   NULL, NULL,
-                                  GTK_WIDGET (self->panel));
+                                  GTK_WIDGET (self->panel),
+                                  100);
 
   pane = ide_editor_perspective_get_bottom_edge (IDE_EDITOR_PERSPECTIVE (editor));
   self->build_log_panel = g_object_new (IDE_TYPE_BUILD_LOG_PANEL, NULL);
diff --git a/libide/editor/ide-editor-sidebar.c b/libide/editor/ide-editor-sidebar.c
index 07000df..ebec913 100644
--- a/libide/editor/ide-editor-sidebar.c
+++ b/libide/editor/ide-editor-sidebar.c
@@ -177,6 +177,32 @@ fixup_stack_switcher_button (GtkWidget *widget,
   gtk_widget_set_hexpand (widget, TRUE);
 }
 
+static gint
+find_position (IdeEditorSidebar *self,
+               gint              priority)
+{
+  GList *children;
+  gint position = 0;
+
+  children = gtk_container_get_children (GTK_CONTAINER (self->stack));
+
+  for (const GList *iter = children; iter != NULL; iter = iter->next)
+    {
+      GtkWidget *widget = iter->data;
+      gint widget_prio = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
+                                                             "IDE_EDITOR_SIDEBAR_PRIORITY"));
+
+      if (widget_prio > priority)
+        break;
+
+      position++;
+    }
+
+  g_list_free (children);
+
+  return position;
+}
+
 /**
  * ide_editor_sidebar_add_section:
  * @self: a #IdeEditorSidebar
@@ -205,14 +231,21 @@ ide_editor_sidebar_add_section (IdeEditorSidebar *self,
                                 const gchar      *icon_name,
                                 const gchar      *menu_id,
                                 const gchar      *menu_icon_name,
-                                GtkWidget        *section)
+                                GtkWidget        *section,
+                                gint              priority)
 {
+  gint position;
+
   g_return_if_fail (IDE_IS_EDITOR_SIDEBAR (self));
   g_return_if_fail (title != NULL);
   g_return_if_fail (icon_name != NULL);
   g_return_if_fail (GTK_IS_WIDGET (section));
 
   g_object_set_data (G_OBJECT (section),
+                     "IDE_EDITOR_SIDEBAR_PRIORITY",
+                     GINT_TO_POINTER (priority));
+
+  g_object_set_data (G_OBJECT (section),
                      "IDE_EDITOR_SIDEBAR_MENU_ID",
                      (gpointer) g_intern_string (menu_id));
 
@@ -220,10 +253,13 @@ ide_editor_sidebar_add_section (IdeEditorSidebar *self,
                      "IDE_EDITOR_SIDEBAR_MENU_ICON_NAME",
                      (gpointer) g_intern_string (menu_icon_name));
 
+  position = find_position (self, priority);
+
   gtk_container_add_with_properties (GTK_CONTAINER (self->stack), section,
+                                     "icon-name", icon_name,
                                      "name", id,
+                                     "position", position,
                                      "title", title,
-                                     "icon-name", icon_name,
                                      NULL);
 
   gtk_container_foreach (GTK_CONTAINER (self->stack_switcher),
@@ -231,6 +267,13 @@ ide_editor_sidebar_add_section (IdeEditorSidebar *self,
                          NULL);
 
   ide_editor_sidebar_update_title (self);
+
+  /* Whenever we add a position 0, select it. We don't
+   * have an otherwise good hueristic to ensure that our
+   * first panel is selected at startup.
+   */
+  if (position == 0)
+    gtk_stack_set_visible_child (self->stack, section);
 }
 
 /**
diff --git a/libide/editor/ide-editor-sidebar.h b/libide/editor/ide-editor-sidebar.h
index bf3a88c..87f44bb 100644
--- a/libide/editor/ide-editor-sidebar.h
+++ b/libide/editor/ide-editor-sidebar.h
@@ -36,6 +36,7 @@ void         ide_editor_sidebar_add_section    (IdeEditorSidebar *self,
                                                 const gchar      *icon_name,
                                                 const gchar      *menu_id,
                                                 const gchar      *menu_icon_name,
-                                                GtkWidget        *section);
+                                                GtkWidget        *section,
+                                                gint              priority);
 
 G_END_DECLS
diff --git a/plugins/project-tree/gb-project-tree-addin.c b/plugins/project-tree/gb-project-tree-addin.c
index 9fb6031..b39b3e2 100644
--- a/plugins/project-tree/gb-project-tree-addin.c
+++ b/plugins/project-tree/gb-project-tree-addin.c
@@ -86,7 +86,8 @@ gb_project_tree_addin_load (IdeWorkbenchAddin *addin,
                                   _("Project Tree"),
                                   "view-list-symbolic",
                                   NULL, NULL,
-                                  GTK_WIDGET (scroller));
+                                  GTK_WIDGET (scroller),
+                                  0);
 
   ide_widget_set_context_handler (self->tree, gb_project_tree_addin_context_set);
 
diff --git a/plugins/todo/gbp-todo-workbench-addin.c b/plugins/todo/gbp-todo-workbench-addin.c
index 60ef645..95e6981 100644
--- a/plugins/todo/gbp-todo-workbench-addin.c
+++ b/plugins/todo/gbp-todo-workbench-addin.c
@@ -115,7 +115,8 @@ gbp_todo_workbench_addin_load (IdeWorkbenchAddin *addin,
                                   _("TODO/FIXMEs"),
                                   "emblem-ok-symbolic",
                                   NULL, NULL,
-                                  GTK_WIDGET (self->panel));
+                                  GTK_WIDGET (self->panel),
+                                  200);
 
   gbp_todo_model_mine_async (self->model,
                              workdir,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]