[gnome-builder/wip/libide-merge] desensitize widgets when empty



commit b181fd673914e80e8781d79b76d301b67eb3e8e3
Author: Christian Hergert <christian hergert me>
Date:   Thu Mar 19 16:27:59 2015 -0700

    desensitize widgets when empty

 data/ui/gb-view-stack.ui          |    4 +-
 src/views/gb-view-stack-private.h |   26 ++++++++++++----------
 src/views/gb-view-stack.c         |   43 ++++++++++++++++++++++++++++++-------
 3 files changed, 51 insertions(+), 22 deletions(-)
---
diff --git a/data/ui/gb-view-stack.ui b/data/ui/gb-view-stack.ui
index debd2cd..ebfabf7 100644
--- a/data/ui/gb-view-stack.ui
+++ b/data/ui/gb-view-stack.ui
@@ -64,7 +64,7 @@
                   </object>
                 </child>
                 <child type="center">
-                  <object class="GtkMenuButton">
+                  <object class="GtkMenuButton" id="document_button">
                     <property name="hexpand">true</property>
                     <property name="popover">popover</property>
                     <property name="visible">true</property>
@@ -82,7 +82,7 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkButton">
+                  <object class="GtkButton" id="close_button">
                     <property name="action-name">view-stack.close</property>
                     <property name="visible">true</property>
                     <style>
diff --git a/src/views/gb-view-stack-private.h b/src/views/gb-view-stack-private.h
index c837eb2..43c187b 100644
--- a/src/views/gb-view-stack-private.h
+++ b/src/views/gb-view-stack-private.h
@@ -25,23 +25,25 @@ G_BEGIN_DECLS
 
 struct _GbViewStack
 {
-  GtkBin      parent_instance;
+  GtkBin         parent_instance;
 
-  GList      *focus_history;
+  GList         *focus_history;
 
   /* Weak references */
-  GtkWidget  *active_view;
-  GBinding   *title_binding;
+  GtkWidget     *active_view;
+  GBinding      *title_binding;
 
   /* Template references */
-  GtkStack   *controls_stack;
-  GtkButton  *go_backward;
-  GtkButton  *go_forward;
-  GtkPopover *popover;
-  GtkStack   *stack;
-  GtkLabel   *title_label;
-
-  guint       focused : 1;
+  GtkStack      *controls_stack;
+  GtkButton     *close_button;
+  GtkMenuButton *document_button;
+  GtkButton     *go_backward;
+  GtkButton     *go_forward;
+  GtkPopover    *popover;
+  GtkStack      *stack;
+  GtkLabel      *title_label;
+
+  guint          focused : 1;
 };
 
 G_END_DECLS
diff --git a/src/views/gb-view-stack.c b/src/views/gb-view-stack.c
index 364fae6..9f5f580 100644
--- a/src/views/gb-view-stack.c
+++ b/src/views/gb-view-stack.c
@@ -55,6 +55,9 @@ gb_view_stack_add (GtkContainer *container,
     {
       GtkWidget *controls;
 
+      gtk_widget_set_sensitive (GTK_WIDGET (self->close_button), TRUE);
+      gtk_widget_set_sensitive (GTK_WIDGET (self->document_button), TRUE);
+
       self->focus_history = g_list_prepend (self->focus_history, child);
       controls = gb_view_get_controls (GB_VIEW (child));
       if (controls)
@@ -137,6 +140,27 @@ gb_view_stack_grab_focus (GtkWidget *widget)
     gtk_widget_grab_focus (visible_child);
 }
 
+static gboolean
+gb_view_stack_is_empty (GbViewStack *self)
+{
+  g_return_val_if_fail (GB_IS_VIEW_STACK (self), FALSE);
+
+  return (self->focus_history == NULL);
+}
+
+static void
+gb_view_stack_real_empty (GbViewStack *self)
+{
+  g_assert (GB_IS_VIEW_STACK (self));
+
+  /* its possible for a widget to be added during "empty" emission. */
+  if (gb_view_stack_is_empty (self))
+    {
+      gtk_widget_set_sensitive (GTK_WIDGET (self->close_button), FALSE);
+      gtk_widget_set_sensitive (GTK_WIDGET (self->document_button), FALSE);
+    }
+}
+
 static void
 gb_view_stack_constructed (GObject *object)
 {
@@ -222,14 +246,15 @@ gb_view_stack_class_init (GbViewStackClass *klass)
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (object_class, PROP_ACTIVE_VIEW, gParamSpecs [PROP_ACTIVE_VIEW]);
 
-  gSignals [EMPTY] = g_signal_new ("empty",
-                                   G_TYPE_FROM_CLASS (klass),
-                                   G_SIGNAL_RUN_LAST,
-                                   0,
-                                   NULL, NULL,
-                                   g_cclosure_marshal_VOID__VOID,
-                                   G_TYPE_NONE,
-                                   0);
+  gSignals [EMPTY] =
+    g_signal_new_class_handler ("empty",
+                                G_TYPE_FROM_CLASS (klass),
+                                G_SIGNAL_RUN_LAST,
+                                G_CALLBACK (gb_view_stack_real_empty),
+                                NULL, NULL,
+                                g_cclosure_marshal_VOID__VOID,
+                                G_TYPE_NONE,
+                                0);
 
   gSignals [SPLIT] = g_signal_new ("split",
                                    G_TYPE_FROM_CLASS (klass),
@@ -243,7 +268,9 @@ gb_view_stack_class_init (GbViewStackClass *klass)
                                    GB_TYPE_VIEW_GRID_SPLIT);
 
   GB_WIDGET_CLASS_TEMPLATE (klass, "gb-view-stack.ui");
+  GB_WIDGET_CLASS_BIND (klass, GbViewStack, close_button);
   GB_WIDGET_CLASS_BIND (klass, GbViewStack, controls_stack);
+  GB_WIDGET_CLASS_BIND (klass, GbViewStack, document_button);
   GB_WIDGET_CLASS_BIND (klass, GbViewStack, go_backward);
   GB_WIDGET_CLASS_BIND (klass, GbViewStack, go_forward);
   GB_WIDGET_CLASS_BIND (klass, GbViewStack, popover);


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