[Xfce4-commits] <xfce4-settings:master> Merge branch 'jeromeg/keyboard-shortcuts'
Jérôme Guelfucci
noreply at xfce.org
Sun Dec 30 15:44:14 CET 2012
Updating branch refs/heads/master
to f381c4e767e553463f7f5ee997e240f200e49ac5 (commit)
from 3966322dd74753d187f7eedea826a939d35322b6 (commit)
commit f381c4e767e553463f7f5ee997e240f200e49ac5
Merge: 3966322 454bb81
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sun Dec 30 15:36:45 2012 +0100
Merge branch 'jeromeg/keyboard-shortcuts'
commit 454bb81a61aa4743e58db8ef1a142a5995138f39
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sun Dec 30 10:31:42 2012 +0100
Remove ignore_property argument in xfce_keyboard_settings_get_shortcut_info.
This argument was not used and it clutters the logs.
commit cd952f2777ffa11e48c003f0795ba5d55c798340
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Thu Dec 27 11:33:36 2012 +0100
Tweak buttons positions.
Group buttons which act on individual shortcuts to the left and put
"Reset to defaults" with some padding on the right as it will reset all
shortcuts.
commit 0b39613666ee95df3dbba6a5c9d1470799104a34
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Thu Dec 27 11:28:16 2012 +0100
Show shortcut label when editing a shortcut.
commit 993d61b8585607913b21af6b81f74cc94bcb9db5
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sat Dec 22 12:04:45 2012 +0100
Center the buttons with an alignment.
commit 762ae8ed668508af536bc069ecfdde67bb9219ed
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sat Dec 22 10:16:21 2012 +0100
Improve layout of command dialog.
commit e5895031ef606614ec7489d1cdd2f840af18d6f5
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sat Dec 22 10:02:58 2012 +0100
Add comments.
commit 1161ff583b2c946715826a514a5489a7309dacea
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sat Dec 22 10:00:57 2012 +0100
Improve the contents of the command dialog.
When creating a shortcut show an explanation instead of an empty
shortcut label. Show the shortcut label when we have one instead of the
raw Gtk+ accelerator string.
commit b1b9fa1598e54093c4a9682b875f083dfb0a2a74
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Thu Dec 20 11:03:03 2012 +0100
Set parent window for the conflict dialog.
commit 849aa7824f8a482496c05b1fd77099e062d1c92b
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Thu Dec 20 00:02:17 2012 +0100
Fix treeview update when handling conflict (bug #8856).
In a conflict, when we chose to use the new command for the shortcut, we
need to remove the old shortcut manually from the treeview because the
signals are not necessarilly received in the logical order.
commit 5e1aedff6e3b9b84429d38db4f0558d423cf7d08
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Wed Dec 19 23:03:56 2012 +0100
Revert "Keep the shortcut dialog above other windows."
This reverts commit a04edfc41ab2035383793ca8315e2e61351108c2.
Error and conflict dialogs are kept under the grab dialog which makes
them unusable.
commit 276875f5f784894b1c75c1b7dd93b599a6235a4c
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Tue Dec 18 23:59:02 2012 +0100
Show the label instead of the accelerator string.
The dialog is far friendlier that way: we have human readable and
translated strings representing the shortcut instead of a bare Gtk+
accelerator.
commit 6b952f0a50dd17fb5d73b73bf37df9ac6519983c
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Tue Dec 18 23:38:48 2012 +0100
Add a button to edit keyboard shortcuts (bug #7600).
dialogs/keyboard-settings/command-dialog.c | 58 ++++-
dialogs/keyboard-settings/keyboard-dialog.glade | 127 ++++++----
dialogs/keyboard-settings/xfce-keyboard-settings.c | 247 ++++++++++++++++++--
3 files changed, 349 insertions(+), 83 deletions(-)
diff --git a/dialogs/keyboard-settings/command-dialog.c b/dialogs/keyboard-settings/command-dialog.c
index 7216c7b..3d24f18 100644
--- a/dialogs/keyboard-settings/command-dialog.c
+++ b/dialogs/keyboard-settings/command-dialog.c
@@ -97,10 +97,12 @@ command_dialog_create_contents (CommandDialog *dialog,
const gchar *action,
gboolean snotify)
{
+ GtkWidget *alignment;
GtkWidget *button;
- GtkWidget *table;
- GtkWidget *label;
+ GtkWidget *content_box;
GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *table;
/* Set dialog title and icon */
gtk_window_set_title (GTK_WINDOW (dialog), _("Shortcut Command"));
@@ -120,22 +122,56 @@ command_dialog_create_contents (CommandDialog *dialog,
gtk_widget_grab_default (button);
gtk_widget_show (button);
+ /* Set the main box layout */
+ alignment = gtk_alignment_new (0, 0, 1, 1);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 6, 12, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (alignment), 0);
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+ alignment);
+ gtk_widget_show (alignment);
+
+ content_box = gtk_vbox_new (FALSE, 6);
+ gtk_container_set_border_width (GTK_CONTAINER (content_box), 6);
+ gtk_container_add (GTK_CONTAINER (alignment), content_box);
+ gtk_widget_show (content_box);
+
+ if (!shortcut)
+ {
+ /* No shortcut passed, means that we are creating a new one */
+
+ const gchar *explanation;
+ gchar *explanation_markup;
+
+ label = gtk_label_new (NULL);
+
+ explanation = _("Enter the command you want to trigger with a shortcut.");
+ explanation_markup = g_strdup_printf ("<i>%s</i>", explanation);
+ gtk_label_set_markup (GTK_LABEL (label), explanation_markup);
+ gtk_box_pack_start (GTK_BOX (content_box), label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+ }
+
table = gtk_table_new (3, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_table_set_col_spacings (GTK_TABLE (table), 12);
gtk_container_set_border_width (GTK_CONTAINER (table), 6);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), table);
+ gtk_container_add (GTK_CONTAINER (content_box), table);
gtk_widget_show (table);
- label = gtk_label_new (_("Shortcut:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (label);
+ if (shortcut)
+ {
+ /* We are editing an existing shortcut */
- 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);
+ label = gtk_label_new (_("Shortcut:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ 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);
+ }
label = gtk_label_new (_("Command:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
diff --git a/dialogs/keyboard-settings/keyboard-dialog.glade b/dialogs/keyboard-settings/keyboard-dialog.glade
index af5c861..72aec7f 100644
--- a/dialogs/keyboard-settings/keyboard-dialog.glade
+++ b/dialogs/keyboard-settings/keyboard-dialog.glade
@@ -8,6 +8,11 @@
<property name="can_focus">False</property>
<property name="stock">gtk-revert-to-saved</property>
</object>
+ <object class="GtkImage" id="image2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-revert-to-saved</property>
+ </object>
<object class="XfceTitledDialog" id="keyboard-layout-selection-dialog">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Keyboard layout selection</property>
@@ -554,60 +559,85 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox2">
+ <object class="GtkAlignment" id="alignment8">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">12</property>
+ <property name="yalign">0</property>
+ <property name="xscale">0</property>
+ <property name="yscale">0</property>
<child>
- <object class="GtkButton" id="add_shortcut_button">
- <property name="label">gtk-add</property>
- <property name="use_action_appearance">False</property>
+ <object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="delete_shortcut_button">
- <property name="label">gtk-remove</property>
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="reset_shortcuts_button">
- <property name="label" translatable="yes">Reset to _Defaults</property>
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="image">image1</property>
- <property name="use_underline">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkButton" id="add_shortcut_button">
+ <property name="label">gtk-add</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="edit_shortcut_button">
+ <property name="label">gtk-edit</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="delete_shortcut_button">
+ <property name="label">gtk-remove</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="reset_shortcuts_button">
+ <property name="label" translatable="yes">Reset to _Defaults</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">image1</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">15</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
@@ -1007,12 +1037,6 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
- <object class="GtkSizeGroup" id="sizegroup1">
- <widgets>
- <widget name="add_shortcut_button"/>
- <widget name="delete_shortcut_button"/>
- </widgets>
- </object>
<object class="GtkAdjustment" id="xkb_key_repeat_delay">
<property name="lower">10</property>
<property name="upper">1000</property>
@@ -1027,4 +1051,5 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkSizeGroup" id="sizegroup1"/>
</interface>
diff --git a/dialogs/keyboard-settings/xfce-keyboard-settings.c b/dialogs/keyboard-settings/xfce-keyboard-settings.c
index 5e7a01d..b6f8b0c 100644
--- a/dialogs/keyboard-settings/xfce-keyboard-settings.c
+++ b/dialogs/keyboard-settings/xfce-keyboard-settings.c
@@ -58,6 +58,7 @@ enum
COMMAND_COLUMN,
SHORTCUT_COLUMN,
SNOTIFY_COLUMN,
+ SHORTCUT_LABEL_COLUMN,
N_COLUMNS
};
@@ -119,8 +120,7 @@ static gboolean xfce_keyboard_settings_validate_shortcut (X
const gchar *shortcut,
XfceKeyboardSettings *settings);
static XfceKeyboardShortcutInfo *xfce_keyboard_settings_get_shortcut_info (XfceKeyboardSettings *settings,
- const gchar *shortcut,
- const gchar *ignore_property);
+ const gchar *shortcut);
static void xfce_keyboard_settings_free_shortcut_info (XfceKeyboardShortcutInfo *info);
static void xfce_keyboard_settings_shortcut_added (XfceShortcutsProvider *provider,
const gchar *shortcut,
@@ -130,6 +130,7 @@ static void xfce_keyboard_settings_shortcut_removed (X
XfceKeyboardSettings *settings);
static void xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings,
GtkButton *button);
+static void xfce_keyboard_settings_edit_button_clicked (XfceKeyboardSettings *settings);
static void xfce_keyboard_settings_delete_button_clicked (XfceKeyboardSettings *settings);
static void xfce_keyboard_settings_reset_button_clicked (XfceKeyboardSettings *settings);
@@ -387,7 +388,7 @@ xfce_keyboard_settings_constructed (GObject *object)
g_signal_connect (kbd_shortcuts_view, "row-activated", G_CALLBACK (xfce_keyboard_settings_row_activated), settings);
/* Create list store for keyboard shortcuts */
- list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
+ list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store), COMMAND_COLUMN, GTK_SORT_ASCENDING);
gtk_tree_view_set_model (GTK_TREE_VIEW (kbd_shortcuts_view), GTK_TREE_MODEL (list_store));
@@ -398,13 +399,17 @@ xfce_keyboard_settings_constructed (GObject *object)
/* Create shortcut column */
renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes (_("Shortcut"), renderer, "text", SHORTCUT_COLUMN, NULL);
+ column = gtk_tree_view_column_new_with_attributes (_("Shortcut"), renderer, "text", SHORTCUT_LABEL_COLUMN, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (kbd_shortcuts_view), column);
/* Connect to add button */
button = gtk_builder_get_object (GTK_BUILDER (settings), "add_shortcut_button");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (xfce_keyboard_settings_add_button_clicked), settings);
+ /* Connect to edit button */
+ button = gtk_builder_get_object (GTK_BUILDER (settings), "edit_shortcut_button");
+ g_signal_connect_swapped (button, "clicked", G_CALLBACK (xfce_keyboard_settings_edit_button_clicked), settings);
+
/* Connect to remove button */
button = gtk_builder_get_object (GTK_BUILDER (settings), "delete_shortcut_button");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (xfce_keyboard_settings_delete_button_clicked), settings);
@@ -586,9 +591,12 @@ static void
_xfce_keyboard_settings_load_shortcut (XfceShortcut *shortcut,
XfceKeyboardSettings *settings)
{
- GtkTreeModel *tree_model;
- GtkTreeIter iter;
- GObject *tree_view;
+ GdkModifierType modifiers;
+ GtkTreeModel *tree_model;
+ GtkTreeIter iter;
+ GObject *tree_view;
+ guint keyval;
+ gchar *label;
g_return_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings));
g_return_if_fail (shortcut != NULL);
@@ -600,11 +608,18 @@ _xfce_keyboard_settings_load_shortcut (XfceShortcut *shortcut,
tree_view = gtk_builder_get_object (GTK_BUILDER (settings), "kbd_shortcuts_view");
tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
+ /* Get the shortcut label */
+ gtk_accelerator_parse (shortcut->shortcut, &keyval, &modifiers);
+ label = gtk_accelerator_get_label (keyval, modifiers);
+
gtk_list_store_append (GTK_LIST_STORE (tree_model), &iter);
gtk_list_store_set (GTK_LIST_STORE (tree_model), &iter,
COMMAND_COLUMN, shortcut->command,
SHORTCUT_COLUMN, shortcut->shortcut,
- SNOTIFY_COLUMN, shortcut->snotify, -1);
+ SNOTIFY_COLUMN, shortcut->snotify,
+ SHORTCUT_LABEL_COLUMN, label, -1);
+
+ g_free (label);
}
@@ -712,14 +727,17 @@ xfce_keyboard_settings_edit_command (XfceKeyboardSettings *settings,
/* Convert tree path to tree iter */
if (G_LIKELY (gtk_tree_model_get_iter (model, &iter, path)))
{
+ gchar *shortcut_label;
+
/* Read shortcut and current command from the activated row */
gtk_tree_model_get (model, &iter,
COMMAND_COLUMN, &command,
SHORTCUT_COLUMN, &shortcut,
+ SHORTCUT_LABEL_COLUMN, &shortcut_label,
SNOTIFY_COLUMN, &snotify, -1);
/* Request a new command from the user */
- dialog = command_dialog_new (shortcut, command, snotify);
+ dialog = command_dialog_new (shortcut_label, command, snotify);
response = command_dialog_run (COMMAND_DIALOG (dialog), GTK_WIDGET (tree_view));
if (G_LIKELY (response == GTK_RESPONSE_OK))
@@ -744,6 +762,7 @@ xfce_keyboard_settings_edit_command (XfceKeyboardSettings *settings,
gtk_widget_destroy (dialog);
/* Free strings */
+ g_free (shortcut_label);
g_free (shortcut);
g_free (command);
}
@@ -757,7 +776,6 @@ xfce_keyboard_settings_validate_shortcut (XfceShortcutDialog *dialog,
XfceKeyboardSettings *settings)
{
XfceKeyboardShortcutInfo *info;
- gchar *property;
gboolean accepted = TRUE;
gint response;
@@ -773,15 +791,14 @@ xfce_keyboard_settings_validate_shortcut (XfceShortcutDialog *dialog,
if (G_UNLIKELY (g_utf8_collate (shortcut, "Return") == 0 || g_utf8_collate (shortcut, "space") == 0))
return FALSE;
- DBG ("shortcut = %s", shortcut);
+ DBG ("Validating shortcut = %s", shortcut);
- property = g_strconcat (CUSTOM_BASE_PROPERTY, "/", shortcut, NULL);
- info = xfce_keyboard_settings_get_shortcut_info (settings, shortcut, property);
- g_free (property);
+ info = xfce_keyboard_settings_get_shortcut_info (settings, shortcut);
if (G_UNLIKELY (info != NULL))
{
- response = xfce_shortcut_conflict_dialog (xfce_shortcuts_provider_get_name (settings->priv->provider),
+ response = xfce_shortcut_conflict_dialog (GTK_WINDOW (dialog),
+ xfce_shortcuts_provider_get_name (settings->priv->provider),
xfce_shortcuts_provider_get_name (info->provider),
shortcut,
xfce_shortcut_dialog_get_action_name (dialog),
@@ -789,9 +806,23 @@ xfce_keyboard_settings_validate_shortcut (XfceShortcutDialog *dialog,
FALSE);
if (G_UNLIKELY (response == GTK_RESPONSE_ACCEPT))
+ {
+ /* We want to use the shortcut with the new owner */
+ DBG ("We want to use %s with %s", shortcut,
+ xfce_shortcut_dialog_get_action_name (dialog));
xfce_shortcuts_provider_reset_shortcut (info->provider, shortcut);
+
+ /*Remove the shortcut manually from the treeview */
+ xfce_keyboard_settings_shortcut_removed (settings->priv->provider,
+ shortcut,
+ settings);
+ }
else
- accepted = FALSE;
+ {
+ /* We want to keep the old owner */
+ DBG ("We want to keep using %s with %s", shortcut, info->shortcut->command);
+ accepted = FALSE;
+ }
xfce_keyboard_settings_free_shortcut_info (info);
}
@@ -803,8 +834,7 @@ xfce_keyboard_settings_validate_shortcut (XfceShortcutDialog *dialog,
static XfceKeyboardShortcutInfo *
xfce_keyboard_settings_get_shortcut_info (XfceKeyboardSettings *settings,
- const gchar *shortcut,
- const gchar *ignore_property)
+ const gchar *shortcut)
{
XfceKeyboardShortcutInfo *info = NULL;
GList *iter;
@@ -814,7 +844,7 @@ xfce_keyboard_settings_get_shortcut_info (XfceKeyboardSettings *settings,
g_return_val_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings), FALSE);
g_return_val_if_fail (shortcut != NULL, FALSE);
- DBG ("shortcut = %s, ignore_property = %s", shortcut, ignore_property);
+ DBG ("Looking for shortcut info for %s", shortcut);
providers = xfce_shortcuts_provider_get_providers ();
@@ -829,7 +859,6 @@ xfce_keyboard_settings_get_shortcut_info (XfceKeyboardSettings *settings,
if (G_LIKELY (sc != NULL))
{
- /* Check ignore_property and change shortcut info struct */
info = g_new0 (XfceKeyboardShortcutInfo, 1);
info->provider = g_object_ref (iter->data);
info->shortcut = sc;
@@ -873,11 +902,25 @@ xfce_keyboard_settings_shortcut_added (XfceShortcutsProvider *provider,
if (G_LIKELY (sc != NULL))
{
+ GdkModifierType modifiers;
+ guint keyval;
+ gchar *label;
+
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+
+ /* Get the shortcut label */
+ gtk_accelerator_parse (sc->shortcut, &keyval, &modifiers);
+ label = gtk_accelerator_get_label (keyval, modifiers);
+
+ DBG ("Add shortcut %s for command %s", shortcut, sc->command);
+
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
SHORTCUT_COLUMN, shortcut,
COMMAND_COLUMN, sc->command,
- SNOTIFY_COLUMN, sc->snotify, -1);
+ SNOTIFY_COLUMN, sc->snotify,
+ SHORTCUT_LABEL_COLUMN, label, -1);
+
+ g_free (label);
xfce_shortcut_free (sc);
}
@@ -923,6 +966,8 @@ xfce_keyboard_settings_shortcut_removed (XfceShortcutsProvider *provider,
view = gtk_builder_get_object (GTK_BUILDER (settings), "kbd_shortcuts_view");
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+ DBG ("Remove shortcut %s from treeview", shortcut);
+
gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) _xfce_keyboard_settings_remove_shortcut,
(gpointer) shortcut);
}
@@ -985,6 +1030,7 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings,
shortcut = xfce_shortcut_dialog_get_shortcut (XFCE_SHORTCUT_DIALOG (shortcut_dialog));
/* Save the new shortcut to xfconf */
+ DBG ("Save shortcut %s with command %s to Xfconf", shortcut, command);
xfce_shortcuts_provider_set_shortcut (settings->priv->provider, shortcut, command, snotify);
}
@@ -999,6 +1045,165 @@ xfce_keyboard_settings_add_button_clicked (XfceKeyboardSettings *settings,
static void
+xfce_keyboard_settings_edit_button_clicked (XfceKeyboardSettings *settings)
+{
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GObject *view;
+ GList *rows;
+ GList *row_iter;
+ GList *row_references = NULL;
+
+ DBG ("edit!");
+
+ g_return_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings));
+
+ view = gtk_builder_get_object (GTK_BUILDER (settings), "kbd_shortcuts_view");
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ rows = gtk_tree_selection_get_selected_rows (selection, &model);
+
+ for (row_iter = g_list_first (rows); row_iter != NULL; row_iter = g_list_next (row_iter))
+ row_references = g_list_append (row_references, gtk_tree_row_reference_new (model, row_iter->data));
+
+ for (row_iter = g_list_first (row_references); row_iter != NULL; row_iter = g_list_next (row_iter))
+ {
+ GtkTreePath *path;
+
+ path = gtk_tree_row_reference_get_path (row_iter->data);
+
+ /* Conver tree path to tree iter */
+ if (G_LIKELY (gtk_tree_model_get_iter (model, &iter, path)))
+ {
+ GtkWidget *command_dialog;
+ gboolean finished;
+ gboolean snotify;
+ gchar *shortcut_label;
+ gchar *shortcut;
+ gchar *command;
+ gint response;
+
+ /* Read row values */
+ gtk_tree_model_get (model, &iter,
+ SHORTCUT_LABEL_COLUMN, &shortcut_label,
+ SHORTCUT_COLUMN, &shortcut,
+ COMMAND_COLUMN, &command,
+ SNOTIFY_COLUMN, &snotify,
+ -1);
+
+ DBG ("Edit shortcut %s / command %s", shortcut, command);
+
+ /* Create command dialog */
+ command_dialog = command_dialog_new (shortcut_label, command, snotify);
+
+ /* Run command dialog until a valid (non-empty) command is entered or the dialog is cancelled */
+ do
+ {
+ response = command_dialog_run (COMMAND_DIALOG (command_dialog), GTK_WIDGET (view));
+
+ if (G_UNLIKELY (response == GTK_RESPONSE_OK &&
+ g_utf8_strlen (command_dialog_get_command (COMMAND_DIALOG (command_dialog)), -1) == 0))
+ xfce_dialog_show_error (GTK_WINDOW (command_dialog), NULL, _("Shortcut command may not be empty."));
+ else
+ finished = TRUE;
+ }
+ while (!finished);
+
+ /* Abort if the dialog was cancelled */
+ if (G_UNLIKELY (response == GTK_RESPONSE_OK))
+ {
+ const gchar *new_command;
+ GtkWidget *shortcut_dialog;
+ gboolean new_snotify;
+ GObject *parent;
+
+ /* Get the command */
+ new_command = command_dialog_get_command (COMMAND_DIALOG (command_dialog));
+ new_snotify = command_dialog_get_snotify (COMMAND_DIALOG (command_dialog));
+
+ /* Hide the command dialog */
+ gtk_widget_hide (command_dialog);
+
+ /* Create shortcut dialog */
+ shortcut_dialog =
+ xfce_shortcut_dialog_new ("commands",
+ new_command,
+ new_command);
+
+ g_signal_connect (shortcut_dialog, "validate-shortcut",
+ G_CALLBACK (xfce_keyboard_settings_validate_shortcut),
+ settings);
+
+ /* Try to keep the window above as it grabs the keyboard, we don't
+ * want users to wonder why the keyboard does not work in another
+ * window */
+ gtk_window_set_keep_above (GTK_WINDOW (shortcut_dialog), TRUE);
+
+ /* 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))
+ {
+ const gchar *new_shortcut;
+ gboolean test_new_shortcut;
+
+ /* Get shortcut */
+ new_shortcut =
+ xfce_shortcut_dialog_get_shortcut (XFCE_SHORTCUT_DIALOG (shortcut_dialog));
+
+ if (g_strcmp0 (command, new_command) != 0
+ || (test_new_shortcut = (g_strcmp0 (shortcut, new_shortcut) != 0))
+ || snotify != new_snotify)
+ {
+ /* Remove the row because we add new one from the
+ * shortcut-added signal */
+ gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+
+ if (test_new_shortcut)
+ /* Remove old keyboard shortcut via xfconf */
+ xfce_shortcuts_provider_reset_shortcut (settings->priv->provider,
+ shortcut);
+
+ /* Save settings */
+ xfce_shortcuts_provider_set_shortcut (settings->priv->provider,
+ new_shortcut,
+ new_command,
+ new_snotify);
+ }
+
+ }
+
+ /* Destroy the shortcut dialog */
+ gtk_widget_destroy (shortcut_dialog);
+ }
+
+ g_free (shortcut_label);
+ g_free (shortcut);
+ g_free (command);
+ gtk_widget_destroy (command_dialog);
+ }
+
+ gtk_tree_path_free (path);
+ }
+
+ /* Free row reference list */
+ g_list_foreach (row_references, (GFunc) gtk_tree_row_reference_free, NULL);
+ g_list_free (row_references);
+
+ /* Free row list */
+ g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (rows);
+}
+
+
+
+static void
xfce_keyboard_settings_delete_button_clicked (XfceKeyboardSettings *settings)
{
GtkTreeSelection *selection;
More information about the Xfce4-commits
mailing list