[gnome-control-center] Make custom keybinding editing work again
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] Make custom keybinding editing work again
- Date: Fri, 21 Jan 2011 07:04:14 +0000 (UTC)
commit 110b7fe8a83a43a59e27aad39784f1f3921e258a
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jan 21 02:03:34 2011 -0500
Make custom keybinding editing work again
Only allow adding custom bindings in their section.
Fix up memory management when removing bindings.
panels/keyboard/keyboard-shortcuts.c | 63 +++++++++++++++++++--------------
1 files changed, 36 insertions(+), 27 deletions(-)
---
diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-shortcuts.c
index 5e9b8b5..71599ef 100644
--- a/panels/keyboard/keyboard-shortcuts.c
+++ b/panels/keyboard/keyboard-shortcuts.c
@@ -853,6 +853,26 @@ description_set_func (GtkTreeViewColumn *tree_column,
}
static void
+shortcut_selection_changed (GtkTreeSelection *selection, gpointer data)
+{
+ GtkWidget *button = data;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ KeyEntry *key;
+ gboolean can_remove;
+
+ can_remove = FALSE;
+ if (gtk_tree_selection_get_selected (selection, &model, &iter))
+ {
+ gtk_tree_model_get (model, &iter, DETAIL_KEYENTRY_COLUMN, &key, -1);
+ if (key && key->command != NULL && key->editable)
+ can_remove = TRUE;
+ }
+
+ gtk_widget_set_sensitive (button, can_remove);
+}
+
+static void
section_selection_changed (GtkTreeSelection *selection, gpointer data)
{
GtkTreeIter iter;
@@ -865,9 +885,13 @@ section_selection_changed (GtkTreeSelection *selection, gpointer data)
GtkWidget *shortcut_treeview;
GtkTreeModel *shortcut_model;
gchar *description;
+ gint group;
gint i;
- gtk_tree_model_get (model, &iter, SECTION_DESCRIPTION_COLUMN, &description, -1);
+ gtk_tree_model_get (model, &iter,
+ SECTION_DESCRIPTION_COLUMN, &description,
+ SECTION_GROUP_COLUMN, &group, -1);
+
keys = g_hash_table_lookup (kb_sections, description);
if (keys == NULL)
{
@@ -875,6 +899,10 @@ section_selection_changed (GtkTreeSelection *selection, gpointer data)
return;
}
+ gtk_widget_set_sensitive (WID (builder, "add-toolbutton"),
+ group == BINDING_GROUP_USER);
+ gtk_widget_set_sensitive (WID (builder, "remove-toolbutton"), FALSE);
+
/* Fill the shortcut treeview with the keys for the selected section */
shortcut_treeview = GTK_WIDGET (gtk_builder_get_object (builder, "shortcut_treeview"));
shortcut_model = gtk_tree_view_get_model (GTK_TREE_VIEW (shortcut_treeview));
@@ -894,26 +922,6 @@ section_selection_changed (GtkTreeSelection *selection, gpointer data)
}
}
-static void
-shortcut_selection_changed (GtkTreeSelection *selection, gpointer data)
-{
- GtkWidget *button = data;
- GtkTreeModel *model;
- GtkTreeIter iter;
- KeyEntry *key;
- gboolean can_remove;
-
- can_remove = FALSE;
- if (gtk_tree_selection_get_selected (selection, &model, &iter))
- {
- gtk_tree_model_get (model, &iter, DETAIL_KEYENTRY_COLUMN, &key, -1);
- if (key && key->command != NULL && key->editable)
- can_remove = TRUE;
- }
-
- gtk_widget_set_sensitive (button, can_remove);
-}
-
typedef struct
{
GtkTreeView *tree_view;
@@ -960,10 +968,10 @@ edit_custom_shortcut (KeyEntry *key)
static gboolean
remove_custom_shortcut (GtkTreeModel *model, GtkTreeIter *iter)
{
- GtkTreeIter parent;
GConfClient *client;
gchar *base;
KeyEntry *key;
+ GPtrArray *keys_array;
gtk_tree_model_get (model, iter,
DETAIL_KEYENTRY_COLUMN, &key,
@@ -990,6 +998,9 @@ remove_custom_shortcut (GtkTreeModel *model, GtkTreeIter *iter)
gconf_client_suggest_sync (client, NULL);
g_object_unref (client);
+ keys_array = g_hash_table_lookup (kb_sections, _("Custom Shortcuts"));
+ g_ptr_array_remove (keys_array, key);
+
g_free (key->gconf_key);
g_free (key->description);
g_free (key->desc_gconf_key);
@@ -997,10 +1008,7 @@ remove_custom_shortcut (GtkTreeModel *model, GtkTreeIter *iter)
g_free (key->cmd_gconf_key);
g_free (key);
- gtk_tree_model_iter_parent (model, &parent, iter);
- gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
- if (!gtk_tree_model_iter_has_child (model, &parent))
- gtk_tree_store_remove (GTK_TREE_STORE (model), &parent);
+ gtk_list_store_remove (GTK_LIST_STORE (model), iter);
return TRUE;
}
@@ -1023,7 +1031,7 @@ update_custom_shortcut (GtkTreeModel *model, GtkTreeIter *iter)
{
GConfClient *client;
- gtk_tree_store_set (GTK_TREE_STORE (model), iter,
+ gtk_list_store_set (GTK_LIST_STORE (model), iter,
DETAIL_KEYENTRY_COLUMN, key, -1);
client = gconf_client_get_default ();
if (key->description != NULL)
@@ -1879,6 +1887,7 @@ setup_dialog (CcPanel *panel, GtkBuilder *builder)
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
g_signal_connect (selection, "changed",
G_CALLBACK (section_selection_changed), builder);
+ section_selection_changed (selection, builder);
/* Setup the shortcut treeview */
treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]