qulogic/libgnt

Fix rebinding of GntBindables.

2019-05-11, Elliott Sales de Andrade
b153641cfe45
Parents c170d9e55711
Children a69fa9089667
Fix rebinding of GntBindables.

`gnt_bindable_register_binding` takes a variadic set of arguments, but
when rebinding, we only have the condensed `GList`. Instead, use the
internal `register_binding` function that *does* take a `GList`.

Fortunately, no previous calls to `gnt_bindable_register_binding` were
ever passed parameters, so this would always copy an empty list anyway.
  • +31 -30
    gntbindable.c
  • --- a/gntbindable.c Sat May 11 01:00:16 2019 +0000
    +++ b/gntbindable.c Sat May 11 01:42:42 2019 -0400
    @@ -55,6 +55,35 @@
    /******************************************************************************
    * Helpers
    *****************************************************************************/
    +static void
    +register_binding(GntBindableClass *klass, const char *name, const char *trigger,
    + GList *list)
    +{
    + GntBindableActionParam *param;
    + GntBindableAction *action;
    +
    + if (name == NULL || *name == '\0') {
    + g_hash_table_remove(klass->bindings, (char *)trigger);
    + gnt_keys_del_combination(trigger);
    + return;
    + }
    +
    + action = g_hash_table_lookup(klass->actions, name);
    + if (!action) {
    + gnt_warning("Invalid action name %s for %s", name,
    + g_type_name(G_OBJECT_CLASS_TYPE(klass)));
    + if (list) {
    + g_list_free(list);
    + }
    + return;
    + }
    +
    + param = g_new0(GntBindableActionParam, 1);
    + param->action = action;
    + param->list = list;
    + g_hash_table_replace(klass->bindings, g_strdup(trigger), param);
    + gnt_keys_add_combination(trigger);
    +}
    static void
    gnt_bindable_free_rebind_info(void)
    @@ -75,11 +104,11 @@
    gnt_bindable_rebinding_rebind(G_GNUC_UNUSED GntWidget *button, gpointer data)
    {
    if (rebind_info.keys) {
    - gnt_bindable_register_binding(rebind_info.klass,
    + register_binding(rebind_info.klass,
    NULL,
    rebind_info.okeys,
    rebind_info.params);
    - gnt_bindable_register_binding(rebind_info.klass,
    + register_binding(rebind_info.klass,
    rebind_info.name,
    rebind_info.keys,
    rebind_info.params);
    @@ -352,34 +381,6 @@
    return (param && param->action);
    }
    -static void
    -register_binding(GntBindableClass *klass, const char *name, const char *trigger, GList *list)
    -{
    - GntBindableActionParam *param;
    - GntBindableAction *action;
    -
    - if (name == NULL || *name == '\0') {
    - g_hash_table_remove(klass->bindings, (char*)trigger);
    - gnt_keys_del_combination(trigger);
    - return;
    - }
    -
    - action = g_hash_table_lookup(klass->actions, name);
    - if (!action) {
    - gnt_warning("Invalid action name %s for %s",
    - name, g_type_name(G_OBJECT_CLASS_TYPE(klass)));
    - if (list)
    - g_list_free(list);
    - return;
    - }
    -
    - param = g_new0(GntBindableActionParam, 1);
    - param->action = action;
    - param->list = list;
    - g_hash_table_replace(klass->bindings, g_strdup(trigger), param);
    - gnt_keys_add_combination(trigger);
    -}
    -
    void gnt_bindable_register_binding(GntBindableClass *klass, const char *name,
    const char *trigger, ...)
    {