[gnome-builder/wip/command-bar-slider: 2/2] workbench: port command-bar to GbSlider



commit 3f4b30cf209ac5eea6fabcb9d99719b1734ab98e
Author: Christian Hergert <christian hergert me>
Date:   Tue Jun 16 03:36:33 2015 -0700

    workbench: port command-bar to GbSlider

 data/ui/gb-workbench.ui               |    5 +--
 plugins/command-bar/gb-command-bar.c  |   43 +++++++++++++++++---------------
 plugins/command-bar/gb-command-bar.h  |    2 +-
 plugins/command-bar/gb-command-bar.ui |    6 +----
 src/workbench/gb-workbench-private.h  |    2 +
 src/workbench/gb-workbench.c          |   10 +++++++
 src/workbench/gb-workbench.h          |    1 +
 7 files changed, 40 insertions(+), 29 deletions(-)
---
diff --git a/data/ui/gb-workbench.ui b/data/ui/gb-workbench.ui
index da91d32..5b1bb8d 100644
--- a/data/ui/gb-workbench.ui
+++ b/data/ui/gb-workbench.ui
@@ -93,11 +93,10 @@
       </object>
     </child>
     <child>
-      <object class="GtkBox">
-        <property name="orientation">vertical</property>
+      <object class="GtkEventBox">
         <property name="visible">true</property>
         <child>
-          <object class="GtkEventBox">
+          <object class="GbSlider" id="slider">
             <property name="visible">true</property>
             <child>
               <object class="GbWorkspace" id="workspace">
diff --git a/plugins/command-bar/gb-command-bar.c b/plugins/command-bar/gb-command-bar.c
index 4e5038b..653c948 100644
--- a/plugins/command-bar/gb-command-bar.c
+++ b/plugins/command-bar/gb-command-bar.c
@@ -26,6 +26,7 @@
 #include "gb-command-manager.h"
 #include "gb-command-vim-provider.h"
 #include "gb-glib.h"
+#include "gb-slider.h"
 #include "gb-string.h"
 #include "gb-view-stack.h"
 #include "gb-widget.h"
@@ -35,7 +36,7 @@
 
 struct _GbCommandBar
 {
-  GtkRevealer        parent_instance;
+  GtkBin             parent_instance;
 
   GbWorkbench       *workbench;
   GbCommandManager  *command_manager;
@@ -61,7 +62,7 @@ struct _GbCommandBar
 
 static void workbench_addin_init (GbWorkbenchAddinInterface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GbCommandBar, gb_command_bar, GTK_TYPE_REVEALER,
+G_DEFINE_TYPE_WITH_CODE (GbCommandBar, gb_command_bar, GTK_TYPE_BIN,
                          G_IMPLEMENT_INTERFACE (GB_TYPE_WORKBENCH_ADDIN, workbench_addin_init))
 
 #define HISTORY_LENGTH 30
@@ -86,7 +87,7 @@ gb_command_bar_load (GbWorkbenchAddin *addin)
 {
   GbCommandBar *self = (GbCommandBar *)addin;
   GbCommandProvider *provider;
-  GtkWidget *child;
+  GtkWidget *slider;
 
   g_assert (GB_IS_COMMAND_BAR (self));
 
@@ -102,10 +103,14 @@ gb_command_bar_load (GbWorkbenchAddin *addin)
   gb_command_manager_add_provider (self->command_manager, provider);
   g_clear_object (&provider);
 
-  child = gtk_bin_get_child (GTK_BIN (self->workbench));
-  gtk_box_pack_end (GTK_BOX (child), GTK_WIDGET (self), FALSE, FALSE, 0);
+  slider = gb_workbench_get_slider (self->workbench);
+  gtk_container_add_with_properties (GTK_CONTAINER (slider), GTK_WIDGET (self),
+                                     "position", GB_SLIDER_BOTTOM,
+                                     NULL);
 
   g_action_map_add_action (G_ACTION_MAP (self->workbench), G_ACTION (self->show_action));
+
+  gtk_widget_show (GTK_WIDGET (self));
 }
 
 static void
@@ -169,24 +174,21 @@ find_alternate_focus (GtkWidget *focus)
 void
 gb_command_bar_hide (GbCommandBar *self)
 {
-  GtkWidget *toplevel;
   GtkWidget *focus;
+  GbSlider *slider;
 
   g_return_if_fail (GB_IS_COMMAND_BAR (self));
 
-  if (!gtk_revealer_get_reveal_child (GTK_REVEALER (self)))
+  slider = GB_SLIDER (gb_workbench_get_slider (self->workbench));
+  if (gb_slider_get_position (slider) != GB_SLIDER_BOTTOM)
     return;
 
-  gtk_revealer_set_reveal_child (GTK_REVEALER (self), FALSE);
-
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
-  if ((toplevel == NULL) || gtk_widget_in_destruction (toplevel))
-    return;
+  gb_slider_set_position (slider, GB_SLIDER_NONE);
 
   if (self->last_focus)
     focus = find_alternate_focus (self->last_focus);
   else
-    focus = toplevel;
+    focus = GTK_WIDGET (self->workbench);
 
   gtk_widget_grab_focus (focus);
 }
@@ -210,16 +212,19 @@ gb_command_bar_set_last_focus (GbCommandBar *self,
 void
 gb_command_bar_show (GbCommandBar *self)
 {
-  GtkWidget *toplevel;
   GtkWidget *focus;
+  GbSlider *slider;
 
   g_return_if_fail (GB_IS_COMMAND_BAR (self));
 
-  if (gtk_revealer_get_reveal_child (GTK_REVEALER (self)))
+  slider = GB_SLIDER (gb_workbench_get_slider (self->workbench));
+
+  if (gb_slider_get_position (slider) == GB_SLIDER_BOTTOM)
     return;
 
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
-  focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
+  gb_slider_set_position (slider, GB_SLIDER_BOTTOM);
+
+  focus = gtk_window_get_focus (GTK_WINDOW (self->workbench));
   gb_command_bar_set_last_focus (self, focus);
 
   gtk_widget_hide (GTK_WIDGET (self->completion_scroller));
@@ -228,7 +233,6 @@ gb_command_bar_show (GbCommandBar *self)
   g_clear_pointer (&self->saved_text, g_free);
   self->saved_position_valid = FALSE;
 
-  gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
   gtk_entry_set_text (self->entry, "");
   gtk_widget_grab_focus (GTK_WIDGET (self->entry));
 }
@@ -538,8 +542,7 @@ show_command_bar (GSimpleAction *action,
                   GVariant      *param,
                   GbCommandBar  *self)
 {
-  gtk_revealer_set_reveal_child (GTK_REVEALER (self), TRUE);
-  gtk_widget_grab_focus (GTK_WIDGET (self->entry));
+  gb_command_bar_show (self);
 }
 
 static gboolean
diff --git a/plugins/command-bar/gb-command-bar.h b/plugins/command-bar/gb-command-bar.h
index 71a6d0a..83703e9 100644
--- a/plugins/command-bar/gb-command-bar.h
+++ b/plugins/command-bar/gb-command-bar.h
@@ -25,7 +25,7 @@ G_BEGIN_DECLS
 
 #define GB_TYPE_COMMAND_BAR (gb_command_bar_get_type())
 
-G_DECLARE_FINAL_TYPE (GbCommandBar, gb_command_bar, GB, COMMAND_BAR, GtkRevealer)
+G_DECLARE_FINAL_TYPE (GbCommandBar, gb_command_bar, GB, COMMAND_BAR, GtkBin)
 
 GtkWidget *gb_command_bar_new  (void);
 void       gb_command_bar_show (GbCommandBar *bar);
diff --git a/plugins/command-bar/gb-command-bar.ui b/plugins/command-bar/gb-command-bar.ui
index 86e7851..f5c997e 100644
--- a/plugins/command-bar/gb-command-bar.ui
+++ b/plugins/command-bar/gb-command-bar.ui
@@ -1,11 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.8 -->
-  <template class="GbCommandBar" parent="GtkRevealer">
-    <property name="visible">True</property>
-    <property name="reveal-child">False</property>
-    <property name="can-focus">False</property>
-    <property name="transition-type">slide-up</property>
+  <template class="GbCommandBar" parent="GtkBin">
     <child>
       <object class="GtkBox" id="vbox1">
         <property name="visible">True</property>
diff --git a/src/workbench/gb-workbench-private.h b/src/workbench/gb-workbench-private.h
index da7a349..1ffd7e9 100644
--- a/src/workbench/gb-workbench-private.h
+++ b/src/workbench/gb-workbench-private.h
@@ -26,6 +26,7 @@
 
 #include "gb-project-tree.h"
 #include "gb-search-box.h"
+#include "gb-slider.h"
 #include "gb-view-grid.h"
 #include "gb-workbench-types.h"
 #include "gb-workspace.h"
@@ -46,6 +47,7 @@ struct _GbWorkbench
   GeditMenuStackSwitcher *gear_menu_button;
   GbProjectTree          *project_tree;
   GbSearchBox            *search_box;
+  GbSlider               *slider;
   GbViewGrid             *view_grid;
   GbWorkspace            *workspace;
 
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 6e75c8a..29912b6 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -642,12 +642,14 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
   GB_WIDGET_CLASS_TEMPLATE (klass, "gb-workbench.ui");
   GB_WIDGET_CLASS_BIND (klass, GbWorkbench, gear_menu_button);
   GB_WIDGET_CLASS_BIND (klass, GbWorkbench, search_box);
+  GB_WIDGET_CLASS_BIND (klass, GbWorkbench, slider);
   GB_WIDGET_CLASS_BIND (klass, GbWorkbench, workspace);
   GB_WIDGET_CLASS_BIND (klass, GbWorkbench, project_tree);
   GB_WIDGET_CLASS_BIND (klass, GbWorkbench, view_grid);
 
   g_type_ensure (GB_TYPE_PROJECT_TREE);
   g_type_ensure (GB_TYPE_SEARCH_BOX);
+  g_type_ensure (GB_TYPE_SLIDER);
   g_type_ensure (GB_TYPE_VIEW_GRID);
   g_type_ensure (GB_TYPE_WORKSPACE);
   g_type_ensure (GB_TYPE_WORKSPACE_PANE);
@@ -1067,3 +1069,11 @@ gb_workbench_reveal_file (GbWorkbench *self,
   gb_tree_scroll_to_node (tree, node);
   gb_tree_node_select (node);
 }
+
+GtkWidget *
+gb_workbench_get_slider (GbWorkbench *self)
+{
+  g_return_val_if_fail (GB_IS_WORKBENCH (self), NULL);
+
+  return GTK_WIDGET (self->slider);
+}
diff --git a/src/workbench/gb-workbench.h b/src/workbench/gb-workbench.h
index 67ebb77..4297fb4 100644
--- a/src/workbench/gb-workbench.h
+++ b/src/workbench/gb-workbench.h
@@ -50,6 +50,7 @@ void              gb_workbench_views_foreach        (GbWorkbench         *self,
                                                      gpointer             callback_data);
 GtkWidget        *gb_workbench_get_workspace        (GbWorkbench         *self);
 GtkWidget        *gb_workbench_get_view_grid        (GbWorkbench         *self);
+GtkWidget        *gb_workbench_get_slider           (GbWorkbench         *self);
 void              gb_workbench_reveal_file          (GbWorkbench         *self,
                                                      GFile               *file);
 


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