Skip to content
Snippets Groups Projects
Commit 3fa2d53f authored by Julien Bonjean's avatar Julien Bonjean
Browse files

[#2916] Added duplicate shortcut keys protection

parent badc0b72
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ GtkWidget* ...@@ -26,7 +26,7 @@ GtkWidget*
create_shortcuts_settings() create_shortcuts_settings()
{ {
GtkWidget *vbox, *result_frame, *window, *treeview, *scrolled_window, *label; GtkWidget *vbox, *result_frame, *window, *treeview, *scrolled_window, *label;
GtkListStore *store;
GtkTreeIter iter; GtkTreeIter iter;
guint i = 0; guint i = 0;
...@@ -40,7 +40,7 @@ create_shortcuts_settings() ...@@ -40,7 +40,7 @@ create_shortcuts_settings()
treeview = gtk_tree_view_new(); treeview = gtk_tree_view_new();
setup_tree_view(treeview); setup_tree_view(treeview);
store = gtk_list_store_new(COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_UINT); GtkListStore *store = gtk_list_store_new(COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_UINT);
Accelerator* list = shortcuts_get_list(); Accelerator* list = shortcuts_get_list();
...@@ -100,14 +100,29 @@ accel_edited(GtkCellRendererAccel *renderer, gchar *path, guint accel_key, ...@@ -100,14 +100,29 @@ accel_edited(GtkCellRendererAccel *renderer, gchar *path, guint accel_key,
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
// Update treeview Accelerator* list = shortcuts_get_list();
model = gtk_tree_view_get_model(treeview); model = gtk_tree_view_get_model(treeview);
gint code = XKeysymToKeycode(GDK_DISPLAY(), accel_key);
// Disable existing binding if key already used
int i = 0;
gtk_tree_model_get_iter_first(model, &iter);
while (list[i].action != NULL)
{
if(list[i].value == code)
{
gtk_list_store_set(GTK_LIST_STORE (model), &iter, MASK, 0, VALUE, 0, -1);
WARN("This key was already affected");
}
gtk_tree_model_iter_next(model, &iter);
i++;
}
// Update treeview
if (gtk_tree_model_get_iter_from_string(model, &iter, path)) if (gtk_tree_model_get_iter_from_string(model, &iter, path))
gtk_list_store_set(GTK_LIST_STORE (model), &iter, MASK, (gint) mask, VALUE, gtk_list_store_set(GTK_LIST_STORE (model), &iter, MASK, (gint) mask, VALUE,
accel_key, -1); accel_key, -1);
gint code = XKeysymToKeycode(GDK_DISPLAY(), accel_key);
// Update GDK bindings // Update GDK bindings
shortcuts_update_bindings(atoi(path), code); shortcuts_update_bindings(atoi(path), code);
} }
......
...@@ -225,6 +225,35 @@ initialize_accelerators_list () ...@@ -225,6 +225,35 @@ initialize_accelerators_list ()
accelerators_list[index].value = 0; accelerators_list[index].value = 0;
} }
static void
update_bindings_data(const guint index, const guint code)
{
// we need to be sure this code is not already affected
// to another action
int i = 0;
while (accelerators_list[i].action != NULL)
{
if(accelerators_list[i].value == code)
{
// disable old binding
accelerators_list[i].value = 0;
// update config table
g_hash_table_replace (shortcutsMap,
g_strdup (accelerators_list[i].action), GINT_TO_POINTER (0));
}
i++;
}
// store new value
accelerators_list[index].value = code;
// update value in hashtable (used for dbus calls)
g_hash_table_replace (shortcutsMap,
g_strdup (accelerators_list[index].action), GINT_TO_POINTER (
accelerators_list[index].value));
}
/* /*
* "Public" functions * "Public" functions
*/ */
...@@ -238,13 +267,8 @@ shortcuts_update_bindings (const guint index, const guint code) ...@@ -238,13 +267,8 @@ shortcuts_update_bindings (const guint index, const guint code)
// first remove all existing bindings // first remove all existing bindings
remove_bindings (); remove_bindings ();
// store new value // update data
accelerators_list[index].value = code; update_bindings_data(index, code);
// update value in hashtable (used for dbus calls)
g_hash_table_replace (shortcutsMap,
g_strdup (accelerators_list[index].action), GINT_TO_POINTER (
accelerators_list[index].value));
// recreate all bindings // recreate all bindings
create_bindings (); create_bindings ();
......
...@@ -59,6 +59,9 @@ initialize_shortcuts_keys(); ...@@ -59,6 +59,9 @@ initialize_shortcuts_keys();
static void* static void*
get_action_callback (const gchar* action); get_action_callback (const gchar* action);
static void
update_bindings_data (const guint index, const guint code);
/* /*
* "Public" functions * "Public" functions
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment