[gnome-control-center/wip/gbsneto/keyboard-improvements: 2/3] keyboard: split current and new shortcuts in edit dialog



commit 40bd8ab9324d4a350cc58aef0012021440dbdd73
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jul 29 15:29:36 2016 -0300

    keyboard: split current and new shortcuts in edit dialog
    
    When editing a shortcut, the current shortcut must be displayed
    side-by-side with the new one. This gives a better understanding
    of what's going on, and may avoid mistakes.
    
    This patch splits the shortcut accelerator in 2: the current and
    the new one, and also adapts the code to update only the new shortcut
    label.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769314

 panels/keyboard/cc-keyboard-shortcut-editor.c |   22 ++++++----
 panels/keyboard/shortcut-editor.ui            |   57 +++++++++++++++++++++++--
 2 files changed, 67 insertions(+), 12 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-shortcut-editor.c b/panels/keyboard/cc-keyboard-shortcut-editor.c
index 0c62532..fc66212 100644
--- a/panels/keyboard/cc-keyboard-shortcut-editor.c
+++ b/panels/keyboard/cc-keyboard-shortcut-editor.c
@@ -40,12 +40,14 @@ struct _CcKeyboardShortcutEditor
   GtkWidget          *edit_button;
   GtkWidget          *headerbar;
   GtkWidget          *name_entry;
+  GtkWidget          *new_shortcut_accel_label;
   GtkWidget          *new_shortcut_conflict_label;
   GtkWidget          *remove_button;
   GtkWidget          *replace_button;
   GtkWidget          *reset_button;
   GtkWidget          *shortcut_accel_label;
   GtkWidget          *shortcut_conflict_label;
+  GtkWidget          *shortcut_grid;
   GtkWidget          *stack;
   GtkWidget          *top_info_label;
 
@@ -226,7 +228,7 @@ get_current_shortcut_label (CcKeyboardShortcutEditor *self)
   if (is_custom_shortcut (self))
     return GTK_SHORTCUT_LABEL (self->custom_shortcut_accel_label);
 
-  return GTK_SHORTCUT_LABEL (self->shortcut_accel_label);
+  return GTK_SHORTCUT_LABEL (self->new_shortcut_accel_label);
 }
 
 static void
@@ -261,6 +263,8 @@ setup_custom_shortcut (CcKeyboardShortcutEditor *self)
 
   gtk_widget_set_sensitive (self->add_button, valid);
 
+  gtk_widget_show (self->shortcut_grid);
+
   if (!valid)
     return;
 
@@ -274,10 +278,12 @@ setup_custom_shortcut (CcKeyboardShortcutEditor *self)
 
   accel = gtk_accelerator_name (self->custom_keyval, self->custom_mask);
 
-
   /* Setup the accelerator label */
   gtk_shortcut_label_set_accelerator (shortcut_label, accel);
 
+  if (self->mode == CC_SHORTCUT_EDITOR_EDIT)
+    gtk_widget_set_visible (self->new_shortcut_accel_label, accel != NULL && *accel != '\0');
+
   /*
    * When the user finishes typing the new shortcut, it gets immediately
    * applied and the toggle button gets inactive.
@@ -439,6 +445,7 @@ setup_keyboard_item (CcKeyboardShortcutEditor *self,
   gtk_widget_hide (self->add_button);
   gtk_widget_hide (self->cancel_button);
   gtk_widget_hide (self->replace_button);
+  gtk_widget_hide (self->new_shortcut_accel_label);
 
   /* Setup the top label */
   text = g_strdup_printf (_("Enter new shortcut to change <b>%s</b>."), item->description);
@@ -456,6 +463,8 @@ setup_keyboard_item (CcKeyboardShortcutEditor *self,
                                                      "visible",
                                                      G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN | 
G_BINDING_SYNC_CREATE);
 
+  gtk_widget_hide (self->shortcut_grid);
+
   /* Setup the custom entries */
   if (is_custom)
     {
@@ -579,17 +588,12 @@ cc_keyboard_shortcut_editor_key_press_event (GtkWidget   *widget,
       self->custom_keyval = 0;
       self->custom_mask = 0;
 
-      if (self->item)
-        apply_custom_item_fields (self, self->item);
-
       gtk_shortcut_label_set_accelerator (GTK_SHORTCUT_LABEL (self->custom_shortcut_accel_label), "");
-      gtk_shortcut_label_set_accelerator (GTK_SHORTCUT_LABEL (self->shortcut_accel_label), "");
+      gtk_shortcut_label_set_accelerator (GTK_SHORTCUT_LABEL (self->new_shortcut_accel_label), "");
 
       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->edit_button), FALSE);
       release_grab (self);
 
-      self->edited = FALSE;
-
       return GDK_EVENT_STOP;
     }
 
@@ -682,12 +686,14 @@ cc_keyboard_shortcut_editor_class_init (CcKeyboardShortcutEditorClass *klass)
   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);
+  gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, new_shortcut_accel_label);
   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, shortcut_grid);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, stack);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardShortcutEditor, top_info_label);
 
diff --git a/panels/keyboard/shortcut-editor.ui b/panels/keyboard/shortcut-editor.ui
index 81b5dc3..bf4abf1 100644
--- a/panels/keyboard/shortcut-editor.ui
+++ b/panels/keyboard/shortcut-editor.ui
@@ -38,11 +38,60 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkShortcutLabel" id="shortcut_accel_label">
-                    <property name="visible">True</property>
+                  <object class="GtkGrid" id="shortcut_grid">
                     <property name="can_focus">False</property>
-                    <property name="halign">center</property>
-                    <property name="disabled-text" translatable="yes">Disabled</property>
+                    <property name="row_spacing">12</property>
+                    <property name="column_spacing">24</property>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="label" translatable="yes">Current Shortcut</property>
+                        <attributes>
+                          <attribute name="weight" value="bold" />
+                        </attributes>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkShortcutLabel" id="shortcut_accel_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">center</property>
+                        <property name="disabled-text" translatable="yes">Disabled</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="left_attach">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="label" translatable="yes">New Shortcut</property>
+                        <attributes>
+                          <attribute name="weight" value="bold" />
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="top_attach">0</property>
+                        <property name="left_attach">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkShortcutLabel" id="new_shortcut_accel_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">center</property>
+                        <property name="disabled-text" translatable="yes">Disabled</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="left_attach">1</property>
+                      </packing>
+                    </child>
                   </object>
                 </child>
                 <child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]