[balsa/gtk4: 33/193] compose-window: Use correct action-group




commit 97a8b7190b2205ae6fe27165d2678048653a0c3c
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Jun 6 12:40:13 2020 -0400

    compose-window: Use correct action-group
    
    Use a separate action-group for each attachment; the actions are the
    same, but the user-data is different.
    
    * src/sendmsg-window.c (remove_attachment), (add_attachment):

 ChangeLog            |  4 ++++
 src/sendmsg-window.c | 35 +++++++++++++++++++----------------
 2 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9de8a5df8..f8752d194 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -242,6 +242,10 @@
 
        * src/balsa-mblist.c (bmbl_select_mailbox), (bmbl_mru_selected_cb):
 
+       compose-window: Use a separate action-group for each attachment
+
+       * src/sendmsg-window.c (remove_attachment), (add_attachment):
+
 2020-06-06  Peter Bloomfield  <pbloomfield bellsouth net>
 
        compose window: Connect to the "pressed" signal of a
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 645d19bea..2852464f9 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1290,15 +1290,13 @@ remove_attachment(GSimpleAction *action,
 
     /* make sure we got the right element */
     gtk_tree_model_get(model, &iter, ATTACH_INFO_COLUMN, &test_info, -1);
-    if (test_info != info) {
-       if (test_info)
-           g_object_unref(test_info);
-       return;
+
+    if (test_info == info) {
+        /* remove the attachment */
+        gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
     }
-    g_object_unref(test_info);
 
-    /* remove the attachment */
-    gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
+    g_object_unref(test_info);
 }
 
 /* change attachment mode - right mouse button callback */
@@ -1653,6 +1651,8 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
     };
     GMenu *menu;
     GMenu *section;
+    static int attachment_number = 0;
+    gchar *attachment_namespace;
 
     g_debug("Trying to attach '%s'", filename);
     if (!(file_uri = libbalsa_vfs_new_from_uri(filename))) {
@@ -1748,8 +1748,9 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
                                     G_N_ELEMENTS(attachment_entries),
                                     attach_data);
 
+    attachment_namespace = g_strdup_printf("attachment-%d", ++attachment_number);
     gtk_widget_insert_action_group(bsmsg->window,
-                                   "attachment",
+                                   attachment_namespace,
                                    G_ACTION_GROUP(simple));
     g_object_unref(simple);
 
@@ -1759,7 +1760,7 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
     if (can_inline) {
         GMenuItem *menu_item =
             g_menu_item_new(_(attach_modes[LIBBALSA_ATTACH_AS_INLINE]), NULL);
-        g_menu_item_set_action_and_target(menu_item, "attachment.new-mode", "i",
+        g_menu_item_set_action_and_target(menu_item, "new-mode", "i",
                                           LIBBALSA_ATTACH_AS_INLINE);
         g_menu_append_item(menu, menu_item);
         g_object_unref(menu_item);
@@ -1769,7 +1770,7 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
     if (can_inline || !is_a_temp_file) {
         GMenuItem *menu_item =
             g_menu_item_new(_(attach_modes[LIBBALSA_ATTACH_AS_ATTACHMENT]), NULL);
-        g_menu_item_set_action_and_target(menu_item, "attachment.new-mode", "i",
+        g_menu_item_set_action_and_target(menu_item, "new-mode", "i",
                                           LIBBALSA_ATTACH_AS_ATTACHMENT);
         g_menu_append_item(menu, menu_item);
         g_object_unref(menu_item);
@@ -1779,7 +1780,7 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
     if (!is_a_temp_file) {
         GMenuItem *menu_item =
             g_menu_item_new(_(attach_modes[LIBBALSA_ATTACH_AS_EXTBODY]), NULL);
-        g_menu_item_set_action_and_target(menu_item, "attachment.new-mode", "i",
+        g_menu_item_set_action_and_target(menu_item, "new-mode", "i",
                                           LIBBALSA_ATTACH_AS_EXTBODY);
         g_menu_append_item(menu, menu_item);
         g_object_unref(menu_item);
@@ -1787,7 +1788,7 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
 
     /* an attachment can be removed */
     section = g_menu_new();
-    g_menu_append(section, _("Remove"), "attachment.remove");
+    g_menu_append(section, _("Remove"), "remove");
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
 
@@ -1795,15 +1796,17 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
        attached... (only for non-message attachments) */
     if (!is_fwd_message) {
         section = g_menu_new();
-        libbalsa_vfs_fill_menu_by_content_type(section, content_type,
-                                               "attachment.launch-app");
+        libbalsa_vfs_fill_menu_by_content_type(section, content_type, "launch-app");
         g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
         g_object_unref(section);
     }
 
-    attach_data->popup_menu =
-        gtk_popover_new_from_model(bsmsg->tree_view, G_MENU_MODEL(menu));
+    attach_data->popup_menu = gtk_popover_new(bsmsg->tree_view);
+    gtk_popover_bind_model(GTK_POPOVER(attach_data->popup_menu),
+                           G_MENU_MODEL(menu),
+                           attachment_namespace);
     g_object_unref(menu);
+    g_free(attachment_namespace);
 
     /* append to the list store */
     content_desc =libbalsa_vfs_content_description(content_type);


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