From c2567b9c3e6d6b86875a5f5b0a2b7fcb16a456a1 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Sat, 21 Sep 2019 08:07:18 +0400 Subject: [PATCH] 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 @@ - - sidebar - @@ -102,9 +99,6 @@ - - panel - @@ -121,7 +115,6 @@ - @@ -201,9 +194,6 @@ - - sidebar - @@ -270,9 +260,6 @@ - - panel -