[gnome-control-center] window: Replace child names with widget references
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] window: Replace child names with widget references
- Date: Mon, 23 Sep 2019 14:10:02 +0000 (UTC)
commit c2567b9c3e6d6b86875a5f5b0a2b7fcb16a456a1
Author: Robert Ancell <robert ancell canonical com>
Date: Sat Sep 21 08:07:18 2019 +0400
window: Replace child names with widget references
Using child names can cause code to be broken if a name is changed - this wont
be picked up as an error in the compiler.
shell/cc-window.c | 28 ++++++++++++++++++++++------
shell/cc-window.ui | 13 -------------
2 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/shell/cc-window.c b/shell/cc-window.c
index 593886d39..fde0dad8c 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -58,6 +58,7 @@ struct _CcWindow
GtkWidget *header;
GtkWidget *header_box;
GtkWidget *main_leaflet;
+ GtkWidget *sidebar_box;
GtkWidget *list_scrolled;
GtkWidget *panel_headerbar;
GtkWidget *search_scrolled;
@@ -129,11 +130,25 @@ remove_all_custom_widgets (CcWindow *self)
CC_EXIT;
}
+static void
+show_panel (CcWindow *self)
+{
+ hdy_leaflet_set_visible_child (HDY_LEAFLET (self->main_leaflet), self->stack);
+ hdy_leaflet_set_visible_child (HDY_LEAFLET (self->header_box), self->panel_headerbar);
+}
+
+static void
+show_sidebar (CcWindow *self)
+{
+ hdy_leaflet_set_visible_child (HDY_LEAFLET (self->main_leaflet), self->sidebar_box);
+ hdy_leaflet_set_visible_child (HDY_LEAFLET (self->header_box), self->header);
+}
+
static void
on_sidebar_activated_cb (CcPanel *panel,
CcWindow *self)
{
- hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "panel");
+ show_panel (self);
}
static gboolean
@@ -415,7 +430,7 @@ set_active_panel_from_id (CcShell *shell,
{
g_object_set (G_OBJECT (self->current_panel), "parameters", parameters, NULL);
if (force_moving_to_the_panel || self->previous_list_view == view)
- hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "panel");
+ show_panel (self);
self->previous_list_view = view;
CC_RETURN (TRUE);
}
@@ -451,7 +466,7 @@ set_active_panel_from_id (CcShell *shell,
add_current_panel_to_history (shell, start_id);
if (force_moving_to_the_panel)
- hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "panel");
+ show_panel (self);
g_free (self->current_panel_id);
self->current_panel_id = g_strdup (start_id);
@@ -575,9 +590,9 @@ search_entry_activate_cb (GtkEntry *entry,
static void
back_button_clicked_cb (GtkButton *button,
- CcWindow *shell)
+ CcWindow *self)
{
- hdy_leaflet_set_visible_child_name (HDY_LEAFLET (shell->main_leaflet), "sidebar");
+ show_sidebar (self);
}
static void
@@ -851,7 +866,7 @@ cc_window_constructed (GObject *object)
self);
update_headerbar_buttons (self);
- hdy_leaflet_set_visible_child_name (HDY_LEAFLET (self->main_leaflet), "sidebar");
+ show_sidebar (self);
G_OBJECT_CLASS (cc_window_parent_class)->constructed (object);
}
@@ -919,6 +934,7 @@ cc_window_class_init (CcWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcWindow, header_sizegroup);
gtk_widget_class_bind_template_child (widget_class, CcWindow, list_scrolled);
gtk_widget_class_bind_template_child (widget_class, CcWindow, main_leaflet);
+ gtk_widget_class_bind_template_child (widget_class, CcWindow, sidebar_box);
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_headerbar);
gtk_widget_class_bind_template_child (widget_class, CcWindow, panel_list);
gtk_widget_class_bind_template_child (widget_class, CcWindow, previous_button);
diff --git a/shell/cc-window.ui b/shell/cc-window.ui
index e7b2a5d89..823cd81e2 100644
--- a/shell/cc-window.ui
+++ b/shell/cc-window.ui
@@ -76,9 +76,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="name">sidebar</property>
- </packing>
</child>
<child>
<object class="GtkSeparator" id="panel_separator">
@@ -102,9 +99,6 @@
<class name="background"/>
</style>
</object>
- <packing>
- <property name="name">panel</property>
- </packing>
</child>
</object>
</child>
@@ -121,7 +115,6 @@
<property name="mode-transition-duration" bind-source="main_leaflet"
bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create"/>
<property name="child-transition-type" bind-source="main_leaflet"
bind-property="child-transition-type" bind-flags="bidirectional|sync-create"/>
<property name="child-transition-duration" bind-source="main_leaflet"
bind-property="child-transition-duration" bind-flags="bidirectional|sync-create"/>
- <property name="visible-child-name" bind-source="main_leaflet"
bind-property="visible-child-name" bind-flags="bidirectional|sync-create"/>
<signal name="notify::visible-child" handler="notify_header_visible_child_cb" swapped="no"/>
<signal name="notify::fold" handler="notify_fold_cb" object="CcWindow" after="yes" swapped="no"/>
<child>
@@ -201,9 +194,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="name">sidebar</property>
- </packing>
</child>
<child>
<object class="GtkSeparator" id="header_separator">
@@ -270,9 +260,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="name">panel</property>
- </packing>
</child>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]