diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-10-18 00:26:27 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-12-13 10:37:44 -0500 |
commit | 38eff36e99b1ccf139de4fb0c616007bcc49dc1e (patch) | |
tree | 31f22001f333b62efcfd7d5862bb4faca642c00f | |
parent | 0c076cc8828cd80f1f156a08569199675bf35165 (diff) | |
download | glade-notebook-actions.tar.gz |
Support notebook actionsnotebook-actions
-rw-r--r-- | plugins/gtk+/glade-gtk-notebook.c | 118 | ||||
-rw-r--r-- | plugins/gtk+/glade-notebook-editor.c | 99 | ||||
-rw-r--r-- | plugins/gtk+/glade-notebook-editor.ui | 94 | ||||
-rw-r--r-- | plugins/gtk+/gtk+.xml.in | 15 |
4 files changed, 297 insertions, 29 deletions
diff --git a/plugins/gtk+/glade-gtk-notebook.c b/plugins/gtk+/glade-gtk-notebook.c index 8f5efc3e..f97f4d34 100644 --- a/plugins/gtk+/glade-gtk-notebook.c +++ b/plugins/gtk+/glade-gtk-notebook.c @@ -380,11 +380,25 @@ glade_gtk_notebook_project_changed (GladeWidget * gwidget, g_object_set_data (G_OBJECT (gwidget), "notebook-project-ptr", project); } +static void +glade_gtk_notebook_parse_finished (GladeProject * project, GObject * object) +{ + GtkWidget *action; + + action = gtk_notebook_get_action_widget (GTK_NOTEBOOK (object), GTK_PACK_START); + glade_widget_property_set (glade_widget_get_from_gobject (object), + "has-action-start", action != NULL); + action = gtk_notebook_get_action_widget (GTK_NOTEBOOK (object), GTK_PACK_END); + glade_widget_property_set (glade_widget_get_from_gobject (object), + "has-action-end", action != NULL); +} + void glade_gtk_notebook_post_create (GladeWidgetAdaptor * adaptor, GObject * notebook, GladeCreateReason reason) { GladeWidget *gwidget = glade_widget_get_from_gobject (notebook); + GladeProject *project = glade_widget_get_project (gwidget); gtk_notebook_popup_disable (GTK_NOTEBOOK (notebook)); @@ -395,6 +409,11 @@ glade_gtk_notebook_post_create (GladeWidgetAdaptor * adaptor, g_signal_connect (G_OBJECT (notebook), "switch-page", G_CALLBACK (glade_gtk_notebook_switch_page), NULL); + + if (reason == GLADE_CREATE_LOAD) + g_signal_connect (project, "parse-finished", + G_CALLBACK (glade_gtk_notebook_parse_finished), + notebook); } static gint @@ -533,11 +552,56 @@ glade_gtk_notebook_set_property (GladeWidgetAdaptor * adaptor, { if (!strcmp (id, "pages")) glade_gtk_notebook_set_n_pages (object, value); + else if (!strcmp (id, "has-action-start")) + { + if (g_value_get_boolean (value)) + { + GtkWidget *action = gtk_notebook_get_action_widget (GTK_NOTEBOOK (object), GTK_PACK_START); + if (!action) + action = glade_placeholder_new (); + g_object_set_data (G_OBJECT (action), "special-child-type", "action-start"); + gtk_notebook_set_action_widget (GTK_NOTEBOOK (object), action, GTK_PACK_START); + } + else + gtk_notebook_set_action_widget (GTK_NOTEBOOK (object), NULL, GTK_PACK_START); + } + else if (!strcmp (id, "has-action-end")) + { + if (g_value_get_boolean (value)) + { + GtkWidget *action = gtk_notebook_get_action_widget (GTK_NOTEBOOK (object), GTK_PACK_END); + if (!action) + action = glade_placeholder_new (); + g_object_set_data (G_OBJECT (action), "special-child-type", "action-end"); + gtk_notebook_set_action_widget (GTK_NOTEBOOK (object), action, GTK_PACK_END); + } + else + gtk_notebook_set_action_widget (GTK_NOTEBOOK (object), NULL, GTK_PACK_END); + } else GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, 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) { @@ -592,10 +656,18 @@ glade_gtk_notebook_add_child (GladeWidgetAdaptor * adaptor, num_page = gtk_notebook_get_n_pages (notebook); gwidget = glade_widget_get_from_gobject (object); - /* Just append pages blindly when loading/dupping - */ - if (glade_widget_superuser ()) + special_child_type = g_object_get_data (child, "special-child-type"); + if (special_child_type && !strcmp (special_child_type, "action-start")) { + gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_START); + } + else if (special_child_type && !strcmp (special_child_type, "action-end")) + { + gtk_notebook_set_action_widget (notebook, GTK_WIDGET (child), GTK_PACK_END); + } + else if (glade_widget_superuser ()) + { + /* Just append pages blindly when loading/dupping */ special_child_type = g_object_get_data (child, "special-child-type"); if (special_child_type && !strcmp (special_child_type, "tab")) { @@ -674,6 +746,23 @@ glade_gtk_notebook_remove_child (GladeWidgetAdaptor * adaptor, GObject * object, GObject * child) { NotebookChildren *nchildren; + gchar *special_child_type; + + special_child_type = g_object_get_data (child, "special-child-type"); + if (special_child_type && !strcmp (special_child_type, "action-start")) + { + GtkWidget *placeholder = glade_placeholder_new (); + g_object_set_data (G_OBJECT (placeholder), "special-child-type", "action-start"); + gtk_notebook_set_action_widget (GTK_NOTEBOOK (object), placeholder, GTK_PACK_START); + return; + } + else if (special_child_type && !strcmp (special_child_type, "action-end")) + { + GtkWidget *placeholder = glade_placeholder_new (); + g_object_set_data (G_OBJECT (placeholder), "special-child-type", "action-end"); + gtk_notebook_set_action_widget (GTK_NOTEBOOK (object), placeholder, GTK_PACK_END); + return; + } nchildren = glade_gtk_notebook_extract_children (GTK_WIDGET (object)); @@ -711,9 +800,23 @@ glade_gtk_notebook_replace_child (GladeWidgetAdaptor * adaptor, GtkNotebook *notebook; GladeWidget *gcurrent, *gnew; gint position = 0; + gchar *special_child_type; notebook = GTK_NOTEBOOK (container); + special_child_type = g_object_get_data (G_OBJECT (current), "special-child-type"); + g_object_set_data (G_OBJECT (new_widget), "special-child-type", special_child_type); + if (!g_strcmp0 (special_child_type, "action-start")) + { + gtk_notebook_set_action_widget (notebook, GTK_WIDGET (new_widget), GTK_PACK_START); + return; + } + else if (!g_strcmp0 (special_child_type, "action-end")) + { + gtk_notebook_set_action_widget (notebook, GTK_WIDGET (new_widget), GTK_PACK_END); + return; + } + if ((gcurrent = glade_widget_get_from_gobject (current)) != NULL) glade_widget_pack_property_get (gcurrent, "position", &position); else @@ -725,9 +828,6 @@ glade_gtk_notebook_replace_child (GladeWidgetAdaptor * adaptor, } } - if (g_object_get_data (G_OBJECT (current), "special-child-type")) - g_object_set_data (G_OBJECT (new_widget), "special-child-type", "tab"); - glade_gtk_notebook_remove_child (adaptor, G_OBJECT (container), G_OBJECT (current)); @@ -803,7 +903,7 @@ glade_gtk_notebook_get_child_property (GladeWidgetAdaptor * adaptor, if (strcmp (property_name, "position") == 0) { - if (g_object_get_data (child, "special-child-type") != NULL) + if (g_strcmp0 (g_object_get_data (child, "special-child-type"), "tab") == 0) { if ((position = notebook_search_tab (GTK_NOTEBOOK (container), GTK_WIDGET (child))) >= 0) @@ -811,6 +911,10 @@ glade_gtk_notebook_get_child_property (GladeWidgetAdaptor * adaptor, else g_value_set_int (value, 0); } + else if (g_object_get_data (child, "special-child-type") != NULL) + { + g_value_set_int (value, 0); + } else gtk_container_child_get_property (GTK_CONTAINER (container), GTK_WIDGET (child), diff --git a/plugins/gtk+/glade-notebook-editor.c b/plugins/gtk+/glade-notebook-editor.c index 60f86181..59860a50 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 962ddc20..abfceec8 100644 --- a/plugins/gtk+/glade-notebook-editor.ui +++ b/plugins/gtk+/glade-notebook-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,8 +74,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">0</property> <property name="top_attach">2</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -90,8 +86,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">1</property> <property name="top_attach">2</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -105,8 +99,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">1</property> <property name="top_attach">3</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -121,8 +113,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <packing> <property name="left_attach">0</property> <property name="top_attach">3</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -148,7 +138,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> @@ -163,7 +152,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">0</property> <property name="top_attach">1</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -177,7 +165,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">2</property> <property name="top_attach">1</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -192,7 +179,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> @@ -206,7 +192,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">2</property> <property name="top_attach">2</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -222,7 +207,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> @@ -237,7 +221,6 @@ Author: Tristan Van Berkom <tvb@gnome.org> <property name="left_attach">2</property> <property name="top_attach">3</property> <property name="width">2</property> - <property name="height">1</property> </packing> </child> <child> @@ -261,12 +244,83 @@ Author: Tristan Van Berkom <tvb@gnome.org> </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">4</property> + <property name="top_attach">6</property> <property name="width">6</property> - <property name="height">1</property> </packing> </child> <child> + <object class="GladePropertyLabel" id="action_start_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="property_name">has-action-start</property> + <property name="custom_text" translatable="yes">Start Action:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">4</property> + </packing> + </child> + <child> + <object class="GtkSwitch" id="action_start_editor"> + <property name="visible">True</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> + <property name="top_attach">4</property> + </packing> + </child> + <child> + <object class="GladePropertyLabel" id="action_end_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="property_name">has-action-end</property> + <property name="custom_text" translatable="yes">End Action:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">5</property> + </packing> + </child> + <child> + <object class="GtkSwitch" id="action_end_editor"> + <property name="visible">True</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> + <property name="top_attach">5</property> + </packing> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + </child> + <child> <placeholder/> </child> <child> diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in index 3da6821e..8a621685 100644 --- a/plugins/gtk+/gtk+.xml.in +++ b/plugins/gtk+/gtk+.xml.in @@ -2233,7 +2233,7 @@ <property id="default-height" default="260" optional="True" optional-default="False"/> <property id="type-hint" default="GDK_WINDOW_TYPE_HINT_DIALOG" save-always="True"/> <!-- We disabled this property until Glade supports GtkHeaderBar editing --> - <property id="use-header-bar" since="3.12" disabled="True"/> + <property id="use-header-bar" since="3.12" disabled="False"/> </properties> </glade-widget-class> @@ -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> @@ -2418,8 +2419,20 @@ </parameter-spec> <_tooltip>The number of pages in the notebook</_tooltip> </property> + + <property id="has-action-start" _name="Start Action" visible="False" save="False" default="False" custom-layout="True"> + <parameter-spec> + <type>GParamBoolean</type> + </parameter-spec> + </property> + <property id="has-action-end" _name="End Action" visible="False" save="False" default="False" custom-layout="True"> + <parameter-spec> + <type>GParamBoolean</type> + </parameter-spec> + </property> </properties> + <packing-properties> <property id="tab-label" disabled="True"/> </packing-properties> |