[gnome-control-center] keyboard: custom shortcut should require name and command



commit fe9fe99439ce2c741066fe547ceab6991f1b84b5
Author: Marcus Karlsson <mk acc umu se>
Date:   Tue Nov 4 21:45:03 2014 +0100

    keyboard: custom shortcut should require name and command
    
    It is possible to press the Add button in the custom shortcut dialog
    when the name and command fields are empty. Disable the button by
    default, and only enable it when the name and command is non-empty.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739647

 panels/keyboard/gnome-keyboard-panel.ui |    9 +++++----
 panels/keyboard/keyboard-shortcuts.c    |   20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/panels/keyboard/gnome-keyboard-panel.ui b/panels/keyboard/gnome-keyboard-panel.ui
index 73627ad..3d28f72 100644
--- a/panels/keyboard/gnome-keyboard-panel.ui
+++ b/panels/keyboard/gnome-keyboard-panel.ui
@@ -19,7 +19,7 @@
         <property name="title" translatable="yes">Custom Shortcut</property>
         <property name="show_close_button">False</property>
         <child>
-          <object class="GtkButton" id="cancelbutton1">
+          <object class="GtkButton" id="custom-shortcut-cancel-button">
             <property name="label" translatable="yes">_Cancel</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
@@ -36,7 +36,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkButton" id="okbutton1">
+          <object class="GtkButton" id="custom-shortcut-ok-button">
             <property name="label" translatable="yes">_Add</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
@@ -45,6 +45,7 @@
             <property name="use_action_appearance">False</property>
             <property name="use_underline">True</property>
             <property name="valign">center</property>
+            <property name="sensitive">False</property>
             <style>
               <class name="text-button"/>
               <class name="suggested-action"/>
@@ -144,8 +145,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-6">cancelbutton1</action-widget>
-      <action-widget response="-5">okbutton1</action-widget>
+      <action-widget response="-6">custom-shortcut-cancel-button</action-widget>
+      <action-widget response="-5">custom-shortcut-ok-button</action-widget>
     </action-widgets>
   </object>
           <object class="GtkNotebook" id="keyboard_notebook">
diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c
index 3550976..1069310 100644
--- a/panels/keyboard/keyboard-shortcuts.c
+++ b/panels/keyboard/keyboard-shortcuts.c
@@ -92,6 +92,7 @@ static GSettings *binding_settings = NULL;
 static GtkWidget *custom_shortcut_dialog = NULL;
 static GtkWidget *custom_shortcut_name_entry = NULL;
 static GtkWidget *custom_shortcut_command_entry = NULL;
+static GtkWidget *custom_shortcut_ok_button = NULL;
 static GHashTable *kb_system_sections = NULL;
 static GHashTable *kb_apps_sections = NULL;
 static GHashTable *kb_user_sections = NULL;
@@ -1728,6 +1729,20 @@ add_custom_shortcut (GtkTreeView  *tree_view,
 }
 
 static void
+shortcut_entry_changed (GtkEntry *entry,
+                        gpointer  user_data)
+{
+  guint16 name_length;
+  guint16 command_length;
+
+  name_length = gtk_entry_get_text_length (custom_shortcut_name_entry);
+  command_length = gtk_entry_get_text_length (custom_shortcut_command_entry);
+
+  gtk_widget_set_sensitive (custom_shortcut_ok_button,
+                            name_length > 0 && command_length > 0);
+}
+
+static void
 add_button_clicked (GtkWidget  *button,
                     GtkBuilder *builder)
 {
@@ -2051,10 +2066,15 @@ setup_dialog (CcPanel *panel, GtkBuilder *builder)
   /* setup the custom shortcut dialog */
   custom_shortcut_dialog = WID (builder,
                                 "custom-shortcut-dialog");
+  custom_shortcut_ok_button = WID (builder, "custom-shortcut-ok-button");
   custom_shortcut_name_entry = WID (builder,
                                     "custom-shortcut-name-entry");
+  g_signal_connect (custom_shortcut_name_entry, "changed",
+                    G_CALLBACK (shortcut_entry_changed), NULL);
   custom_shortcut_command_entry = WID (builder,
                                        "custom-shortcut-command-entry");
+  g_signal_connect (custom_shortcut_command_entry, "changed",
+                    G_CALLBACK (shortcut_entry_changed), NULL);
   g_signal_connect (WID (builder, "add-toolbutton"),
                     "clicked", G_CALLBACK (add_button_clicked), builder);
   g_signal_connect (WID (builder, "remove-toolbutton"),


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