[glade/notebook-actions] Fix more undo issues



commit bc660e85f1dd13847139407f16370b5fdd6295a3
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 13 10:33:12 2015 -0500

    Fix more undo issues
    
    Handle the has-action-start/end properties just like the box
    code handles use-center-child.

 plugins/gtk+/glade-gtk-notebook.c     |   19 ++++++
 plugins/gtk+/glade-notebook-editor.c  |   99 ++++++++++++++++++++++++++++++++-
 plugins/gtk+/glade-notebook-editor.ui |   16 +++---
 plugins/gtk+/gtk+.xml.in              |    1 +
 4 files changed, 126 insertions(+), 9 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-notebook.c b/plugins/gtk+/glade-gtk-notebook.c
index c15e581..f97f4d3 100644
--- a/plugins/gtk+/glade-gtk-notebook.c
+++ b/plugins/gtk+/glade-gtk-notebook.c
@@ -583,6 +583,25 @@ glade_gtk_notebook_set_property (GladeWidgetAdaptor * adaptor,
                                                       id, value);
 }
 
+void
+glade_gtk_notebook_get_property (GladeWidgetAdaptor * adaptor,
+                            GObject * object, const gchar * id, GValue * value)
+{
+  if (!strcmp (id, "has-action-start"))
+    {
+      g_value_reset (value);
+      g_value_set_boolean (value, gtk_notebook_get_action_widget (GTK_NOTEBOOK (object), GTK_PACK_START) != 
NULL);
+    }
+  else if (!strcmp (id, "has-action-end"))
+    {
+      g_value_reset (value);
+      g_value_set_boolean (value, gtk_notebook_get_action_widget (GTK_NOTEBOOK (object), GTK_PACK_END) != 
NULL);
+    }
+  else
+    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->get_property (adaptor, object, id,
+                                                      value);
+}
+
 static gboolean
 glade_gtk_notebook_verify_n_pages (GObject * object, const GValue * value)
 {
diff --git a/plugins/gtk+/glade-notebook-editor.c b/plugins/gtk+/glade-notebook-editor.c
index 60f8618..59860a5 100644
--- a/plugins/gtk+/glade-notebook-editor.c
+++ b/plugins/gtk+/glade-notebook-editor.c
@@ -28,11 +28,15 @@
 
 static void glade_notebook_editor_editable_init (GladeEditableIface * iface);
 static void glade_notebook_editor_grab_focus (GtkWidget * widget);
+static void has_start_action_changed (GObject *object, GParamSpec *pspec, GladeNotebookEditor *editor);
+static void has_end_action_changed (GObject *object, GParamSpec *pspec, GladeNotebookEditor *editor);
 
 struct _GladeNotebookEditorPrivate
 {
   GtkWidget *embed;
   GtkWidget *tabs_grid;
+  GtkWidget *action_start_editor;
+  GtkWidget *action_end_editor;
 };
 
 static GladeEditableIface *parent_editable_iface;
@@ -52,6 +56,11 @@ glade_notebook_editor_class_init (GladeNotebookEditorClass * klass)
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/gladegtk/glade-notebook-editor.ui");
   gtk_widget_class_bind_template_child_private (widget_class, GladeNotebookEditor, embed);
   gtk_widget_class_bind_template_child_private (widget_class, GladeNotebookEditor, tabs_grid);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeNotebookEditor, action_start_editor);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeNotebookEditor, action_end_editor);
+
+  gtk_widget_class_bind_template_callback (widget_class, has_start_action_changed);
+  gtk_widget_class_bind_template_callback (widget_class, has_end_action_changed);
 }
 
 static void
@@ -68,6 +77,8 @@ glade_notebook_editor_load (GladeEditable * editable, GladeWidget * widget)
   GladeNotebookEditor *notebook_editor = GLADE_NOTEBOOK_EDITOR (editable);
   GladeNotebookEditorPrivate *priv = notebook_editor->priv;
   gboolean show_tabs = FALSE;
+  gboolean has_start_action = FALSE;
+  gboolean has_end_action = FALSE;
 
   /* Chain up to default implementation */
   parent_editable_iface->load (editable, widget);
@@ -75,8 +86,13 @@ glade_notebook_editor_load (GladeEditable * editable, GladeWidget * widget)
   if (widget)
     {
       glade_widget_property_get (widget, "show-tabs", &show_tabs);
-
       gtk_widget_set_visible (priv->tabs_grid, show_tabs);
+
+      glade_widget_property_get (widget, "has-action-start", &has_start_action);
+      gtk_switch_set_active (GTK_SWITCH (priv->action_start_editor), has_start_action);
+
+      glade_widget_property_get (widget, "has-action-end", &has_end_action);
+      gtk_switch_set_active (GTK_SWITCH (priv->action_end_editor), has_end_action);
     }
 }
 
@@ -101,3 +117,84 @@ glade_notebook_editor_new (void)
 {
   return g_object_new (GLADE_TYPE_NOTEBOOK_EDITOR, NULL);
 }
+
+static void
+has_action_changed (GladeNotebookEditor *editor, GtkPackType pack_type)
+{
+  GladeNotebookEditorPrivate *priv = editor->priv;
+  GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (editor));
+  GtkWidget *notebook;
+  GtkWidget *action;
+  GladeWidget *gaction = NULL;
+  GladeProperty *property;
+  gboolean has_action;
+  GtkWidget *action_editor;
+
+  if (glade_editable_loading (GLADE_EDITABLE (editor)) || !gwidget)
+    return;
+
+  if (pack_type == GTK_PACK_START)
+    {
+      action_editor = priv->action_start_editor;
+      property = glade_widget_get_property (gwidget, "has-action-start");
+    }
+  else
+    {
+      action_editor = priv->action_end_editor;
+      property = glade_widget_get_property (gwidget, "has-action-end");
+    }
+
+  has_action = gtk_switch_get_active (GTK_SWITCH (action_editor));
+
+  notebook = (GtkWidget *)glade_widget_get_object (gwidget);
+  action = gtk_notebook_get_action_widget (GTK_NOTEBOOK (notebook), pack_type);
+
+  if (action && !GLADE_IS_PLACEHOLDER (action))
+    gaction = glade_widget_get_from_gobject (action);
+
+  glade_editable_block (GLADE_EDITABLE (editor));
+
+  if (has_action && pack_type == GTK_PACK_START)
+    glade_command_push_group (_("Setting %s to have a start action"),
+                              glade_widget_get_name (gwidget));
+  else if (has_action && pack_type == GTK_PACK_END)
+    glade_command_push_group (_("Setting %s to have an end action"),
+                              glade_widget_get_name (gwidget));
+  else if (!has_action && pack_type == GTK_PACK_START)
+    glade_command_push_group (_("Setting %s to not have a start action"),
+                              glade_widget_get_name (gwidget));
+  else
+    glade_command_push_group (_("Setting %s to not have an end action"),
+                              glade_widget_get_name (gwidget));
+
+  /* If a project widget exists when were disabling center child, it needs
+   * to be removed first as a part of the issuing GladeCommand group
+   */
+  if (gaction)
+    {
+      GList list;
+      list.prev = list.next = NULL;
+      list.data = gaction;
+      glade_command_delete (&list);
+    }
+
+  glade_command_set_property (property, has_action);
+
+  glade_command_pop_group ();
+
+  glade_editable_unblock (GLADE_EDITABLE (editor));
+
+  glade_editable_load (GLADE_EDITABLE (editor), gwidget);
+}
+
+static void
+has_start_action_changed (GObject *object, GParamSpec *pspec, GladeNotebookEditor *editor)
+{
+  has_action_changed (editor, GTK_PACK_START);
+}
+
+static void
+has_end_action_changed (GObject *object, GParamSpec *pspec, GladeNotebookEditor *editor)
+{
+  has_action_changed (editor, GTK_PACK_END);
+}
diff --git a/plugins/gtk+/glade-notebook-editor.ui b/plugins/gtk+/glade-notebook-editor.ui
index efcc266..abfceec 100644
--- a/plugins/gtk+/glade-notebook-editor.ui
+++ b/plugins/gtk+/glade-notebook-editor.ui
@@ -261,10 +261,11 @@ Author: Tristan Van Berkom <tvb gnome org>
           </packing>
         </child>
         <child>
-          <object class="GladePropertyShell" id="action_start_editor">
+          <object class="GtkSwitch" id="action_start_editor">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="property_name">has-action-start</property>
+            <property name="can_focus">True</property>
+            <property name="halign">start</property>
+            <signal name="notify::active" handler="has_start_action_changed" swapped="no"/>
           </object>
           <packing>
             <property name="left_attach">1</property>
@@ -284,10 +285,11 @@ Author: Tristan Van Berkom <tvb gnome org>
           </packing>
         </child>
         <child>
-          <object class="GladePropertyShell" id="action_end_editor">
+          <object class="GtkSwitch" id="action_end_editor">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="property_name">has-action-end</property>
+            <property name="can_focus">True</property>
+            <property name="halign">start</property>
+            <signal name="notify::active" handler="has_end_action_changed" swapped="no"/>
           </object>
           <packing>
             <property name="left_attach">1</property>
@@ -361,8 +363,6 @@ Author: Tristan Van Berkom <tvb gnome org>
       <editor id="group_name_editor"/>
       <editor id="scrollable_editor"/>
       <editor id="enable_popup_editor"/>
-      <editor id="action_start_editor"/>
-      <editor id="action_end_editor"/>
     </child-editors>
   </template>
 </interface>
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 5d0714b..8a62168 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -2384,6 +2384,7 @@
         <child-verify-function>glade_gtk_notebook_child_verify_property</child-verify-function>
         <special-child-type>type</special-child-type>
         <set-property-function>glade_gtk_notebook_set_property</set-property-function>
+        <get-property-function>glade_gtk_notebook_get_property</get-property-function>
         <verify-function>glade_gtk_notebook_verify_property</verify-function>
         
<child-action-activate-function>glade_gtk_notebook_child_action_activate</child-action-activate-function>
         


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