[gnome-control-center/wip/gbsneto/new-keyboard-panel: 27/27] keyboard: support resetting keys from the list
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/new-keyboard-panel: 27/27] keyboard: support resetting keys from the list
- Date: Tue, 19 Jul 2016 16:04:19 +0000 (UTC)
commit b13407ad32f4bb46269664be8d970acdf1de8138
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Jul 18 21:48:47 2016 -0300
keyboard: support resetting keys from the list
Following the proposed mockups, the shortcut list must
have the ability to reset modified right away.
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.
panels/keyboard/cc-keyboard-panel.c | 89 +++++++++++++++++++++++-
panels/keyboard/cc-keyboard-shortcut-editor.c | 27 ++++++++
panels/keyboard/shortcut-editor.ui | 1 +
3 files changed, 113 insertions(+), 4 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-panel.c b/panels/keyboard/cc-keyboard-panel.c
index fc07ce2..9eb93d3 100644
--- a/panels/keyboard/cc-keyboard-panel.c
+++ b/panels/keyboard/cc-keyboard-panel.c
@@ -62,6 +62,11 @@ enum {
PROP_PARAMETERS
};
+static const gchar* custom_css =
+"button.reset-shortcut-button {"
+" padding: 0;"
+"}";
+
/*
* RowData functions
*/
@@ -103,7 +108,25 @@ transform_binding_to_accel (GBinding *binding,
item = CC_KEYBOARD_ITEM (g_binding_get_source (binding));
- accelerator = convert_keysym_state_to_string (item->keyval, item->mask, item->keycode);
+ /* Bold the label when the shortcut is modified */
+ if (cc_keyboard_item_is_modified (item))
+ {
+ gchar *tmp;
+
+ tmp = convert_keysym_state_to_string (item->keyval,
+ item->mask,
+ item->keycode);
+
+ accelerator = g_strdup_printf ("<b>%s</b>", tmp);
+
+ g_free (tmp);
+ }
+ else
+ {
+ accelerator = convert_keysym_state_to_string (item->keyval,
+ item->mask,
+ item->keycode);
+ }
g_value_set_string (to_value, accelerator);
@@ -113,16 +136,37 @@ transform_binding_to_accel (GBinding *binding,
}
static void
+shortcut_modified_changed_cb (CcKeyboardItem *item,
+ GParamSpec *pspec,
+ GtkWidget *button)
+{
+ gtk_widget_set_child_visible (button, cc_keyboard_item_is_modified (item));
+}
+
+static void
+reset_shortcut_cb (GtkWidget *reset_button,
+ CcKeyboardItem *item)
+{
+ cc_keyboard_item_reset (item);
+}
+
+static void
add_item (CcKeyboardPanel *self,
CcKeyboardItem *item,
const gchar *section_id,
const gchar *section_title)
{
- GtkWidget *row, *box, *label;
+ GtkWidget *row, *box, *label, *reset_button;
/* Horizontal box */
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_container_set_border_width (GTK_CONTAINER (box), 6);
+ box = g_object_new (GTK_TYPE_BOX,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ "spacing", 18,
+ "margin-start", 6,
+ "margin-end", 6,
+ "margin-bottom", 4,
+ "margin-top", 4,
+ NULL);
/* Shortcut title */
label = gtk_label_new (item->description);
@@ -142,6 +186,7 @@ add_item (CcKeyboardPanel *self,
/* Shortcut accelerator */
label = gtk_label_new ("");
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
gtk_size_group_add_widget (self->accelerator_sizegroup, label);
@@ -157,6 +202,31 @@ add_item (CcKeyboardPanel *self,
gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
+ /* Reset shortcut button */
+ reset_button = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_set_valign (reset_button, GTK_ALIGN_CENTER);
+
+ gtk_button_set_relief (GTK_BUTTON (reset_button), GTK_RELIEF_NONE);
+ gtk_widget_set_child_visible (reset_button, cc_keyboard_item_is_modified (item));
+
+ gtk_widget_set_tooltip_text (reset_button, _("Reset the shortcut to its default value"));
+
+ gtk_container_add (GTK_CONTAINER (box), reset_button);
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (reset_button), "flat");
+ gtk_style_context_add_class (gtk_widget_get_style_context (reset_button), "circular");
+ gtk_style_context_add_class (gtk_widget_get_style_context (reset_button), "reset-shortcut-button");
+
+ g_signal_connect (item,
+ "notify::is-modified",
+ G_CALLBACK (shortcut_modified_changed_cb),
+ reset_button);
+
+ g_signal_connect (reset_button,
+ "clicked",
+ G_CALLBACK (reset_shortcut_cb),
+ item);
+
/* The row */
row = gtk_list_box_row_new ();
gtk_container_add (GTK_CONTAINER (row), box);
@@ -398,11 +468,22 @@ cc_keyboard_panel_class_init (CcKeyboardPanelClass *klass)
static void
cc_keyboard_panel_init (CcKeyboardPanel *self)
{
+ GtkCssProvider *provider;
g_resources_register (cc_keyboard_get_resource ());
gtk_widget_init_template (GTK_WIDGET (self));
+ /* Custom CSS */
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (provider, custom_css, -1, NULL);
+
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+
+ g_object_unref (provider);
+
/* Shortcut manager */
self->manager = cc_keyboard_manager_new ();
diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c
index 06f7405..eeffdd1 100644
--- a/panels/keyboard/cc-keyboard-shortcut-editor.c
+++ b/panels/keyboard/cc-keyboard-shortcut-editor.c
@@ -48,6 +48,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;
@@ -59,6 +60,7 @@ struct _CcKeyboardShortcutEditor
CcKeyboardManager *manager;
CcKeyboardItem *item;
+ GBinding *reset_item_binding;
CcKeyboardItem *collision_item;
@@ -410,6 +412,20 @@ replace_button_clicked_cb (CcKeyboardShortcutEditor *self)
}
static void
+reset_item_clicked_cb (CcKeyboardShortcutEditor *self)
+{
+ gchar *accel;
+
+ /* Reset first, then update the shortcut */
+ cc_keyboard_item_reset (self->item);
+
+ accel = gtk_accelerator_name (self->item->keyval, self->item->mask);
+ cc_shortcut_label_set_accelerator (CC_SHORTCUT_LABEL (self->shortcut_accel_label), accel);
+
+ g_free (accel);
+}
+
+static void
setup_keyboard_item (CcKeyboardShortcutEditor *self,
CcKeyboardItem *item)
{
@@ -440,6 +456,13 @@ setup_keyboard_item (CcKeyboardShortcutEditor *self,
cc_shortcut_label_set_accelerator (CC_SHORTCUT_LABEL (self->shortcut_accel_label), accel);
cc_shortcut_label_set_accelerator (CC_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-modified",
+ self->reset_button,
+ "visible",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+
/* Setup the custom entries */
if (is_custom)
{
@@ -475,6 +498,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);
}
@@ -645,6 +670,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);
@@ -657,6 +683,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
diff --git a/panels/keyboard/shortcut-editor.ui b/panels/keyboard/shortcut-editor.ui
index 8978461..3bca7e1 100644
--- a/panels/keyboard/shortcut-editor.ui
+++ b/panels/keyboard/shortcut-editor.ui
@@ -64,6 +64,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">end</property>
+ <signal name="clicked" handler="reset_item_clicked_cb" object="CcKeyboardShortcutEditor"
swapped="yes" />
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]