[glade/headerbar] GladeWindowEditor: Added custom control for client side decorations



commit 32fc32041c333790b7b87ba0e88831865836d820
Author: Tristan Van Berkom <tristan upstairslabs com>
Date:   Sat Oct 18 14:38:31 2014 +0900

    GladeWindowEditor: Added custom control for client side decorations
    
    This is needed so that when the command is issued, it can also
    include the child deletion as a part of the command group.

 plugins/gtk+/glade-window-editor.c  |   80 +++++++++++++++++++++++++++++++++++
 plugins/gtk+/glade-window-editor.ui |   66 +++++++++++++----------------
 2 files changed, 110 insertions(+), 36 deletions(-)
---
diff --git a/plugins/gtk+/glade-window-editor.c b/plugins/gtk+/glade-window-editor.c
index 62a6451..eafb2cd 100644
--- a/plugins/gtk+/glade-window-editor.c
+++ b/plugins/gtk+/glade-window-editor.c
@@ -31,6 +31,7 @@ static void glade_window_editor_grab_focus (GtkWidget * widget);
 /* Callbacks */
 static void icon_name_toggled    (GtkWidget *widget, GladeWindowEditor * window_editor);
 static void icon_file_toggled    (GtkWidget *widget, GladeWindowEditor * window_editor);
+static void use_csd_toggled      (GtkWidget *widget, GladeWindowEditor * window_editor);
 
 struct _GladeWindowEditorPrivate {
   GtkWidget *embed;
@@ -38,6 +39,7 @@ struct _GladeWindowEditorPrivate {
   GtkWidget *extension_port;
   GtkWidget *icon_name_radio;
   GtkWidget *icon_file_radio;
+  GtkWidget *use_csd_check;
 };
 
 static GladeEditableIface *parent_editable_iface;
@@ -59,9 +61,11 @@ glade_window_editor_class_init (GladeWindowEditorClass * klass)
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, embed);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, icon_name_radio);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, icon_file_radio);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeWindowEditor, use_csd_check);
 
   gtk_widget_class_bind_template_callback (widget_class, icon_name_toggled);
   gtk_widget_class_bind_template_callback (widget_class, icon_file_toggled);
+  gtk_widget_class_bind_template_callback (widget_class, use_csd_toggled);
 }
 
 static void
@@ -94,13 +98,17 @@ glade_window_editor_load (GladeEditable *editable,
   if (gwidget)
     {
       gboolean icon_name;
+      gboolean use_csd;
 
       glade_widget_property_get (gwidget, "glade-window-icon-name", &icon_name);
+      glade_widget_property_get (gwidget, "use-csd", &use_csd);
 
       if (icon_name)
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->icon_name_radio), TRUE);
       else
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->icon_file_radio), TRUE);
+
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_csd_check), use_csd);
     }
 }
 
@@ -180,6 +188,78 @@ icon_file_toggled (GtkWidget         *widget,
   glade_editable_load (GLADE_EDITABLE (window_editor), gwidget);
 }
 
+/* Hack to find the titlebar */
+static void check_titlebar (GtkWidget *widget, gpointer data)
+{
+  GtkWidget **titlebar = data;
+  if (gtk_style_context_has_class (gtk_widget_get_style_context (widget), "titlebar"))
+    *titlebar = widget;
+}
+
+static GtkWidget *
+gtk_window_get_titlebar (GtkWindow *window)
+{
+  GtkWidget *titlebar = NULL;
+  gtk_container_forall (GTK_CONTAINER (window), check_titlebar, &titlebar);
+  return titlebar;
+}
+
+static void
+use_csd_toggled (GtkWidget         *widget,
+                GladeWindowEditor *window_editor)
+{
+  GladeWindowEditorPrivate *priv = window_editor->priv;
+  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (window_editor));
+  GladeWidget   *gtitlebar = NULL;
+  GtkWidget     *window;
+  GtkWidget     *titlebar;
+  GladeProperty *property;
+  gboolean       use_csd;
+
+  if (glade_editable_loading (GLADE_EDITABLE (window_editor)) || !gwidget)
+    return;
+
+  /* Get new desired property state */
+  use_csd = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_csd_check));
+
+  /* Get any existing titlebar widget */
+  window = (GtkWidget *)glade_widget_get_object (gwidget);
+  titlebar = gtk_window_get_titlebar (GTK_WINDOW (window));
+
+  if (titlebar && !GLADE_IS_PLACEHOLDER (titlebar))
+    gtitlebar = glade_widget_get_from_gobject (titlebar);
+
+  glade_editable_block (GLADE_EDITABLE (window_editor));
+
+  if (use_csd)
+    glade_command_push_group (_("Setting %s to use a custom titlebar"),
+                             glade_widget_get_name (gwidget));
+  else
+    glade_command_push_group (_("Setting %s to use a system provided titlebar"),
+                             glade_widget_get_name (gwidget));
+
+  /* If a project widget exists when were disabling CSD, it needs
+   * to be removed first as a part of the issuing GladeCommand group
+   */
+  if (gtitlebar)
+    {
+      GList list;
+      list.prev = list.next = NULL;
+      list.data = gtitlebar;
+      glade_command_delete (&list);
+    }
+
+  property = glade_widget_get_property (gwidget, "use-csd");
+  glade_command_set_property (property, use_csd);
+
+  glade_command_pop_group ();
+
+  glade_editable_unblock (GLADE_EDITABLE (window_editor));
+
+  /* reload buttons and sensitivity and stuff... */
+  glade_editable_load (GLADE_EDITABLE (window_editor), gwidget);
+}
+
 /*************************************
  *                API                *
  *************************************/
diff --git a/plugins/gtk+/glade-window-editor.ui b/plugins/gtk+/glade-window-editor.ui
index 889b133..47794f1 100644
--- a/plugins/gtk+/glade-window-editor.ui
+++ b/plugins/gtk+/glade-window-editor.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.1 
+<!-- Generated with glade 3.18.2 
 
 libgladegtk - Glade UI Designer Gtk+ support plugin
 Copyright (C) 2013 Tristan Van Berkom <tvb gnome org>
@@ -217,34 +217,6 @@ Author: Tristan Van Berkom <tvb gnome org>
           </packing>
         </child>
         <child>
-          <object class="GladePropertyLabel" id="title_label">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="margin_left">12</property>
-            <property name="hexpand">False</property>
-            <property name="property_name">title</property>
-            <property name="custom_text" translatable="yes">Title:</property>
-          </object>
-          <packing>
-            <property name="left_attach">0</property>
-            <property name="top_attach">11</property>
-            <property name="width">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GladePropertyShell" id="title_editor">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="hexpand">False</property>
-            <property name="property_name">title</property>
-          </object>
-          <packing>
-            <property name="left_attach">2</property>
-            <property name="top_attach">11</property>
-            <property name="width">4</property>
-          </packing>
-        </child>
-        <child>
           <object class="GtkRadioButton" id="icon_file_radio">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
@@ -693,27 +665,49 @@ Author: Tristan Van Berkom <tvb gnome org>
           </packing>
         </child>
         <child>
-          <object class="GladePropertyLabel" id="csd_label">
+          <object class="GladePropertyLabel" id="title_label">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="property_name">use-csd</property>
-            <property name="custom_text" translatable="yes">Client-side decorations:</property>
+            <property name="margin_left">12</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">title</property>
+            <property name="custom_text" translatable="yes">Title:</property>
           </object>
           <packing>
             <property name="left_attach">0</property>
             <property name="top_attach">10</property>
+            <property name="width">2</property>
           </packing>
         </child>
         <child>
-          <object class="GladePropertyShell" id="csd_editor">
+          <object class="GladePropertyShell" id="title_editor">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="property_name">use-csd</property>
+            <property name="hexpand">False</property>
+            <property name="property_name">title</property>
           </object>
           <packing>
-            <property name="left_attach">1</property>
+            <property name="left_attach">2</property>
             <property name="top_attach">10</property>
-            <property name="width">5</property>
+            <property name="width">4</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkCheckButton" id="use_csd_check">
+            <property name="label" translatable="yes">Client side window decorations</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="tooltip_text" translatable="yes">Whether this window should include a custom 
titlebar.</property>
+            <property name="margin_left">12</property>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+            <signal name="toggled" handler="use_csd_toggled" swapped="no"/>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">11</property>
+            <property name="width">6</property>
           </packing>
         </child>
         <child>


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