[gnome-control-center/wip/gbsneto/keyboard-improvements: 63/67] shortcut-editor: use a different page to edit custom shortcuts
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/keyboard-improvements: 63/67] shortcut-editor: use a different page to edit custom shortcuts
- Date: Thu, 1 Sep 2016 13:49:08 +0000 (UTC)
commit 194bb3486f52c44216f6cd34985eda92174705f0
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Aug 30 15:41:27 2016 -0300
shortcut-editor: use a different page to edit custom shortcuts
When adding a new keyboard shortcut, in accordance to the mockups,
the dialog should present a new page calling for an action from the
user.
This patch adds this page, and adapts the code to show it whenever
the user wants to change the shortcut.
https://bugzilla.gnome.org/show_bug.cgi?id=769314
panels/keyboard/cc-keyboard-shortcut-editor.c | 49 ++++++++++++++----
panels/keyboard/shortcut-editor.ui | 67 +++++++++++++++++++++++--
2 files changed, 102 insertions(+), 14 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c
index 6f1d8b0..3422b75 100644
--- a/panels/keyboard/cc-keyboard-shortcut-editor.c
+++ b/panels/keyboard/cc-keyboard-shortcut-editor.c
@@ -37,6 +37,7 @@ struct _CcKeyboardShortcutEditor
GtkWidget *cancel_button;
GtkWidget *command_entry;
GtkWidget *custom_shortcut_accel_label;
+ GtkWidget *custom_shortcut_stack;
GtkWidget *edit_button;
GtkWidget *headerbar;
GtkWidget *name_entry;
@@ -166,7 +167,7 @@ cancel_editing (CcKeyboardShortcutEditor *self)
static gboolean
is_custom_shortcut (CcKeyboardShortcutEditor *self)
{
- return g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (self->stack)), "custom");
+ return !g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (self->stack)), "edit");
}
static void
@@ -268,25 +269,35 @@ setup_custom_shortcut (CcKeyboardShortcutEditor *self)
CcKeyboardItem *collision_item;
HeaderMode mode;
gboolean is_custom;
- gboolean valid;
+ gboolean valid, accel_valid;
gchar *accel;
is_custom = is_custom_shortcut (self);
- valid = is_valid_binding (self->custom_keyval, self->custom_mask, self->custom_keycode) &&
- gtk_accelerator_valid (self->custom_keyval, self->custom_mask) &&
- !self->custom_is_modifier;
+ accel_valid = is_valid_binding (self->custom_keyval, self->custom_mask, self->custom_keycode) &&
+ gtk_accelerator_valid (self->custom_keyval, self->custom_mask) &&
+ !self->custom_is_modifier;
+ valid = accel_valid;
/* Additional checks for custom shortcuts */
if (is_custom)
{
- valid = valid &&
+ if (accel_valid)
+ {
+ gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "custom");
+ gtk_stack_set_visible_child_name (GTK_STACK (self->custom_shortcut_stack), "label");
+ gtk_widget_show (self->edit_button);
+ }
+
+ valid = accel_valid &&
gtk_entry_get_text_length (GTK_ENTRY (self->name_entry)) > 0 &&
gtk_entry_get_text_length (GTK_ENTRY (self->command_entry)) > 0;
}
+ gtk_widget_set_sensitive (self->replace_button, valid);
+ gtk_widget_set_sensitive (self->add_button, valid);
set_header_mode (self, valid ? ADD : is_custom ? CUSTOM_CANCEL : NONE);
- if (!valid)
+ if (!accel_valid)
return;
shortcut_label = get_current_shortcut_label (self);
@@ -399,6 +410,19 @@ cancel_button_clicked_cb (GtkWidget *button,
}
static void
+change_custom_shortcut_button_clicked_cb (CcKeyboardShortcutEditor *self)
+{
+ /*
+ * Setting the edit button to active performs a grab and let the
+ * shortcut editor dialog know we're actually editing a shortcut.
+ */
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->edit_button), TRUE);
+
+ gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "change-shortcut");
+ set_header_mode (self, NONE);
+}
+
+static void
command_entry_changed_cb (CcKeyboardShortcutEditor *self)
{
setup_custom_shortcut (self);
@@ -611,9 +635,7 @@ cc_keyboard_shortcut_editor_key_press_event (GtkWidget *widget,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->edit_button), FALSE);
release_grab (self);
- /* Hide the dialog when editing a standard shortcut */
- if (!is_custom)
- cancel_editing (self);
+ cancel_editing (self);
return GDK_EVENT_STOP;
}
@@ -726,6 +748,7 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, cancel_button);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, command_entry);
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_button);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, headerbar);
gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, name_entry);
@@ -741,6 +764,7 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
gtk_widget_class_bind_template_callback (widget_class, add_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, cancel_button_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, change_custom_shortcut_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, command_entry_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, edit_custom_shortcut_button_toggled_cb);
gtk_widget_class_bind_template_callback (widget_class, name_entry_changed_cb);
@@ -832,6 +856,8 @@ cc_keyboard_shortcut_editor_set_mode (CcKeyboardShortcutEditor *self,
is_create_mode = mode == CC_SHORTCUT_EDITOR_CREATE;
gtk_widget_set_visible (self->new_shortcut_conflict_label, is_create_mode);
+ gtk_stack_set_visible_child_name (GTK_STACK (self->custom_shortcut_stack),
+ is_create_mode ? "button" : "label");
if (mode == CC_SHORTCUT_EDITOR_CREATE)
{
@@ -842,5 +868,8 @@ cc_keyboard_shortcut_editor_set_mode (CcKeyboardShortcutEditor *self,
gtk_header_bar_set_title (GTK_HEADER_BAR (self->headerbar), _("Add Custom Shortcut"));
gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "custom");
+
+ gtk_widget_hide (self->remove_button);
+ gtk_widget_hide (self->edit_button);
}
}
diff --git a/panels/keyboard/shortcut-editor.ui b/panels/keyboard/shortcut-editor.ui
index 4cdbf42..c67f167 100644
--- a/panels/keyboard/shortcut-editor.ui
+++ b/panels/keyboard/shortcut-editor.ui
@@ -175,12 +175,32 @@
</packing>
</child>
<child>
- <object class="GtkShortcutLabel" id="custom_shortcut_accel_label">
+ <object class="GtkStack" id="custom_shortcut_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="hexpand">True</property>
- <property name="disabled-text" translatable="yes">None</property>
+ <child>
+ <object class="GtkButton" id="change_custom_shortcut_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <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">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="disabled-text" translatable="yes">None</property>
+ </object>
+ <packing>
+ <property name="name">label</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
@@ -210,6 +230,45 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">18</property>
+ <property name="expand">True</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">Enter the new shortcut</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property
name="resource">/org/gnome/control-center/keyboard/enter-keyboard-shortcut.svg</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">Press Esc to cancel.</property>
+ <style>
+ <class name="dim-label" />
+ </style>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="name">change-shortcut</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]