[gnome-builder/wip/chergert/layout] editor: make IdeEditorSidebar subclass IdeLayoutPane



commit 3c16836494ec3699de74f09e927b8b58b8e2801b
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jul 12 17:22:33 2017 -0700

    editor: make IdeEditorSidebar subclass IdeLayoutPane
    
    This allows us to remove another widget from the hierarchy here.
    The goal is that the panels we use in the editor will be
    subclasses of the IdeLayoutPane with visibility/interactivity
    semantics based on the new design.

 data/themes/shared/shared-editor.css    |    2 +-
 libide/editor/ide-editor-perspective.c  |   33 ++++++--
 libide/editor/ide-editor-perspective.ui |   21 +----
 libide/editor/ide-editor-sidebar.c      |    8 +-
 libide/editor/ide-editor-sidebar.h      |    4 +-
 libide/editor/ide-editor-sidebar.ui     |  134 ++++++++++++++++---------------
 6 files changed, 107 insertions(+), 95 deletions(-)
---
diff --git a/data/themes/shared/shared-editor.css b/data/themes/shared/shared-editor.css
index fa03859..9643ae2 100644
--- a/data/themes/shared/shared-editor.css
+++ b/data/themes/shared/shared-editor.css
@@ -1,4 +1,4 @@
-ideeditorsidebar > stackswitcher {
+ideeditorsidebar > dzldockpaned:first-child stackswitcher {
   margin: 6px;
 }
 ideeditorsidebar .handle {
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 0b04d9b..7537269 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -38,7 +38,6 @@ struct _IdeEditorPerspective
 
   /* Template widgets */
   IdeLayoutGrid       *grid;
-  IdeEditorSidebar    *sidebar;
   IdeEditorProperties *properties;
 
   /* State before entering focus mode */
@@ -94,19 +93,38 @@ ide_editor_perspective_add (GtkContainer *container,
     GTK_CONTAINER_CLASS (ide_editor_perspective_parent_class)->add (container, widget);
 }
 
+static GtkWidget *
+ide_editor_perspective_create_edge (DzlDockBin      *dock_bin,
+                                    GtkPositionType  edge)
+{
+  g_assert (DZL_IS_DOCK_BIN (dock_bin));
+  g_assert (edge >= GTK_POS_LEFT);
+  g_assert (edge <= GTK_POS_BOTTOM);
+
+  if (edge == GTK_POS_LEFT)
+    return g_object_new (IDE_TYPE_EDITOR_SIDEBAR,
+                         "edge", edge,
+                         "reveal-child", FALSE,
+                         "visible", TRUE,
+                         NULL);
+
+  return DZL_DOCK_BIN_CLASS (ide_editor_perspective_parent_class)->create_edge (dock_bin, edge);
+}
+
 static void
 ide_editor_perspective_class_init (IdeEditorPerspectiveClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+  DzlDockBinClass *dock_bin_class = DZL_DOCK_BIN_CLASS (klass);
 
   container_class->add = ide_editor_perspective_add;
 
-  gtk_widget_class_set_template_from_resource (widget_class,
-                                               "/org/gnome/builder/ui/ide-editor-perspective.ui");
+  dock_bin_class->create_edge = ide_editor_perspective_create_edge;
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-editor-perspective.ui");
   gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, grid);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, properties);
-  gtk_widget_class_bind_template_child (widget_class, IdeEditorPerspective, sidebar);
 
   g_type_ensure (IDE_TYPE_EDITOR_PROPERTIES);
   g_type_ensure (IDE_TYPE_EDITOR_SIDEBAR);
@@ -116,9 +134,12 @@ ide_editor_perspective_class_init (IdeEditorPerspectiveClass *klass)
 static void
 ide_editor_perspective_init (IdeEditorPerspective *self)
 {
+  IdeEditorSidebar *sidebar;
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  _ide_editor_sidebar_set_open_pages (self->sidebar, G_LIST_MODEL (self->grid));
+  sidebar = ide_editor_perspective_get_sidebar (self);
+  _ide_editor_sidebar_set_open_pages (sidebar, G_LIST_MODEL (self->grid));
 
   _ide_editor_perspective_init_actions (self);
   _ide_editor_perspective_init_shortcuts (self);
@@ -410,7 +431,7 @@ ide_editor_perspective_get_sidebar (IdeEditorPerspective *self)
 {
   g_return_val_if_fail (IDE_IS_EDITOR_PERSPECTIVE (self), NULL);
 
-  return self->sidebar;
+  return IDE_EDITOR_SIDEBAR (dzl_dock_bin_get_left_edge (DZL_DOCK_BIN (self)));
 }
 
 /**
diff --git a/libide/editor/ide-editor-perspective.ui b/libide/editor/ide-editor-perspective.ui
index 6a9ee99..f58d811 100644
--- a/libide/editor/ide-editor-perspective.ui
+++ b/libide/editor/ide-editor-perspective.ui
@@ -1,28 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="IdeEditorPerspective" parent="IdeLayout">
-    <child internal-child="left">
-      <object class="IdeLayoutPane">
-        <child>
-          <object class="IdeEditorSidebar" id="sidebar">
-            <property name="visible">true</property>
-          </object>
-        </child>
-      </object>
-    </child>
     <child internal-child="right">
-      <object class="IdeLayoutPane">
-        <!-- This is a transient panel -->
+      <object class="IdeLayoutTransientSidebar">
         <property name="reveal-child">false</property>
         <child>
-          <object class="DzlDockWidget">
+          <object class="IdeEditorProperties" id="properties">
+            <property name="sensitive">false</property>
             <property name="visible">true</property>
-            <child>
-              <object class="IdeEditorProperties" id="properties">
-                <property name="sensitive">false</property>
-                <property name="visible">true</property>
-              </object>
-            </child>
           </object>
         </child>
       </object>
diff --git a/libide/editor/ide-editor-sidebar.c b/libide/editor/ide-editor-sidebar.c
index ebec913..85360a6 100644
--- a/libide/editor/ide-editor-sidebar.c
+++ b/libide/editor/ide-editor-sidebar.c
@@ -39,9 +39,10 @@
 
 struct _IdeEditorSidebar
 {
-  GtkBox             parent_instance;
+  IdeLayoutPane      parent_instance;
 
   /* Template widgets */
+  GtkBox            *box;
   GtkStackSwitcher  *stack_switcher;
   GtkListBox        *open_pages_list_box;
   GtkBox            *open_pages_section;
@@ -50,7 +51,7 @@ struct _IdeEditorSidebar
   GtkStack          *stack;
 };
 
-G_DEFINE_TYPE (IdeEditorSidebar, ide_editor_sidebar, GTK_TYPE_BOX)
+G_DEFINE_TYPE (IdeEditorSidebar, ide_editor_sidebar, IDE_TYPE_LAYOUT_PANE)
 
 static void
 ide_editor_sidebar_update_title (IdeEditorSidebar *self)
@@ -122,6 +123,7 @@ ide_editor_sidebar_class_init (IdeEditorSidebarClass *klass)
   widget_class->destroy = ide_editor_sidebar_destroy;
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-editor-sidebar.ui");
+  gtk_widget_class_bind_template_child (widget_class, IdeEditorSidebar, box);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorSidebar, open_pages_list_box);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorSidebar, open_pages_section);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorSidebar, section_menu_button);
@@ -136,8 +138,6 @@ ide_editor_sidebar_init (IdeEditorSidebar *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
-
   g_signal_connect_swapped (self->open_pages_list_box,
                             "row-activated",
                             G_CALLBACK (ide_editor_sidebar_open_pages_row_activated),
diff --git a/libide/editor/ide-editor-sidebar.h b/libide/editor/ide-editor-sidebar.h
index 87f44bb..72250d9 100644
--- a/libide/editor/ide-editor-sidebar.h
+++ b/libide/editor/ide-editor-sidebar.h
@@ -18,13 +18,13 @@
 
 #pragma once
 
-#include <gtk/gtk.h>
+#include "layout/ide-layout-pane.h"
 
 G_BEGIN_DECLS
 
 #define IDE_TYPE_EDITOR_SIDEBAR (ide_editor_sidebar_get_type())
 
-G_DECLARE_FINAL_TYPE (IdeEditorSidebar, ide_editor_sidebar, IDE, EDITOR_SIDEBAR, GtkBox)
+G_DECLARE_FINAL_TYPE (IdeEditorSidebar, ide_editor_sidebar, IDE, EDITOR_SIDEBAR, IdeLayoutPane)
 
 GtkWidget   *ide_editor_sidebar_new            (void);
 const gchar *ide_editor_sidebar_get_section_id (IdeEditorSidebar *self);
diff --git a/libide/editor/ide-editor-sidebar.ui b/libide/editor/ide-editor-sidebar.ui
index a64f0de..7940ce9 100644
--- a/libide/editor/ide-editor-sidebar.ui
+++ b/libide/editor/ide-editor-sidebar.ui
@@ -1,72 +1,31 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="IdeEditorSidebar" parent="GtkBox">
-    <property name="orientation">vertical</property>
+  <template class="IdeEditorSidebar" parent="IdeLayoutPane">
     <child>
-      <object class="GtkStackSwitcher" id="stack_switcher">
-        <property name="halign">fill</property>
-        <property name="hexpand">true</property>
-        <property name="stack">stack</property>
-        <property name="visible">true</property>
-      </object>
-    </child>
-    <child>
-      <object class="DzlMultiPaned">
+      <object class="GtkBox" id="box">
+        <property name="vexpand">true</property>
         <property name="orientation">vertical</property>
         <property name="visible">true</property>
         <child>
-          <object class="GtkBox" id="open_pages_section">
-            <property name="orientation">vertical</property>
-            <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">Open Pages</property>
-                <property name="xalign">0.0</property>
-                <property name="visible">true</property>
-                <style>
-                  <class name="dim-label"/>
-                  <class name="title"/>
-                </style>
-              </object>
-            </child>
-            <child>
-              <object class="DzlElasticBin">
-                <property name="visible">true</property>
-                <child>
-                  <object class="GtkScrolledWindow">
-                    <property name="hscrollbar-policy">never</property>
-                    <property name="propagate-natural-height">true</property>
-                    <property name="min-content-height">30</property>
-                    <property name="visible">true</property>
-                    <child>
-                      <object class="GtkListBox" id="open_pages_list_box">
-                        <property name="selection-mode">none</property>
-                        <property name="visible">true</property>
-                        <style>
-                          <class name="open-pages"/>
-                        </style>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
+          <object class="GtkStackSwitcher" id="stack_switcher">
+            <property name="halign">fill</property>
+            <property name="hexpand">true</property>
+            <property name="stack">stack</property>
+            <property name="visible">true</property>
           </object>
         </child>
         <child>
-          <object class="GtkBox">
-            <property name="vexpand">true</property>
+          <object class="DzlMultiPaned">
             <property name="orientation">vertical</property>
             <property name="visible">true</property>
             <child>
-              <object class="GtkBox">
-                <property name="orientation">horizontal</property>
-                <property name="spacing">6</property>
-                <property name="visible">true</property>
+              <object class="GtkBox" id="open_pages_section">
+                <property name="orientation">vertical</property>
                 <child>
-                  <object class="GtkLabel" id="section_title">
-                    <property name="hexpand">true</property>
-                    <property name="visible">true</property>
+                  <object class="GtkLabel">
+                    <property name="label" translatable="yes">Open Pages</property>
                     <property name="xalign">0.0</property>
+                    <property name="visible">true</property>
                     <style>
                       <class name="dim-label"/>
                       <class name="title"/>
@@ -74,14 +33,23 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkMenuButton" id="section_menu_button">
-                    <style>
-                      <class name="image-button"/>
-                      <class name="flat"/>
-                    </style>
+                  <object class="DzlElasticBin">
+                    <property name="visible">true</property>
                     <child>
-                      <object class="GtkImage" id="section_image">
+                      <object class="GtkScrolledWindow">
+                        <property name="hscrollbar-policy">never</property>
+                        <property name="propagate-natural-height">true</property>
+                        <property name="min-content-height">30</property>
                         <property name="visible">true</property>
+                        <child>
+                          <object class="GtkListBox" id="open_pages_list_box">
+                            <property name="selection-mode">none</property>
+                            <property name="visible">true</property>
+                            <style>
+                              <class name="open-pages"/>
+                            </style>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
@@ -89,11 +57,49 @@
               </object>
             </child>
             <child>
-              <object class="GtkStack" id="stack">
-                <property name="interpolate-size">false</property>
-                <property name="homogeneous">false</property>
+              <object class="GtkBox">
                 <property name="vexpand">true</property>
+                <property name="orientation">vertical</property>
                 <property name="visible">true</property>
+                <child>
+                  <object class="GtkBox">
+                    <property name="orientation">horizontal</property>
+                    <property name="spacing">6</property>
+                    <property name="visible">true</property>
+                    <child>
+                      <object class="GtkLabel" id="section_title">
+                        <property name="hexpand">true</property>
+                        <property name="visible">true</property>
+                        <property name="xalign">0.0</property>
+                        <style>
+                          <class name="dim-label"/>
+                          <class name="title"/>
+                        </style>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkMenuButton" id="section_menu_button">
+                        <style>
+                          <class name="image-button"/>
+                          <class name="flat"/>
+                        </style>
+                        <child>
+                          <object class="GtkImage" id="section_image">
+                            <property name="visible">true</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkStack" id="stack">
+                    <property name="interpolate-size">false</property>
+                    <property name="homogeneous">false</property>
+                    <property name="vexpand">true</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>


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