diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-10-25 20:30:57 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-10-25 20:30:57 -0400 |
commit | e2cefafcb5765e3c38b1d5892db70ab7af8d5f14 (patch) | |
tree | f34bb792df5eb5133a31bece320e1fe396fafb32 | |
parent | 4e788d5218ba8a0057c00c06a92840f751d4c326 (diff) | |
download | glade-box-center.tar.gz |
Move use-center-child to the box editorbox-center
This makes adding and removing center widgets undoable.
-rw-r--r-- | plugins/gtk+/glade-box-editor.c | 98 | ||||
-rw-r--r-- | plugins/gtk+/glade-box-editor.ui | 37 | ||||
-rw-r--r-- | plugins/gtk+/gtk+.xml.in | 2 |
3 files changed, 114 insertions, 23 deletions
diff --git a/plugins/gtk+/glade-box-editor.c b/plugins/gtk+/glade-box-editor.c index c3342005..a34f62be 100644 --- a/plugins/gtk+/glade-box-editor.c +++ b/plugins/gtk+/glade-box-editor.c @@ -26,14 +26,23 @@ #include "glade-box-editor.h" +static void glade_box_editor_editable_init (GladeEditableIface * iface); static void glade_box_editor_grab_focus (GtkWidget * widget); +static void use_center_child_toggled (GtkWidget *widget, GladeBoxEditor * box_editor); + struct _GladeBoxEditorPrivate { GtkWidget *embed; + GtkWidget *use_center_child; }; -G_DEFINE_TYPE_WITH_PRIVATE (GladeBoxEditor, glade_box_editor, GLADE_TYPE_EDITOR_SKELETON) +static GladeEditableIface *parent_editable_iface; + +G_DEFINE_TYPE_WITH_CODE (GladeBoxEditor, glade_box_editor, GLADE_TYPE_EDITOR_SKELETON, + G_ADD_PRIVATE (GladeBoxEditor) + G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, + glade_box_editor_editable_init)); static void glade_box_editor_class_init (GladeBoxEditorClass * klass) @@ -44,6 +53,9 @@ glade_box_editor_class_init (GladeBoxEditorClass * klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/gladegtk/glade-box-editor.ui"); gtk_widget_class_bind_template_child_private (widget_class, GladeBoxEditor, embed); + gtk_widget_class_bind_template_child_private (widget_class, GladeBoxEditor, use_center_child); + + gtk_widget_class_bind_template_callback (widget_class, use_center_child_toggled); } static void @@ -62,6 +74,90 @@ glade_box_editor_grab_focus (GtkWidget * widget) gtk_widget_grab_focus (box_editor->priv->embed); } +static void +glade_box_editor_load (GladeEditable *editable, + GladeWidget *gwidget) +{ + GladeBoxEditor *box_editor = GLADE_BOX_EDITOR (editable); + GladeBoxEditorPrivate *priv = box_editor->priv; + + /* Chain up to default implementation */ + parent_editable_iface->load (editable, gwidget); + + if (gwidget) + { + gboolean use_center_child; + + glade_widget_property_get (gwidget, "use-center-child", &use_center_child); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_center_child), use_center_child); + } +} + +static void +glade_box_editor_editable_init (GladeEditableIface * iface) +{ + parent_editable_iface = g_type_interface_peek_parent (iface); + + iface->load = glade_box_editor_load; +} + +static void +use_center_child_toggled (GtkWidget * widget, + GladeBoxEditor * box_editor) +{ + GladeBoxEditorPrivate *priv = box_editor->priv; + GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (box_editor)); + GladeWidget *gcenter = NULL; + GtkWidget *box; + GtkWidget *center; + GladeProperty *property; + gboolean use_center_child; + + if (glade_editable_loading (GLADE_EDITABLE (box_editor)) || !gwidget) + return; + + /* Get new desired property state */ + use_center_child = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_center_child)); + + /* Get any existing center child */ + box = (GtkWidget *)glade_widget_get_object (gwidget); + center = gtk_box_get_center_widget (GTK_BOX (box)); + + if (center && !GLADE_IS_PLACEHOLDER (center)) + gcenter = glade_widget_get_from_gobject (center); + + glade_editable_block (GLADE_EDITABLE (box_editor)); + + if (use_center_child) + glade_command_push_group (_("Setting %s to use a center child"), + glade_widget_get_name (gwidget)); + else + glade_command_push_group (_("Setting %s to not use a center child"), + 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 (gcenter) + { + GList list; + list.prev = list.next = NULL; + list.data = gcenter; + glade_command_delete (&list); + } + + property = glade_widget_get_property (gwidget, "use-center-child"); + glade_command_set_property (property, use_center_child); + + glade_command_pop_group (); + + glade_editable_unblock (GLADE_EDITABLE (box_editor)); + + /* reload buttons and sensitivity and stuff... */ + glade_editable_load (GLADE_EDITABLE (box_editor), gwidget); +} + GtkWidget * glade_box_editor_new (void) { diff --git a/plugins/gtk+/glade-box-editor.ui b/plugins/gtk+/glade-box-editor.ui index 4d466f27..887f638d 100644 --- a/plugins/gtk+/glade-box-editor.ui +++ b/plugins/gtk+/glade-box-editor.ui @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.16.0 +<!-- Generated with glade 3.18.1 libgladegtk - Glade UI Designer Gtk+ support plugin Copyright (C) 2013 Tristan Van Berkom <tvb@gnome.org> @@ -43,7 +43,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">0</property> <property name="top_attach">0</property> <property name="width">6</property> - <property name="height">1</property> </packing> </child> <child> @@ -61,7 +60,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">0</property> <property name="top_attach">1</property> <property name="width">6</property> - <property name="height">1</property> </packing> </child> <child> @@ -76,7 +74,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">0</property> <property name="top_attach">2</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -89,8 +86,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">2</property> <property name="top_attach">2</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -106,7 +101,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">0</property> <property name="top_attach">3</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -119,8 +113,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">2</property> <property name="top_attach">3</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -133,8 +125,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">3</property> <property name="top_attach">2</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -147,8 +137,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">4</property> <property name="top_attach">2</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -163,7 +151,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">0</property> <property name="top_attach">4</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -176,8 +163,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">2</property> <property name="top_attach">4</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -192,14 +177,24 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">3</property> <property name="top_attach">3</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> - <placeholder/> - </child> - <child> - <placeholder/> + <object class="GtkCheckButton" id="use_center_child"> + <property name="label" translatable="yes">Add center child</property> + <property name="tooltip_text" translatable="yes">Whether this box should include a centered child.</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="use_center_child_toggled" swapped="no"/> + </object> + <packing> + <property name="left_attach">3</property> + <property name="top_attach">4</property> + <property name="width">2</property> + </packing> </child> <child> <placeholder/> diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in index 3f730528..23d11b33 100644 --- a/plugins/gtk+/gtk+.xml.in +++ b/plugins/gtk+/gtk+.xml.in @@ -656,7 +656,7 @@ <value id="GTK_BASELINE_POSITION_BOTTOM" _name="Bottom"/> </displayable-values> </property> - <property visible="True" save="False" id="use-center-child" since="3.12" default="FALSE" name="Center Child"> + <property save="False" id="use-center-child" since="3.12" default="FALSE" _name="Center Child" custom-layout="True"> <parameter-spec> <type>GParamBoolean</type> </parameter-spec> |