[file-roller/wip/jtojnar/gtk4] wip: Started removing GtkAccelGroup



commit ad599462c725a048f10d68ad0a5a11b32829c14a
Author: Jan Tojnar <jtojnar gmail com>
Date:   Mon Dec 13 17:19:26 2021 +0100

    wip: Started removing GtkAccelGroup

 src/fr-window.c | 19 -------------------
 src/gtk-utils.c | 46 ++++++++++++++++++++--------------------------
 src/gtk-utils.h |  1 -
 3 files changed, 20 insertions(+), 46 deletions(-)
---
diff --git a/src/fr-window.c b/src/fr-window.c
index 82df5b89..9878ba43 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -247,7 +247,6 @@ struct _FrWindowPrivate {
        GtkTreePath       *list_hover_path;
        GtkTreeViewColumn *filename_column;
        GtkWindowGroup    *window_group;
-       GtkAccelGroup     *accel_group;
        GHashTable        *named_dialogs;
 
        gboolean         filter_mode;
@@ -571,7 +570,6 @@ fr_window_free_private_data (FrWindow *window)
        _g_object_unref (window->priv->cancellable);
        g_hash_table_unref (window->priv->named_dialogs);
        g_object_unref (window->priv->window_group);
-       g_object_unref (window->priv->accel_group);
 }
 
 
@@ -911,12 +909,10 @@ fr_window_init (FrWindow *window)
        window->priv->cancellable = g_cancellable_new ();
        window->priv->compression = FR_COMPRESSION_NORMAL;
        window->priv->window_group = gtk_window_group_new ();
-       window->priv->accel_group = gtk_accel_group_new ();
        window->priv->populating_file_list = FALSE;
        window->priv->named_dialogs = g_hash_table_new (g_str_hash, g_str_equal);
 
        gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW (window));
-       gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accel_group);
 
        window->archive = NULL;
 }
@@ -5470,32 +5466,17 @@ fr_window_attach (FrWindow      *window,
 /* -- fr_window_add_accelerators -- */
 
 
-static GtkAccelGroup *
-gth_window_get_accel_group (FrWindow *window)
-{
-       if (window->priv->accel_group == NULL) {
-               window->priv->accel_group = gtk_accel_group_new ();
-               gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accel_group);
-       }
-
-       return window->priv->accel_group;
-}
-
-
 static void
 fr_window_add_accelerators (FrWindow                 *window,
                            const FrAccelerator      *accelerators,
                            int                       n_accelerators)
 {
-       GtkAccelGroup *accel_group;
        int            i;
 
-       accel_group = gth_window_get_accel_group (window);
        for (i = 0; i < n_accelerators; i++) {
                const FrAccelerator *acc = accelerators + i;
 
                _gtk_window_add_accelerator_for_action (GTK_WINDOW (window),
-                                                       accel_group,
                                                        acc->action_name,
                                                        acc->accelerator,
                                                        NULL);
diff --git a/src/gtk-utils.c b/src/gtk-utils.c
index 5805bbb8..82590d7a 100644
--- a/src/gtk-utils.c
+++ b/src/gtk-utils.c
@@ -738,8 +738,7 @@ accel_data_free (gpointer  user_data,
 
 
 static gboolean
-window_accelerator_activated_cb (GtkAccelGroup *accel_group,
-                                GObject                *object,
+window_accelerator_activated_cb (GObject               *object,
                                 guint           key,
                                 GdkModifierType         mod,
                                 gpointer                user_data)
@@ -759,7 +758,6 @@ window_accelerator_activated_cb (GtkAccelGroup      *accel_group,
 
 void
 _gtk_window_add_accelerator_for_action (GtkWindow      *window,
-                                       GtkAccelGroup   *accel_group,
                                        const char      *action_name,
                                        const char      *accel,
                                        GVariant        *target)
@@ -767,7 +765,6 @@ _gtk_window_add_accelerator_for_action (GtkWindow   *window,
        AccelData       *accel_data;
        guint            key;
        GdkModifierType  mods;
-       GClosure        *closure;
 
        if ((action_name == NULL) || (accel == NULL))
                return;
@@ -786,14 +783,6 @@ _gtk_window_add_accelerator_for_action (GtkWindow  *window,
                accel_data->target = g_variant_ref (target);
 
        gtk_accelerator_parse (accel, &key, &mods);
-       closure = g_cclosure_new (G_CALLBACK (window_accelerator_activated_cb),
-                                 accel_data,
-                                 accel_data_free);
-       gtk_accel_group_connect (accel_group,
-                                key,
-                                mods,
-                                0,
-                                closure);
 }
 
 
@@ -802,7 +791,6 @@ _gtk_window_add_accelerator_for_action (GtkWindow   *window,
 
 static void
 add_accelerators_from_menu_item (GtkWindow      *window,
-                                GtkAccelGroup  *accel_group,
                                 GMenuModel     *model,
                                 int             item)
 {
@@ -811,8 +799,10 @@ add_accelerators_from_menu_item (GtkWindow      *window,
        GVariant                *value;
        const char              *accel = NULL;
        const char              *action = NULL;
+       g_autofree gchar        *detailed_action = NULL;
        GVariant                *target = NULL;
 
+
        iter = g_menu_model_iterate_item_attributes (model, item);
        while (g_menu_attribute_iter_get_next (iter, &key, &value)) {
                if (g_str_equal (key, "action") && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
@@ -825,11 +815,20 @@ add_accelerators_from_menu_item (GtkWindow      *window,
        }
        g_object_unref (iter);
 
-       _gtk_window_add_accelerator_for_action (window,
-                                               accel_group,
-                                               action,
-                                               accel,
-                                               target);
+       if (action == NULL) {
+               return;
+       }
+
+       printf("accel %s: %s: %p\n", action, accel, target);
+       if (target == NULL) {
+               detailed_action = g_strdup(action);
+       } else {
+               g_autofree gchar *target_string = g_variant_print (target, TRUE);
+               detailed_action = g_strconcat (action, "(", target_string, ")", NULL);
+       }
+
+       _gtk_application_add_accelerator_for_action (GTK_APPLICATION (g_application_get_default ()), 
detailed_action, accel);
+       // gtk_application_set_accels_for_action(detailed_action, accel);
 
        if (target != NULL)
                g_variant_unref (target);
@@ -838,7 +837,6 @@ add_accelerators_from_menu_item (GtkWindow      *window,
 
 static void
 add_accelerators_from_menu (GtkWindow      *window,
-                           GtkAccelGroup  *accel_group,
                            GMenuModel     *model)
 {
        int              i;
@@ -847,11 +845,11 @@ add_accelerators_from_menu (GtkWindow      *window,
        GMenuModel      *m;
 
        for (i = 0; i < g_menu_model_get_n_items (model); i++) {
-               add_accelerators_from_menu_item (window, accel_group, model, i);
+               add_accelerators_from_menu_item (window, model, i);
 
                iter = g_menu_model_iterate_item_links (model, i);
                while (g_menu_link_iter_get_next (iter, &key, &m)) {
-                       add_accelerators_from_menu (window, accel_group, m);
+                       add_accelerators_from_menu (window, m);
                        g_object_unref (m);
                }
                g_object_unref (iter);
@@ -863,11 +861,7 @@ void
 _gtk_window_add_accelerators_from_menu (GtkWindow  *window,
                                        GMenuModel *menu)
 {
-       GtkAccelGroup *accel_group;
-
-       accel_group = gtk_accel_group_new ();
-       add_accelerators_from_menu (window, accel_group, menu);
-       gtk_window_add_accel_group (window, accel_group);
+       add_accelerators_from_menu (window, menu);
 }
 
 
diff --git a/src/gtk-utils.h b/src/gtk-utils.h
index d7dbc54d..3c408163 100644
--- a/src/gtk-utils.h
+++ b/src/gtk-utils.h
@@ -107,7 +107,6 @@ GtkWidget *   _gtk_header_bar_create_image_toggle_button
                                                    const char       *action_name);
 void          _gtk_window_add_accelerator_for_action
                                                   (GtkWindow        *window,
-                                                   GtkAccelGroup    *accel_group,
                                                    const char       *action_name,
                                                    const char       *accel,
                                                    GVariant         *target);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]