keyboard: 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.
This commit is contained in:
parent
ee4d08ca1d
commit
ef9b0c7313
2 changed files with 35 additions and 46 deletions
|
@ -30,9 +30,13 @@ struct _CcKeyboardShortcutEditor
|
|||
|
||||
GtkButton *add_button;
|
||||
GtkButton *cancel_button;
|
||||
GtkButton *change_custom_shortcut_button;
|
||||
GtkEntry *command_entry;
|
||||
GtkBox *custom_edit_box;
|
||||
GtkGrid *custom_grid;
|
||||
GtkShortcutLabel *custom_shortcut_accel_label;
|
||||
GtkStack *custom_shortcut_stack;
|
||||
GtkBox *edit_box;
|
||||
GtkHeaderBar *headerbar;
|
||||
GtkEntry *name_entry;
|
||||
GtkLabel *new_shortcut_conflict_label;
|
||||
|
@ -43,6 +47,8 @@ struct _CcKeyboardShortcutEditor
|
|||
GtkButton *set_button;
|
||||
GtkShortcutLabel *shortcut_accel_label;
|
||||
GtkLabel *shortcut_conflict_label;
|
||||
GtkBox *standard_box;
|
||||
GtkBox *standard_edit_box;
|
||||
GtkStack *standard_shortcut_stack;
|
||||
GtkStack *stack;
|
||||
GtkLabel *top_info_label;
|
||||
|
@ -101,14 +107,14 @@ static GParamSpec *properties [N_PROPS] = { NULL, };
|
|||
static ShortcutEditorPage
|
||||
get_shortcut_editor_page (CcKeyboardShortcutEditor *self)
|
||||
{
|
||||
if (g_str_equal (gtk_stack_get_visible_child_name (self->stack), "change-shortcut"))
|
||||
if (gtk_stack_get_visible_child (self->stack) == GTK_WIDGET (self->custom_edit_box))
|
||||
return PAGE_CUSTOM_EDIT;
|
||||
|
||||
if (g_str_equal (gtk_stack_get_visible_child_name (self->stack), "custom"))
|
||||
if (gtk_stack_get_visible_child (self->stack) == GTK_WIDGET (self->custom_grid))
|
||||
return PAGE_CUSTOM;
|
||||
|
||||
if (g_str_equal (gtk_stack_get_visible_child_name (self->stack), "edit") &&
|
||||
g_str_equal (gtk_stack_get_visible_child_name (self->standard_shortcut_stack), "change-shortcut"))
|
||||
if (gtk_stack_get_visible_child (self->stack) == GTK_WIDGET (self->edit_box) &&
|
||||
gtk_stack_get_visible_child (self->standard_shortcut_stack) == GTK_WIDGET (self->standard_edit_box))
|
||||
{
|
||||
return PAGE_STANDARD_EDIT;
|
||||
}
|
||||
|
@ -123,21 +129,21 @@ set_shortcut_editor_page (CcKeyboardShortcutEditor *self,
|
|||
switch (page)
|
||||
{
|
||||
case PAGE_CUSTOM:
|
||||
gtk_stack_set_visible_child_name (self->stack, "custom");
|
||||
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->custom_grid));
|
||||
break;
|
||||
|
||||
case PAGE_CUSTOM_EDIT:
|
||||
gtk_stack_set_visible_child_name (self->stack, "change-shortcut");
|
||||
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->custom_edit_box));
|
||||
break;
|
||||
|
||||
case PAGE_STANDARD:
|
||||
gtk_stack_set_visible_child_name (self->stack, "edit");
|
||||
gtk_stack_set_visible_child_name (self->standard_shortcut_stack, "main");
|
||||
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->edit_box));
|
||||
gtk_stack_set_visible_child (self->standard_shortcut_stack, GTK_WIDGET (self->standard_box));
|
||||
break;
|
||||
|
||||
case PAGE_STANDARD_EDIT:
|
||||
gtk_stack_set_visible_child_name (self->stack, "edit");
|
||||
gtk_stack_set_visible_child_name (self->standard_shortcut_stack, "change-shortcut");
|
||||
gtk_stack_set_visible_child (self->stack, GTK_WIDGET (self->edit_box));
|
||||
gtk_stack_set_visible_child (self->standard_shortcut_stack, GTK_WIDGET (self->standard_edit_box));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -213,7 +219,7 @@ cancel_editing (CcKeyboardShortcutEditor *self)
|
|||
static gboolean
|
||||
is_custom_shortcut (CcKeyboardShortcutEditor *self)
|
||||
{
|
||||
return !g_str_equal (gtk_stack_get_visible_child_name (self->stack), "edit");
|
||||
return gtk_stack_get_visible_child (self->stack) != GTK_WIDGET (self->edit_box);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -352,8 +358,8 @@ setup_custom_shortcut (CcKeyboardShortcutEditor *self)
|
|||
|
||||
/* We have to check if the current accelerator is empty in order to
|
||||
* decide if we show the "Set Shortcut" button or the accelerator label */
|
||||
gtk_stack_set_visible_child_name (self->custom_shortcut_stack,
|
||||
is_accel_empty ? "button" : "label");
|
||||
gtk_stack_set_visible_child (self->custom_shortcut_stack,
|
||||
is_accel_empty ? GTK_WIDGET (self->change_custom_shortcut_button) : GTK_WIDGET (self->custom_shortcut_accel_label));
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->reset_custom_button), !is_accel_empty);
|
||||
}
|
||||
|
||||
|
@ -525,7 +531,7 @@ reset_custom_clicked_cb (CcKeyboardShortcutEditor *self)
|
|||
if (self->item)
|
||||
cc_keyboard_manager_reset_shortcut (self->manager, self->item);
|
||||
|
||||
gtk_stack_set_visible_child_name (self->custom_shortcut_stack, "button");
|
||||
gtk_stack_set_visible_child (self->custom_shortcut_stack, GTK_WIDGET (self->change_custom_shortcut_button));
|
||||
gtk_widget_hide (GTK_WIDGET (self->reset_custom_button));
|
||||
}
|
||||
|
||||
|
@ -623,8 +629,8 @@ setup_keyboard_item (CcKeyboardShortcutEditor *self,
|
|||
/* If there is no accelerator set for this custom shortcut, show the "Set Shortcut" button. */
|
||||
is_accel_empty = !accel || accel[0] == '\0';
|
||||
|
||||
gtk_stack_set_visible_child_name (self->custom_shortcut_stack,
|
||||
is_accel_empty ? "button" : "label");
|
||||
gtk_stack_set_visible_child (self->custom_shortcut_stack,
|
||||
is_accel_empty ? GTK_WIDGET (self->change_custom_shortcut_button) : GTK_WIDGET (self->custom_shortcut_accel_label));
|
||||
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->reset_custom_button), !is_accel_empty);
|
||||
|
||||
|
@ -887,9 +893,13 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
|
|||
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, add_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, cancel_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, change_custom_shortcut_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, command_entry);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, custom_edit_box);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, custom_grid);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, custom_shortcut_accel_label);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, custom_shortcut_stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, edit_box);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, headerbar);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, name_entry);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, new_shortcut_conflict_label);
|
||||
|
@ -900,6 +910,8 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
|
|||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, set_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, shortcut_accel_label);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, shortcut_conflict_label);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, standard_box);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, standard_edit_box);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, standard_shortcut_stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, top_info_label);
|
||||
|
@ -1003,8 +1015,8 @@ cc_keyboard_shortcut_editor_set_mode (CcKeyboardShortcutEditor *self,
|
|||
is_create_mode = mode == CC_SHORTCUT_EDITOR_CREATE;
|
||||
|
||||
gtk_widget_set_visible (GTK_WIDGET (self->new_shortcut_conflict_label), is_create_mode);
|
||||
gtk_stack_set_visible_child_name (self->custom_shortcut_stack,
|
||||
is_create_mode ? "button" : "label");
|
||||
gtk_stack_set_visible_child (self->custom_shortcut_stack,
|
||||
is_create_mode ? GTK_WIDGET (self->change_custom_shortcut_button) : GTK_WIDGET (self->custom_shortcut_accel_label));
|
||||
|
||||
if (mode == CC_SHORTCUT_EDITOR_CREATE)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<property name="vexpand">True</property>
|
||||
<property name="border_width">12</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="edit_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
@ -45,7 +45,7 @@
|
|||
<property name="expand">True</property>
|
||||
<property name="transition_type">crossfade</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="standard_edit_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
@ -72,12 +72,9 @@
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">change-shortcut</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="standard_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
|
@ -130,19 +127,13 @@
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">main</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">edit</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<object class="GtkGrid" id="custom_grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
|
@ -259,9 +250,6 @@
|
|||
<property name="label" translatable="yes">Set Shortcut…</property>
|
||||
<signal name="clicked" handler="change_custom_shortcut_button_clicked_cb" object="CcKeyboardShortcutEditor" swapped="yes" />
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">button</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutLabel" id="custom_shortcut_accel_label">
|
||||
|
@ -271,9 +259,6 @@
|
|||
<property name="hexpand">True</property>
|
||||
<property name="disabled-text" translatable="yes">None</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">label</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -282,13 +267,9 @@
|
|||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">custom</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="custom_edit_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
@ -322,10 +303,6 @@
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">change-shortcut</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue