[glade/headerbar: 6/8] GtkHeaderBar: Fixed property sensitivity issues



commit dfccf4b692c72208add5cf19bc854a576988e95a
Author: Tristan Van Berkom <tristan upstairslabs com>
Date:   Wed Nov 5 18:38:55 2014 +0900

    GtkHeaderBar: Fixed property sensitivity issues
    
    The custom editor was calling glade_widget_property_set_sensitive()
    directly which does not work with undo/redo.
    
    Cleaned up the editor and adaptor so that the editor issues commands
    and the adaptor->set_property() adjusts property sensitivity when
    'show-close-button' and 'use-custom-title' properties change.
    
    Also some minor changes to the gtk+.xml.in, no need for the
    decoration layout property to be optional really, since the property
    is a string and will not be saved if it's not set.

 plugins/gtk+/glade-gtk-header-bar.c    |   91 ++++++++++++++++++++++----------
 plugins/gtk+/glade-header-bar-editor.c |   54 ++++++++++++-------
 plugins/gtk+/gtk+.xml.in               |    4 +-
 3 files changed, 98 insertions(+), 51 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-header-bar.c b/plugins/gtk+/glade-gtk-header-bar.c
index d462b59..a7bf6c3 100644
--- a/plugins/gtk+/glade-gtk-header-bar.c
+++ b/plugins/gtk+/glade-gtk-header-bar.c
@@ -5,6 +5,8 @@
 
 #include "glade-header-bar-editor.h"
 
+#define TITLE_DISABLED_MESSAGE _("This property does not apply when a custom title is set")
+
 static gint
 glade_gtk_header_bar_get_num_children (GObject *hb, GtkPackType type)
 {
@@ -292,41 +294,74 @@ glade_gtk_header_bar_set_size (GObject * object,
 }
 
 void
+glade_gtk_header_bar_set_use_custom_title (GObject *object,
+                                          gboolean use_custom_title)
+{
+  GladeWidget *gwidget = glade_widget_get_from_gobject (object);
+  GtkWidget *child;
+
+  if (use_custom_title)
+    {
+      child = gtk_header_bar_get_custom_title (GTK_HEADER_BAR (object));
+      if (!child)
+       {
+         child = glade_placeholder_new ();
+         g_object_set_data (G_OBJECT (child), "special-child-type", "title");
+       }
+    }
+  else
+    child = NULL;
+
+  gtk_header_bar_set_custom_title (GTK_HEADER_BAR (object), child);
+
+  if (GLADE_IS_PLACEHOLDER (child))
+    {
+      GList *list, *l;
+
+      list = glade_placeholder_packing_actions (GLADE_PLACEHOLDER (child));
+      for (l = list; l; l = l->next)
+       {
+         GladeWidgetAction *gwa = l->data;
+         if (!strcmp (glade_widget_action_get_class (gwa)->id, "remove_slot"))
+           glade_widget_action_set_visible (gwa, FALSE);
+       }
+    }
+
+  if (use_custom_title)
+    {
+      glade_widget_property_set_sensitive (gwidget, "title", FALSE, TITLE_DISABLED_MESSAGE);
+      glade_widget_property_set_sensitive (gwidget, "subtitle", FALSE, TITLE_DISABLED_MESSAGE);
+      glade_widget_property_set_sensitive (gwidget, "has-subtitle", FALSE, TITLE_DISABLED_MESSAGE);
+    }
+  else
+    {
+      glade_widget_property_set_sensitive (gwidget, "title", TRUE, NULL);
+      glade_widget_property_set_sensitive (gwidget, "subtitle", TRUE, NULL);
+      glade_widget_property_set_sensitive (gwidget, "has-subtitle", TRUE, NULL);
+    }
+}
+
+void
 glade_gtk_header_bar_set_property (GladeWidgetAdaptor * adaptor,
                                    GObject * object,
                                    const gchar * id,
                                    const GValue * value)
 {
   if (!strcmp (id, "use-custom-title"))
+    glade_gtk_header_bar_set_use_custom_title (object, g_value_get_boolean (value));
+  else if (!strcmp (id, "show-close-button"))
     {
-      GtkWidget *child;
-
-      if (g_value_get_boolean (value))
-        {
-          child = gtk_header_bar_get_custom_title (GTK_HEADER_BAR (object));
-          if (!child)
-            {
-              child = glade_placeholder_new ();
-              g_object_set_data (G_OBJECT (child), "special-child-type", "title");
-            }
-        }
-      else
-        child = NULL;
-
-      gtk_header_bar_set_custom_title (GTK_HEADER_BAR (object), child);
-
-      if (GLADE_IS_PLACEHOLDER (child))
-        {
-          GList *list, *l;
-
-          list = glade_placeholder_packing_actions (GLADE_PLACEHOLDER (child));
-          for (l = list; l; l = l->next)
-            {
-              GladeWidgetAction *gwa = l->data;
-              if (!strcmp (glade_widget_action_get_class (gwa)->id, "remove_slot"))
-                glade_widget_action_set_visible (gwa, FALSE);
-            }
-        }
+      GladeWidget *gwidget = glade_widget_get_from_gobject (object);
+
+      /* We don't set the property to 'ignore' so that we catch this in the adaptor,
+       * but we also do not apply the property to the runtime object here, thus
+       * avoiding showing the close button which would in turn close glade itself
+       * when clicked.
+       */
+      glade_widget_property_set_sensitive (gwidget, "decoration-layout",
+                                          g_value_get_boolean (value),
+                                          _("The decoration layout does not apply to header bars "
+                                            "which do no show window controls"));
     }
   else if (!strcmp (id, "start-size"))
     glade_gtk_header_bar_set_size (object, value, GTK_PACK_START);
diff --git a/plugins/gtk+/glade-header-bar-editor.c b/plugins/gtk+/glade-header-bar-editor.c
index 37ef06b..48a7da6 100644
--- a/plugins/gtk+/glade-header-bar-editor.c
+++ b/plugins/gtk+/glade-header-bar-editor.c
@@ -26,8 +26,6 @@
 
 #include "glade-header-bar-editor.h"
 
-#define TITLE_DISABLED_MESSAGE _("This property does not apply when a custom title is set")
-
 static void glade_header_bar_editor_editable_init (GladeEditableIface * iface);
 static void glade_header_bar_editor_grab_focus    (GtkWidget          * widget);
 
@@ -149,29 +147,23 @@ use_custom_title_toggled (GtkWidget            *widget,
       glade_command_delete (&list);
     }
 
-  property = glade_widget_get_property (gwidget, "use-custom-title");
-  glade_command_set_property (property, use_custom_title);
-
   if (use_custom_title)
     {
-      glade_widget_property_set (gwidget, "title", NULL);
-      glade_widget_property_set (gwidget, "subtitle", NULL);
-      glade_widget_property_set (gwidget, "has-subtitle", TRUE);
-      glade_widget_property_set_sensitive (gwidget, "title", FALSE, TITLE_DISABLED_MESSAGE);
-      glade_widget_property_set_sensitive (gwidget, "subtitle", FALSE, TITLE_DISABLED_MESSAGE);
-      glade_widget_property_set_sensitive (gwidget, "has-subtitle", FALSE, TITLE_DISABLED_MESSAGE);
-    }
-  else
-    {
-      glade_widget_property_set_sensitive (gwidget, "title", TRUE, NULL);
-      glade_widget_property_set_sensitive (gwidget, "subtitle", TRUE, NULL);
-      glade_widget_property_set_sensitive (gwidget, "has-subtitle", TRUE, NULL);
+      property = glade_widget_get_property (gwidget, "title");
+      glade_command_set_property (property, NULL);
+
+      property = glade_widget_get_property (gwidget, "subtitle");
+      glade_command_set_property (property, NULL);
+
+      property = glade_widget_get_property (gwidget, "has-subtitle");
+      glade_command_set_property (property, TRUE);
     }
 
-  glade_command_pop_group ();
+  property = glade_widget_get_property (gwidget, "use-custom-title");
+  glade_command_set_property (property, use_custom_title);
 
+  glade_command_pop_group ();
   glade_editable_unblock (GLADE_EDITABLE (editor));
-
   glade_editable_load (GLADE_EDITABLE (editor), gwidget);
 }
 
@@ -181,6 +173,7 @@ show_decoration_toggled (GtkWidget            *widget,
 {
   GladeHeaderBarEditorPrivate *priv = editor->priv;
   GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (editor));
+  GladeProperty *property;
   gboolean       show_decoration;
 
   if (glade_editable_loading (GLADE_EDITABLE (editor)) || !gwidget)
@@ -188,8 +181,27 @@ show_decoration_toggled (GtkWidget            *widget,
 
   show_decoration = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->show_decoration_check));
 
-  glade_widget_property_set (gwidget, "show-close-button", show_decoration);
-  glade_widget_property_set_sensitive (gwidget, "decoration-layout", show_decoration, "");
+  glade_editable_block (GLADE_EDITABLE (editor));
+
+  if (show_decoration)
+    glade_command_push_group (_("Setting %s to show window controls"),
+                              glade_widget_get_name (gwidget));
+  else
+    glade_command_push_group (_("Setting %s to not show window controls"),
+                              glade_widget_get_name (gwidget));
+
+  if (!show_decoration)
+    {
+      property = glade_widget_get_property (gwidget, "decoration-layout");
+      glade_command_set_property (property, NULL);
+    }
+
+  property = glade_widget_get_property (gwidget, "show-close-button");
+  glade_command_set_property (property, show_decoration);
+
+  glade_command_pop_group ();
+  glade_editable_unblock (GLADE_EDITABLE (editor));
+  glade_editable_load (GLADE_EDITABLE (editor), gwidget);
 }
 
 GtkWidget *
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 31bf29b..28fc427 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -2419,9 +2419,9 @@
        <property id="has-subtitle" _name="Reserve space for subtitle" custom-layout="True">
           <_tooltip>Keep the headerbar height the same as the subtitle changes dynamically.</_tooltip>
         </property>
-       <property id="show-close-button" ignore="True" save="True" custom-layout="True"/>
+       <property id="show-close-button" custom-layout="True" needs-sync="True"/>
        <property id="spacing" custom-layout="True"/>
-       <property id="decoration-layout" _name="Decoration Layout" optional="True" optional-default="False" 
custom-layout="True"/>
+       <property id="decoration-layout" custom-layout="True"/>
         <property id="decoration-layout-set" disabled="True"/>
         <property id="custom-title" disabled="True"/>
         <property id="use-custom-title" _name="Custom Title" default="FALSE" visible="True" save="False" 
custom-layout="True">


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