[gnome-control-center] display: Replace GtkStack child names with widget references
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] display: Replace GtkStack child names with widget references
- Date: Mon, 30 Mar 2020 01:49:23 +0000 (UTC)
commit 73469d3ba2150ae8b0408840e080ad3163891fbe
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Nov 20 12:36:42 2019 +1300
display: Replace GtkStack child names with widget references
The child names are easier to break if widgets are changed - this can't be
detected by the compiler.
panels/display/cc-display-panel.c | 12 ++++++++----
panels/display/cc-display-panel.ui | 15 ++-------------
panels/display/cc-night-light-page.c | 30 +++++++++++++++++++++---------
panels/display/cc-night-light-page.ui | 34 ----------------------------------
4 files changed, 31 insertions(+), 60 deletions(-)
---
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index 7f64a31a1..524793070 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -105,9 +105,11 @@ struct _CcDisplayPanel
GtkWidget *config_type_switcher_frame;
GtkLabel *current_output_label;
GtkWidget *display_settings_frame;
+ GtkBox *multi_selection_box;
GtkSwitch *output_enabled_switch;
GtkComboBox *output_selection_combo;
GtkStack *output_selection_stack;
+ GtkButtonBox *output_selection_two_buttonbox;
GtkButtonBox *output_selection_two_first;
GtkButtonBox *output_selection_two_second;
HdyComboRow *primary_display_row;
@@ -653,10 +655,12 @@ cc_display_panel_class_init (CcDisplayPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, config_type_single);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, current_output_label);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, display_settings_frame);
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, multi_selection_box);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, night_light_page);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_enabled_switch);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_combo);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_stack);
+ gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_two_buttonbox);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_two_first);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, output_selection_two_second);
gtk_widget_class_bind_template_child (widget_class, CcDisplayPanel, primary_display_row);
@@ -825,9 +829,9 @@ rebuild_ui (CcDisplayPanel *panel)
/* We need a switcher except in CLONE mode */
if (type == CC_DISPLAY_CONFIG_CLONE)
- gtk_stack_set_visible_child_name (panel->output_selection_stack, "no-selection");
+ gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET
(panel->current_output_label));
else
- gtk_stack_set_visible_child_name (panel->output_selection_stack, "two-selection");
+ gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET
(panel->output_selection_two_buttonbox));
}
else if (n_usable_outputs > 1)
{
@@ -841,7 +845,7 @@ rebuild_ui (CcDisplayPanel *panel)
if (type == CC_DISPLAY_CONFIG_CLONE || type > CC_DISPLAY_CONFIG_LAST_VALID)
type = CC_DISPLAY_CONFIG_JOIN;
- gtk_stack_set_visible_child_name (panel->output_selection_stack, "multi-selection");
+ gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET (panel->multi_selection_box));
}
else
{
@@ -853,7 +857,7 @@ rebuild_ui (CcDisplayPanel *panel)
gtk_widget_set_visible (panel->config_type_switcher_frame, FALSE);
gtk_widget_set_visible (panel->arrangement_frame, FALSE);
- gtk_stack_set_visible_child_name (panel->output_selection_stack, "no-selection");
+ gtk_stack_set_visible_child (panel->output_selection_stack, GTK_WIDGET (panel->current_output_label));
}
cc_panel_set_selected_type (panel, type);
diff --git a/panels/display/cc-display-panel.ui b/panels/display/cc-display-panel.ui
index ed5a414d2..9728bbf9e 100644
--- a/panels/display/cc-display-panel.ui
+++ b/panels/display/cc-display-panel.ui
@@ -286,12 +286,9 @@
<attribute name="weight" value="bold"/>
</attributes>
</object>
- <packing>
- <property name="name">no-selection</property>
- </packing>
</child>
<child>
- <object class="GtkButtonBox">
+ <object class="GtkButtonBox" id="output_selection_two_buttonbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">expand</property>
@@ -326,13 +323,9 @@
</packing>
</child>
</object>
- <packing>
- <property name="name">two-selection</property>
- <property name="position">1</property>
- </packing>
</child>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="multi_selection_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -364,10 +357,6 @@
</packing>
</child>
</object>
- <packing>
- <property name="name">multi-selection</property>
- <property name="position">2</property>
- </packing>
</child>
<child>
<object class="GtkFrame">
diff --git a/panels/display/cc-night-light-page.c b/panels/display/cc-night-light-page.c
index a6bfd73b9..0fe03f36f 100644
--- a/panels/display/cc-night-light-page.c
+++ b/panels/display/cc-night-light-page.c
@@ -34,6 +34,10 @@ struct _CcNightLightPage {
GtkBin parent;
GtkWidget *box_manual;
+ GtkButton *button_from_am;
+ GtkButton *button_from_pm;
+ GtkButton *button_to_am;
+ GtkButton *button_to_pm;
GtkWidget *infobar_disabled;
GtkListBox *listbox;
GtkWidget *scale_color_temperature;
@@ -74,7 +78,9 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self,
gdouble value,
GtkAdjustment *adj_hours,
GtkAdjustment *adj_mins,
- GtkStack *stack)
+ GtkStack *stack,
+ GtkButton *button_am,
+ GtkButton *button_pm)
{
gdouble hours;
gdouble mins = 0.f;
@@ -109,10 +115,8 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self,
gtk_adjustment_set_value (GTK_ADJUSTMENT (adj_mins), mins);
self->ignore_value_changed = FALSE;
- if (is_24h)
- gtk_stack_set_visible_child_name (stack, "blank");
- else
- gtk_stack_set_visible_child_name (stack, is_pm ? "pm" : "am");
+ gtk_widget_set_visible (GTK_WIDGET (stack), !is_24h);
+ gtk_stack_set_visible_child (stack, is_pm ? GTK_WIDGET (button_pm) : GTK_WIDGET (button_am));
}
static void
@@ -165,7 +169,9 @@ dialog_update_state (CcNightLightPage *self)
dialog_adjustments_set_frac_hours (self, value,
self->adjustment_from_hours,
self->adjustment_from_minutes,
- self->stack_from);
+ self->stack_from,
+ self->button_from_am,
+ self->button_from_pm);
/* set to */
if (automatic && self->proxy_color != NULL)
@@ -190,7 +196,9 @@ dialog_update_state (CcNightLightPage *self)
dialog_adjustments_set_frac_hours (self, value,
self->adjustment_to_hours,
self->adjustment_to_minutes,
- self->stack_to);
+ self->stack_to,
+ self->button_to_am,
+ self->button_to_pm);
self->ignore_value_changed = TRUE;
value = (gdouble) g_settings_get_uint (self->settings_display, "night-light-temperature");
@@ -464,7 +472,7 @@ dialog_update_adjustments (CcNightLightPage *self)
else
{
if (gtk_adjustment_get_value (self->adjustment_from_hours) > 12)
- gtk_stack_set_visible_child_name (self->stack_from, "pm");
+ gtk_stack_set_visible_child (self->stack_from, GTK_WIDGET (self->button_from_pm));
gtk_adjustment_set_lower (self->adjustment_from_hours, 1);
gtk_adjustment_set_upper (self->adjustment_from_hours, 12);
@@ -479,7 +487,7 @@ dialog_update_adjustments (CcNightLightPage *self)
else
{
if (gtk_adjustment_get_value (self->adjustment_to_hours) > 12)
- gtk_stack_set_visible_child_name (self->stack_to, "pm");
+ gtk_stack_set_visible_child (self->stack_to, GTK_WIDGET (self->button_to_pm));
gtk_adjustment_set_lower (self->adjustment_to_hours, 1);
gtk_adjustment_set_upper (self->adjustment_to_hours, 12);
@@ -583,6 +591,10 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_to_minutes);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, adjustment_color_temperature);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, box_manual);
+ gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_am);
+ gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_from_pm);
+ gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am);
+ gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox);
gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch);
diff --git a/panels/display/cc-night-light-page.ui b/panels/display/cc-night-light-page.ui
index b79a642b2..9d66b67bb 100644
--- a/panels/display/cc-night-light-page.ui
+++ b/panels/display/cc-night-light-page.ui
@@ -241,9 +241,6 @@
<class name="unpadded-button"/>
</style>
</object>
- <packing>
- <property name="name">am</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="button_from_pm">
@@ -257,20 +254,6 @@
<class name="unpadded-button"/>
</style>
</object>
- <packing>
- <property name="name">pm</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="name">blank</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
</child>
@@ -361,9 +344,6 @@
<class name="unpadded-button"/>
</style>
</object>
- <packing>
- <property name="name">am</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="button_to_pm">
@@ -377,20 +357,6 @@
<class name="unpadded-button"/>
</style>
</object>
- <packing>
- <property name="name">pm</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="name">blank</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]