keyboard: add support to reset shortcuts to their default values

Following the proposed mockups, the shortcut list must
have the ability to reset modified to non-default shortcuts
right from the listbox.

After adding the necessary API in CcKeyboardItem, adding
the user-visible elements to enable that is easy.

To make that happen, add a button that resets the
keyboard shortcut.

https://bugzilla.gnome.org/show_bug.cgi?id=769063
This commit is contained in:
Georges Basile Stavracas Neto 2016-07-18 21:48:47 -03:00
parent 376459af43
commit 1c85479742
5 changed files with 183 additions and 4 deletions

View file

@ -43,6 +43,7 @@ struct _CcKeyboardShortcutEditor
GtkWidget *new_shortcut_conflict_label;
GtkWidget *remove_button;
GtkWidget *replace_button;
GtkWidget *reset_button;
GtkWidget *shortcut_accel_label;
GtkWidget *shortcut_conflict_label;
GtkWidget *stack;
@ -54,6 +55,7 @@ struct _CcKeyboardShortcutEditor
CcKeyboardManager *manager;
CcKeyboardItem *item;
GBinding *reset_item_binding;
CcKeyboardItem *collision_item;
@ -402,6 +404,20 @@ replace_button_clicked_cb (CcKeyboardShortcutEditor *self)
gtk_widget_hide (GTK_WIDGET (self));
}
static void
reset_item_clicked_cb (CcKeyboardShortcutEditor *self)
{
gchar *accel;
/* Reset first, then update the shortcut */
cc_keyboard_manager_reset_shortcut (self->manager, self->item);
accel = gtk_accelerator_name (self->item->keyval, self->item->mask);
gtk_shortcut_label_set_accelerator (GTK_SHORTCUT_LABEL (self->shortcut_accel_label), accel);
g_free (accel);
}
static void
setup_keyboard_item (CcKeyboardShortcutEditor *self,
CcKeyboardItem *item)
@ -433,6 +449,13 @@ setup_keyboard_item (CcKeyboardShortcutEditor *self,
gtk_shortcut_label_set_accelerator (GTK_SHORTCUT_LABEL (self->shortcut_accel_label), accel);
gtk_shortcut_label_set_accelerator (GTK_SHORTCUT_LABEL (self->custom_shortcut_accel_label), accel);
g_clear_pointer (&self->reset_item_binding, g_binding_unbind);
self->reset_item_binding = g_object_bind_property (item,
"is-value-default",
self->reset_button,
"visible",
G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
/* Setup the custom entries */
if (is_custom)
{
@ -468,6 +491,8 @@ cc_keyboard_shortcut_editor_finalize (GObject *object)
g_clear_object (&self->item);
g_clear_object (&self->manager);
g_clear_pointer (&self->reset_item_binding, g_binding_unbind);
G_OBJECT_CLASS (cc_keyboard_shortcut_editor_parent_class)->finalize (object);
}
@ -660,6 +685,7 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, new_shortcut_conflict_label);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, remove_button);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, replace_button);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, reset_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, stack);
@ -672,6 +698,7 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
gtk_widget_class_bind_template_callback (widget_class, name_entry_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, replace_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, reset_item_clicked_cb);
}
static void