[balsa/gtk4: 83/314] balsa-message: Add action-entries in a helper




commit b7581d0fdd27cd5fc4ee0b95c6a90a11f138938a
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jun 24 17:35:31 2020 -0400

    balsa-message: Add action-entries in a helper

 src/balsa-message.c | 75 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 45 insertions(+), 30 deletions(-)
---
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 59df654c4..53f6cd535 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -842,7 +842,8 @@ show_part_change_state(GSimpleAction *action,
 }
 
 static void
-balsa_message_init(BalsaMessage * balsa_message)
+balsa_message_add_actions(BalsaMessage *balsa_message,
+                          const gchar  *action_namespace)
 {
     GSimpleActionGroup *simple;
     static const GActionEntry entries[] = {
@@ -853,22 +854,10 @@ balsa_message_init(BalsaMessage * balsa_message)
         {"show-part",               libbalsa_radio_activated, "s", "''",
                                     show_part_change_state},
     };
-    GtkStack  *stack;
-    GtkWidget *vbox;
-    GtkWidget *scroll;
-    GtkWidget *viewport;
-    GtkWidget **buttons;
-    GtkTreeStore *model;
-    GtkCellRenderer *renderer;
-    GtkTreeSelection *selection;
-    GtkEventController *key_controller;
-    GtkGesture *gesture;
-    GMenu *menu;
 
     simple = g_simple_action_group_new();
     g_action_map_add_action_entries(G_ACTION_MAP(simple),
-                                    entries,
-                                    G_N_ELEMENTS(entries),
+                                    entries, G_N_ELEMENTS(entries),
                                     balsa_message);
     balsa_message->toggle_all_inline_action =
         g_action_map_lookup_action(G_ACTION_MAP(simple), "toggle-all-inline");
@@ -876,9 +865,25 @@ balsa_message_init(BalsaMessage * balsa_message)
         g_action_map_lookup_action(G_ACTION_MAP(simple), "show-part");
 
     gtk_widget_insert_action_group(GTK_WIDGET(balsa_message),
-                                   "message-menu",
+                                   action_namespace,
                                    G_ACTION_GROUP(simple));
     g_object_unref(simple);
+}
+
+static void
+balsa_message_init(BalsaMessage * balsa_message)
+{
+    GtkStack  *stack;
+    GtkWidget *vbox;
+    GtkWidget *scroll;
+    GtkWidget *viewport;
+    GtkWidget **buttons;
+    GtkTreeStore *model;
+    GtkCellRenderer *renderer;
+    GtkTreeSelection *selection;
+    GtkEventController *key_controller;
+    GtkGesture *gesture;
+    GMenu *menu;
 
     balsa_message->switcher = gtk_stack_switcher_new();
     gtk_box_pack_start(GTK_BOX(balsa_message), balsa_message->switcher, FALSE, FALSE, 0);
@@ -1001,6 +1006,8 @@ balsa_message_init(BalsaMessage * balsa_message)
     gtk_box_pack_start(GTK_BOX(vbox), balsa_message->find_bar, FALSE, FALSE, 0);
 
     /* The context menu that is popped up when more than one part is selected */
+    balsa_message_add_actions(balsa_message, "message-menu");
+
     menu = g_menu_new();
     g_menu_append(menu, _("Save selected as…"), "save-selected");
     g_menu_append(menu, _("Save selected to folder…"), "save-selected-to-folder");
@@ -1829,6 +1836,28 @@ copy_part_change_state(GSimpleAction *action,
         gtk_popover_popdown((GtkPopover *) info->popup_widget);
 }
 
+static void
+part_add_actions(BalsaMessage *balsa_message,
+                 const gchar  *action_namespace,
+                 gpointer      user_data)
+{
+    GSimpleActionGroup *simple;
+    static const GActionEntry entries[] = {
+        {"save", save_activated},
+        {"open-with", libbalsa_radio_activated, "s", "''", open_with_change_state},
+        {"copy-part", libbalsa_radio_activated, "s", "''", copy_part_change_state}
+    };
+
+    simple = g_simple_action_group_new();
+    g_action_map_add_action_entries(G_ACTION_MAP(simple),
+                                    entries, G_N_ELEMENTS(entries),
+                                    user_data);
+    gtk_widget_insert_action_group(GTK_WIDGET(balsa_message),
+                                   action_namespace,
+                                   G_ACTION_GROUP(simple));
+    g_object_unref(simple);
+}
+
 static void
 part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
 /* Remarks: Will add items in the following order:
@@ -1840,26 +1869,12 @@ part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
 {
     static int menu_number;
     gchar *namespace;
-    GSimpleActionGroup *simple;
-    static const GActionEntry entries[] = {
-        {"save", save_activated},
-        {"open-with", libbalsa_radio_activated, "s", "''", open_with_change_state},
-        {"copy-part", libbalsa_radio_activated, "s", "''", copy_part_change_state}
-    };
     GMenu *menu;
     gchar *content_type;
 
     namespace = g_strdup_printf("menu-%d", ++menu_number);
 
-    simple = g_simple_action_group_new();
-    g_action_map_add_action_entries(G_ACTION_MAP(simple),
-                                    entries,
-                                    G_N_ELEMENTS(entries),
-                                    info);
-    gtk_widget_insert_action_group(GTK_WIDGET(balsa_message),
-                                   namespace,
-                                   G_ACTION_GROUP(simple));
-    g_object_unref(simple);
+    part_add_actions(balsa_message, namespace, info);
 
     menu = g_menu_new();
 


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