[balsa/gtk4: 52/312] Various: Make GtkMenu versions work




commit 9203cd9eb05c631a10434352b83f11f846f42168
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jun 15 11:51:16 2020 -0400

    Various: Make GtkMenu versions work
    
    Each menu needs to be attached to a widget, which both handles destruction
    and gives access to the necessary action group.
    
    Fixes the issue noted in b752ed667697a38f1b4edf5650c7132fd2e5d25e
    
    * src/balsa-index.c (bndx_popup_menu_create):
    * src/balsa-message.c (balsa_message_init), (display_content), (part_create_menu):
    * src/balsa-mime-widget-text.c (bmwt_html_popup_context_menu):
    * src/mailbox-node.c (create_context_menu):
    * src/sendmsg-window.c (add_attachment), (add_urlref_attachment):
    * src/toolbar-factory.c (tm_popup_context_menu_cb):

 ChangeLog                    | 15 +++++++++++++++
 src/balsa-index.c            |  1 +
 src/balsa-message.c          | 11 +++++++----
 src/balsa-mime-widget-text.c |  3 +++
 src/mailbox-node.c           |  6 ++++--
 src/sendmsg-window.c         |  3 ++-
 src/toolbar-factory.c        |  1 +
 7 files changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e583df52c..dac4b52bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -337,6 +337,21 @@
 
        * src/main.c (balsa_startup_cb):
 
+2020-06-15  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Various: Make GtkMenu versions work.
+
+       Each menu needs to be attached to a widget, which both handles
+       destruction and gives access to the necessary action group.
+
+       * src/balsa-index.c (bndx_popup_menu_create):
+       * src/balsa-message.c (balsa_message_init), (display_content),
+       (part_create_menu):
+       * src/balsa-mime-widget-text.c (bmwt_html_popup_context_menu):
+       * src/mailbox-node.c (create_context_menu):
+       * src/sendmsg-window.c (add_attachment), (add_urlref_attachment):
+       * src/toolbar-factory.c (tm_popup_context_menu_cb):
+
 2020-06-15  Peter Bloomfield  <pbloomfield bellsouth net>
 
        pref-manager: Use GtkMenuButton to pop-up "Add" menus
diff --git a/src/balsa-index.c b/src/balsa-index.c
index ba91c6341..425b43c1b 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2140,6 +2140,7 @@ bndx_popup_menu_create(BalsaIndex * bindex)
         gtk_popover_set_position(GTK_POPOVER(bindex->popup_widget), GTK_POS_BOTTOM);
     } else {
         bindex->popup_widget = gtk_menu_new_from_model(G_MENU_MODEL(menu));
+        gtk_menu_attach_to_widget(GTK_MENU(bindex->popup_widget), GTK_WIDGET(bindex), NULL);
     }
 }
 
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 045c0edf3..6bc5e6bb6 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -1006,6 +1006,9 @@ balsa_message_init(BalsaMessage * balsa_message)
             gtk_popover_new_from_model(balsa_message->treeview, G_MENU_MODEL(menu));
     } else {
         balsa_message->save_all_popup = gtk_menu_new_from_model(G_MENU_MODEL(menu));
+        gtk_menu_attach_to_widget(GTK_MENU(balsa_message->save_all_popup),
+                                  balsa_message->treeview,
+                                  NULL);
     }
     g_object_unref(menu);
 
@@ -1790,12 +1793,11 @@ display_content(BalsaMessage * balsa_message)
             gtk_popover_new_from_model(balsa_message->attach_button,
                                        G_MENU_MODEL(balsa_message->parts_menu));
     } else {
-        if (balsa_message->parts_popup)
-            g_object_unref(balsa_message->parts_popup);
-
         balsa_message->parts_popup =
             gtk_menu_new_from_model(G_MENU_MODEL(balsa_message->parts_menu));
-        g_object_ref_sink(balsa_message->parts_popup);
+        gtk_menu_attach_to_widget(GTK_MENU(balsa_message->parts_popup),
+                                  balsa_message->attach_button,
+                                  NULL);
     }
 
     /* Populate the parts-menu */
@@ -1948,6 +1950,7 @@ part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
             gtk_popover_new_from_model(balsa_message->treeview, G_MENU_MODEL(menu));
     } else {
         info->popup_menu = gtk_menu_new_from_model(G_MENU_MODEL(menu));
+        gtk_menu_attach_to_widget(GTK_MENU(info->popup_menu), balsa_message->treeview, NULL);
     }
 
     g_object_unref(menu);
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index bcef3bdbd..72ede7de6 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1348,6 +1348,9 @@ bmwt_html_popup_context_menu(GtkWidget    *html,
                                                     G_MENU_MODEL(menu));
         } else {
             popup_menu = gtk_menu_new_from_model(G_MENU_MODEL(menu));
+            gtk_menu_attach_to_widget(GTK_MENU(popup_menu),
+                                      libbalsa_html_get_view_widget(html),
+                                      NULL);
         }
 
         g_object_set_data(G_OBJECT(html), "popup-menu", popup_menu);
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index 9500f93c4..164f9a35a 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -1184,10 +1184,12 @@ create_context_menu(BalsaMailboxNode *mbnode,
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
 
-    if (libbalsa_use_popover())
+    if (libbalsa_use_popover()) {
         context_menu = gtk_popover_new_from_model(relative_to, G_MENU_MODEL(menu));
-    else
+    } else {
         context_menu = gtk_menu_new_from_model(G_MENU_MODEL(menu));
+        gtk_menu_attach_to_widget(GTK_MENU(context_menu), relative_to, NULL);
+    }
     g_object_unref(menu);
 
     return context_menu;
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 0cdb1df29..9450da440 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1815,6 +1815,7 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
                                   G_MENU_MODEL(menu),
                                   attachment_namespace,
                                   TRUE);
+        gtk_menu_attach_to_widget(GTK_MENU(attach_data->popup_menu), bsmsg->tree_view, NULL);
     }
 
     g_object_unref(menu);
@@ -1906,7 +1907,7 @@ add_urlref_attachment(BalsaSendmsg * bsmsg, const gchar *url)
             gtk_popover_new_from_model(bsmsg->window, G_MENU_MODEL(menu));
     } else {
         attach_data->popup_menu = gtk_menu_new_from_model(G_MENU_MODEL(menu));
-        gtk_widget_show_all(attach_data->popup_menu);
+        gtk_menu_attach_to_widget(GTK_MENU(attach_data->popup_menu), bsmsg->window, NULL);
     }
     g_object_unref(menu);
 
diff --git a/src/toolbar-factory.c b/src/toolbar-factory.c
index 18469c9a7..1c21012bf 100644
--- a/src/toolbar-factory.c
+++ b/src/toolbar-factory.c
@@ -764,6 +764,7 @@ tm_popup_context_menu_cb(GtkWidget    * toolbar,
     } else {
         popup_menu = gtk_menu_new();
         gtk_menu_shell_bind_model(GTK_MENU_SHELL(popup_menu), G_MENU_MODEL(menu), namespace, TRUE);
+        gtk_menu_attach_to_widget(GTK_MENU(popup_menu), toolbar, NULL);
     }
 
     g_object_unref(menu);


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