[gnome-control-center] keyboard: add a reset all button



commit 818024970c6d1f094f42c99e76d24841343cfe38
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jan 31 08:58:51 2017 -0200

    keyboard: add a reset all button
    
    As described in the proposed mockups [1], the Keyboard panel
    should have a Reset All button above the list of shortcuts that
    allows the user to quickly reset all the shortcuts to their
    default keybinding. The current implementation, however, lacks
    this button.
    
    Fix that by adding a "Reset All" button, and implementing the
    reset all action. A message dialog is shown in order to confirm
    the action, and custom shortcuts are not reset (unless the conflict
    with the default keybinding of another standard shortcut).
    
    [1] 
https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/system-settings/keyboard/keyboard-wires.png
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777840

 panels/keyboard/cc-keyboard-panel.c     |   65 +++++++++++++++++++++++++++++++
 panels/keyboard/gnome-keyboard-panel.ui |   28 +++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-panel.c b/panels/keyboard/cc-keyboard-panel.c
index 9ad3f97..6aa7142 100644
--- a/panels/keyboard/cc-keyboard-panel.c
+++ b/panels/keyboard/cc-keyboard-panel.c
@@ -145,6 +145,70 @@ shortcut_modified_changed_cb (CcKeyboardItem *item,
 }
 
 static void
+reset_all_shortcuts_cb (GtkWidget *widget,
+                        gpointer   user_data)
+{
+  CcKeyboardPanel *self;
+  RowData *data;
+
+  self = user_data;
+
+  if (widget == (GtkWidget *) self->add_shortcut_row)
+    return;
+
+  data = g_object_get_data (G_OBJECT (widget), "data");
+
+  /* Don't reset custom shortcuts */
+  if (data->item->type == CC_KEYBOARD_ITEM_TYPE_GSETTINGS_PATH)
+    return;
+
+  /* cc_keyboard_manager_reset_shortcut() already resets conflicting shortcuts,
+   * so no other check is needed here. */
+  cc_keyboard_manager_reset_shortcut (self->manager, data->item);
+}
+
+static void
+reset_all_clicked_cb (CcKeyboardPanel *self)
+{
+  GtkWidget *dialog, *toplevel, *button;
+  guint response;
+
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
+  dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
+                                   GTK_DIALOG_MODAL | GTK_DIALOG_USE_HEADER_BAR | 
GTK_DIALOG_DESTROY_WITH_PARENT,
+                                   GTK_MESSAGE_WARNING,
+                                   GTK_BUTTONS_NONE,
+                                   _("Reset All Shortcuts?"));
+
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                            _("Resetting the shortcuts may affect your custom shortcuts. "
+                                              "This cannot be undone."));
+
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                          _("Cancel"), GTK_RESPONSE_CANCEL,
+                          _("Reset All"), GTK_RESPONSE_ACCEPT,
+                          NULL);
+
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+
+  /* Make the "Reset All" button destructive */
+  button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+  gtk_style_context_add_class (gtk_widget_get_style_context (button), "destructive-action");
+
+  /* Reset shortcuts if accepted */
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  if (response == GTK_RESPONSE_ACCEPT)
+    {
+      gtk_container_foreach (GTK_CONTAINER (self->listbox),
+                             reset_all_shortcuts_cb,
+                             self);
+    }
+
+  gtk_widget_destroy (dialog);
+}
+
+static void
 reset_shortcut_cb (GtkWidget      *reset_button,
                    CcKeyboardItem *item)
 {
@@ -514,6 +578,7 @@ cc_keyboard_panel_class_init (CcKeyboardPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, search_button);
   gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, search_entry);
 
+  gtk_widget_class_bind_template_callback (widget_class, reset_all_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, shortcut_row_activated);
 }
 
diff --git a/panels/keyboard/gnome-keyboard-panel.ui b/panels/keyboard/gnome-keyboard-panel.ui
index c5e38bf..fe68614 100644
--- a/panels/keyboard/gnome-keyboard-panel.ui
+++ b/panels/keyboard/gnome-keyboard-panel.ui
@@ -51,6 +51,34 @@
                 <property name="spacing">12</property>
                 <property name="halign">center</property>
                 <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hexpand">True</property>
+                        <property name="xalign">0.0</property>
+                        <property name="label" translatable="yes">Keyboard Shortcuts</property>
+                        <attributes>
+                          <attribute name="weight" value="bold" />
+                        </attributes>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkButton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">Reset All</property>
+                        <property name="tooltip-text" translatable="yes">Reset all shortcuts to their 
default keybindings</property>
+                        <signal name="clicked" handler="reset_all_clicked_cb" object="CcKeyboardPanel" 
swapped="yes" />
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
                   <object class="GtkFrame">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>


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