From 986d4526ffc175917be47f40bba0b4b0606e104a Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sat, 11 Feb 2012 23:34:06 +0300 Subject: [PATCH] Added an Assign button to keyboard shortcuts dialog Added an Assign button to the keyboard dialog when creating a new shortcut. Clicking that button pops up the map key dialog instead of after clicking the OK button. For bug 5414 --- dialogs/keyboard-settings/command-dialog.c | 77 +++++++++++++++++--- dialogs/keyboard-settings/command-dialog.h | 3 + dialogs/keyboard-settings/xfce-keyboard-settings.c | 78 ++++++++++++------- 3 files changed, 119 insertions(+), 39 deletions(-) diff --git a/dialogs/keyboard-settings/command-dialog.c b/dialogs/keyboard-settings/command-dialog.c index 7216c7b..7aeb3e5 100644 --- a/dialogs/keyboard-settings/command-dialog.c +++ b/dialogs/keyboard-settings/command-dialog.c @@ -30,17 +30,21 @@ -static void command_dialog_create_contents (CommandDialog *dialog, - const gchar *shortcut, - const gchar *action, - gboolean snotify); -static void command_dialog_button_clicked (CommandDialog *dialog); +static void command_dialog_create_contents (CommandDialog *dialog, + const gchar *shortcut, + const gchar *action, + gboolean snotify); +static void command_dialog_button_clicked (CommandDialog *dialog); +static void command_dialog_shortcut_clicked (CommandDialog *dialog); struct _CommandDialogClass { XfceTitledDialogClass __parent__; + + /*< signals >*/ + void (*assign_shortcut)(CommandDialog *command); }; struct _CommandDialog @@ -49,6 +53,7 @@ struct _CommandDialog GtkWidget *entry; GtkWidget *button; + GtkWidget *shortcut; GtkWidget *sn_option; }; @@ -57,11 +62,25 @@ struct _CommandDialog G_DEFINE_TYPE (CommandDialog, command_dialog, XFCE_TYPE_TITLED_DIALOG) +enum +{ + ASSIGN_SHORTCUT_SIGNAL, + LAST_SIGNAL, +}; + +static guint command_dialog_signals[LAST_SIGNAL] = { 0, }; + + static void command_dialog_class_init (CommandDialogClass *klass) { - + command_dialog_signals[ASSIGN_SHORTCUT_SIGNAL] = g_signal_new ( + "assign-shortcut", + G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (CommandDialogClass, assign_shortcut), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } @@ -132,10 +151,19 @@ command_dialog_create_contents (CommandDialog *dialog, gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); - label = gtk_label_new (shortcut); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show (label); + hbox = gtk_hbox_new (FALSE, 6); + gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0); + gtk_widget_show (hbox); + + dialog->shortcut = gtk_label_new (shortcut); + gtk_misc_set_alignment (GTK_MISC (dialog->shortcut), 0.0, 0.5); + gtk_container_add (GTK_CONTAINER (hbox), dialog->shortcut); + gtk_widget_show (dialog->shortcut); + + button = gtk_button_new_with_mnemonic (_("_Assign")); + g_signal_connect_swapped (button, "clicked", G_CALLBACK (command_dialog_shortcut_clicked), dialog); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0); + gtk_widget_show (button); label = gtk_label_new (_("Command:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); @@ -167,6 +195,25 @@ command_dialog_create_contents (CommandDialog *dialog, +void +command_dialog_set_shortcut (CommandDialog *dialog, + const gchar *shortcut) +{ + g_return_if_fail (IS_COMMAND_DIALOG (dialog)); + gtk_label_set_text (GTK_LABEL (dialog->shortcut), shortcut); +} + + + +const char* +command_dialog_get_shortcut (CommandDialog *dialog) +{ + g_return_val_if_fail (IS_COMMAND_DIALOG (dialog), NULL); + return gtk_label_get_text (GTK_LABEL (dialog->shortcut)); +} + + + const char* command_dialog_get_command (CommandDialog *dialog) { @@ -290,3 +337,13 @@ command_dialog_button_clicked (CommandDialog *dialog) /* Destroy the dialog */ gtk_widget_destroy (chooser); } + + + +static void +command_dialog_shortcut_clicked (CommandDialog *dialog) +{ + g_return_if_fail (IS_COMMAND_DIALOG (dialog)); + + g_signal_emit ( G_OBJECT (dialog), command_dialog_signals[ASSIGN_SHORTCUT_SIGNAL], 0); +} diff --git a/dialogs/keyboard-settings/command-dialog.h b/dialogs/keyboard-settings/command-dialog.h index 5fe229f..2095a7e 100644 --- a/dialogs/keyboard-settings/command-dialog.h +++ b/dialogs/keyboard-settings/command-dialog.h @@ -39,6 +39,9 @@ GType command_dialog_get_type (void) G_GNUC_CONST; GtkWidget *command_dialog_new (const gchar *shortcut, const gchar *action, gboolean snotify); +void command_dialog_set_shortcut (CommandDialog *dialog, + const gchar *shortcut); +const char *command_dialog_get_shortcut (CommandDialog *dialog); const char *command_dialog_get_command (CommandDialog *dialog); gboolean command_dialog_get_snotify (CommandDialog *dialog); gint command_dialog_run (CommandDialog *dialog, diff --git a/dialogs/keyboard-settings/xfce-keyboard-settings.c b/dialogs/keyboard-settings/xfce-keyboard-settings.c index 8776a69..848445c 100644 --- a/dialogs/keyboard-settings/xfce-keyboard-settings.c +++ b/dialogs/keyboard-settings/xfce-keyboard-settings.c @@ -121,6 +121,8 @@ static void xfce_keyboard_settings_add_button_clicked (X GtkButton *button); static void xfce_keyboard_settings_delete_button_clicked (XfceKeyboardSettings *settings); static void xfce_keyboard_settings_reset_button_clicked (XfceKeyboardSettings *settings); +static void xfce_keyboard_settings_assign_shortcut_dialog(CommandDialog *command_dialog, + XfceKeyboardSettings *settings); #ifdef HAVE_LIBXKLAVIER @@ -834,8 +836,6 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings, GtkButton *button) { GtkWidget *command_dialog; - GtkWidget *shortcut_dialog; - GObject *parent; const gchar *shortcut; const gchar *command; gboolean finished = FALSE; @@ -847,6 +847,9 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings, /* Create command dialog */ command_dialog = command_dialog_new (NULL, NULL, FALSE); + g_signal_connect (command_dialog, "assign-shortcut", + G_CALLBACK (xfce_keyboard_settings_assign_shortcut_dialog), settings); + /* Run command dialog until a vaild (non-empty) command is entered or the dialog is cancelled */ do { @@ -863,36 +866,16 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings, /* Abort if the dialog was cancelled */ if (G_UNLIKELY (response == GTK_RESPONSE_OK)) { - /* Get the command */ - command = command_dialog_get_command (COMMAND_DIALOG (command_dialog)); - snotify = command_dialog_get_snotify (COMMAND_DIALOG (command_dialog)); - - /* Hide the command dialog */ - gtk_widget_hide (command_dialog); + /* Update all the values */ + shortcut = command_dialog_get_shortcut (COMMAND_DIALOG (command_dialog)); + command = command_dialog_get_command (COMMAND_DIALOG (command_dialog)); + snotify = command_dialog_get_snotify (COMMAND_DIALOG (command_dialog)); - /* Create shortcut dialog */ - shortcut_dialog = xfce_shortcut_dialog_new ("commands", command, command); - g_signal_connect (shortcut_dialog, "validate-shortcut", G_CALLBACK (xfce_keyboard_settings_validate_shortcut), settings); - - /* Run shortcut dialog until a valid shortcut is entered or the dialog is cancelled */ - parent = gtk_builder_get_object (GTK_BUILDER (settings), "keyboard-shortcuts-dialog"); - response = xfce_shortcut_dialog_run (XFCE_SHORTCUT_DIALOG (shortcut_dialog), GTK_WIDGET (parent)); - - /* Only continue if the shortcut dialog succeeded */ - if (G_LIKELY (response == GTK_RESPONSE_OK)) - { - /* Get shortcut */ - shortcut = xfce_shortcut_dialog_get_shortcut (XFCE_SHORTCUT_DIALOG (shortcut_dialog)); - - /* Save the new shortcut to xfconf */ - xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut, command, snotify); - } - - /* Destroy the shortcut dialog */ - gtk_widget_destroy (shortcut_dialog); + /* Save the new shortcut to xfconf */ + xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut, command, snotify); } - /* Destroy the shortcut dialog */ + /* Destroy the command dialog */ gtk_widget_destroy (command_dialog); } @@ -976,6 +959,43 @@ xfce_keyboard_settings_reset_button_clicked (XfceKeyboardSettings *settings) +static void +xfce_keyboard_settings_assign_shortcut_dialog (CommandDialog *command_dialog, + XfceKeyboardSettings *settings) +{ + GtkWidget *shortcut_dialog; + GObject *parent; + const gchar *shortcut; + const gchar *command; + gint response; + + /* Get the command */ + command = command_dialog_get_command (COMMAND_DIALOG (command_dialog)); + + /* Create shortcut dialog */ + shortcut_dialog = xfce_shortcut_dialog_new ("commands", command, command); + g_signal_connect (shortcut_dialog, "validate-shortcut", G_CALLBACK (xfce_keyboard_settings_validate_shortcut), settings); + + /* Run shortcut dialog until a valid shortcut is entered or the dialog is cancelled */ + parent = gtk_builder_get_object (GTK_BUILDER (settings), "keyboard-shortcuts-dialog"); + response = xfce_shortcut_dialog_run (XFCE_SHORTCUT_DIALOG (shortcut_dialog), GTK_WIDGET (parent)); + + /* Only update if the shortcut dialog succeeded */ + if (G_LIKELY (response == GTK_RESPONSE_OK)) + { + /* Get the shortcut */ + shortcut = xfce_shortcut_dialog_get_shortcut (XFCE_SHORTCUT_DIALOG (shortcut_dialog)); + + /* Update the command dialog */ + command_dialog_set_shortcut (command_dialog, shortcut); + } + + /* Destroy the shortcut dialog */ + gtk_widget_destroy (shortcut_dialog); +} + + + #ifdef HAVE_LIBXKLAVIER static gchar * -- 1.7.5.4