[balsa/gtk4: 37/246] Various: Implement libbalsa_popup_widget_new()




commit afdf29774ac027aa4a71d2fc4a8b8b18b5657cc4
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jun 15 16:22:41 2020 -0400

    Various: Implement libbalsa_popup_widget_new()
    
    Implement libbalsa_popup_widget_new() as a wrapper for creating either
    a GtkPopover or a GtkMenu, and use it.
    
    * libbalsa/libbalsa.c (libbalsa_use_popover), (libbalsa_popup_widget_new):
    * libbalsa/libbalsa.h:
    * src/balsa-index.c (bndx_popup_menu_create), (bndx_do_popup):
    * src/balsa-message.c (balsa_message_init), (tree_mult_selection_popup),
      (tree_button_press_cb), (part_info_init), (add_to_attachments_popup),
      (add_toggle_inline_menu_item), (display_content),
      (open_with_change_state), (copy_part_change_state), (part_create_menu),
      (balsa_part_info_init):
    * src/balsa-mime-widget-text.c (bmwt_html_populate_popup_menu), (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                    |  21 +++++++++
 libbalsa/libbalsa.c          |  30 +++++++++++++
 libbalsa/libbalsa.h          |   3 ++
 src/balsa-index.c            |  38 ++++++++--------
 src/balsa-message.c          | 100 +++++++++++++++----------------------------
 src/balsa-mime-widget-text.c |  52 +++++++++++-----------
 src/mailbox-node.c           |  44 ++++++++-----------
 src/sendmsg-window.c         |  41 +++++++-----------
 src/toolbar-factory.c        |  12 +-----
 9 files changed, 166 insertions(+), 175 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5513a1d19..5cba4ff01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -236,6 +236,27 @@
 
        * src/main.c (balsa_startup_cb):
 
+2020-06-15  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Various: Implement libbalsa_popup_widget_new() as a wrapper for
+       creating either a GtkPopover or a GtkMenu, and use it.
+
+       * libbalsa/libbalsa.c (libbalsa_use_popover),
+       (libbalsa_popup_widget_new):
+       * libbalsa/libbalsa.h:
+       * src/balsa-index.c (bndx_popup_menu_create), (bndx_do_popup):
+       * src/balsa-message.c (balsa_message_init),
+       (tree_mult_selection_popup), (tree_button_press_cb),
+       (part_info_init), (add_to_attachments_popup),
+       (add_toggle_inline_menu_item), (display_content),
+       (open_with_change_state), (copy_part_change_state),
+       (part_create_menu), (balsa_part_info_init):
+       * src/balsa-mime-widget-text.c (bmwt_html_populate_popup_menu),
+       (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>
 
        Various: Make GtkMenu versions work.
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index 05e216ff2..6c25a266e 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -746,6 +746,13 @@ libbalsa_dialog_flags(void)
        return libbalsa_use_headerbar() ? GTK_DIALOG_USE_HEADER_BAR : (GtkDialogFlags) 0;
 }
 
+/*
+ * Helpers for using GtkPopover or GtkMenu for context menus
+ */
+
+/*
+ * Look for the BALSA_USE_POPOVER environment variable
+ */
 gboolean
 libbalsa_use_popover(void)
 {
@@ -763,3 +770,26 @@ libbalsa_use_popover(void)
        }
        return use_popover;
 }
+
+/*
+ * Construct either a GtkPopover or a GtkMenu, according to the
+ * environment variable
+ */
+GtkWidget *
+libbalsa_popup_widget_new(GtkWidget   *relative_to,
+                          GMenuModel  *model,
+                          const gchar *action_namespace)
+{
+    GtkWidget *popup_widget;
+
+    if (libbalsa_use_popover()) {
+        popup_widget = gtk_popover_new(relative_to);
+        gtk_popover_bind_model(GTK_POPOVER(popup_widget), model, action_namespace);
+    } else {
+        popup_widget = gtk_menu_new();
+        gtk_menu_attach_to_widget(GTK_MENU(popup_widget), relative_to, NULL);
+        gtk_menu_shell_bind_model(GTK_MENU_SHELL(popup_widget), model, action_namespace, TRUE);
+    }
+
+    return popup_widget;
+}
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index 76bdf2ed1..992cb7027 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -187,6 +187,9 @@ gboolean libbalsa_use_headerbar(void);
 GtkDialogFlags libbalsa_dialog_flags(void);
 
 gboolean libbalsa_use_popover(void);
+GtkWidget *libbalsa_popup_widget_new(GtkWidget   *relative_to,
+                                     GMenuModel  *model,
+                                     const gchar *action_namespace);
 
 #if HAVE_GTKSOURCEVIEW
 GtkWidget *libbalsa_source_view_new(gboolean highlight_phrases);
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 425b43c1b..b76a773f1 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2094,13 +2094,13 @@ bndx_popup_menu_create(BalsaIndex * bindex)
     /* this is an invariable part of the context message menu. */
     section = g_menu_new();
 
-    g_menu_append(section, _("_Reply…"),            "popup.reply");
-    g_menu_append(section, _("Reply To _All…"),     "popup.reply-to-all");
-    g_menu_append(section, _("Reply To _Group…"),   "popup.reply-to-group");
-    g_menu_append(section, _("_Forward Attached…"), "popup.forward-attached");
-    g_menu_append(section, _("Forward _Inline…"),   "popup.forward-inline");
-    g_menu_append(section, _("_Pipe through…"),     "popup.pipe");
-    g_menu_append(section, _("_Store Address…"),    "popup.store-address");
+    g_menu_append(section, _("_Reply…"),            "reply");
+    g_menu_append(section, _("Reply To _All…"),     "reply-to-all");
+    g_menu_append(section, _("Reply To _Group…"),   "reply-to-group");
+    g_menu_append(section, _("_Forward Attached…"), "forward-attached");
+    g_menu_append(section, _("Forward _Inline…"),   "forward-inline");
+    g_menu_append(section, _("_Pipe through…"),     "pipe");
+    g_menu_append(section, _("_Store Address…"),    "store-address");
 
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
@@ -2108,9 +2108,9 @@ bndx_popup_menu_create(BalsaIndex * bindex)
     /* items that are insensitive for a read-only mailbox */
     section = g_menu_new();
 
-    g_menu_append(section, _("_Delete"),        "popup.delete");
-    g_menu_append(section, _("_Undelete"),      "popup.undelete");
-    g_menu_append(section, _("Move To _Trash"), "popup.trash");
+    g_menu_append(section, _("_Delete"),        "delete");
+    g_menu_append(section, _("_Undelete"),      "undelete");
+    g_menu_append(section, _("Move To _Trash"), "trash");
 
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
@@ -2118,8 +2118,8 @@ bndx_popup_menu_create(BalsaIndex * bindex)
     /* Toggle items */
     submenu = g_menu_new();
 
-    g_menu_append(submenu, _("_Flagged"), "popup.toggle-flagged");
-    g_menu_append(submenu, _("_Unread"),  "popup.toggle-unread");
+    g_menu_append(submenu, _("_Flagged"), "toggle-flagged");
+    g_menu_append(submenu, _("_Unread"),  "toggle-unread");
 
     g_menu_append_submenu(menu, _("T_oggle"), G_MENU_MODEL(submenu));
     g_object_unref(submenu);
@@ -2130,18 +2130,15 @@ bndx_popup_menu_create(BalsaIndex * bindex)
 
     /* View source */
     section = g_menu_new();
-    g_menu_append(section, _("_View Source"), "popup.view-source");
+    g_menu_append(section, _("_View Source"), "view-source");
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
 
     bindex->popup_menu = menu;
-    if (libbalsa_use_popover()) {
-        bindex->popup_widget = gtk_popover_new_from_model(GTK_WIDGET(bindex), G_MENU_MODEL(menu));
+    bindex->popup_widget =
+        libbalsa_popup_widget_new(GTK_WIDGET(bindex), G_MENU_MODEL(menu), "popup");
+    if (libbalsa_use_popover())
         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);
-    }
 }
 
 /* bndx_do_popup: common code for the popup menu;
@@ -2218,8 +2215,7 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent *event)
     item = g_menu_item_new_from_model(G_MENU_MODEL(index->popup_menu),
                                       index->move_position);
 
-    mru_menu =
-        balsa_mblist_mru_menu(&balsa_app.folder_mru, "popup.move-to");
+    mru_menu = balsa_mblist_mru_menu(&balsa_app.folder_mru, "move-to");
     g_menu_item_set_submenu(item, G_MENU_MODEL(mru_menu));
     g_object_unref(mru_menu);
 
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 1b8b505f0..f967fc76f 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -89,7 +89,7 @@ struct _BalsaPartInfo {
     BalsaMimeWidget *mime_widget;
 
     /* The contect menu; referenced */
-    GtkWidget *popup_menu;
+    GtkWidget *popup_widget;
 
     /* the path in the tree view */
     GtkTreePath *path;
@@ -997,19 +997,10 @@ balsa_message_init(BalsaMessage * balsa_message)
 
     /* The context menu that is popped up when more than one part is selected */
     menu = g_menu_new();
-    g_menu_append(menu, _("Save selected as…"),
-                  "message-menu.save-selected");
-    g_menu_append(menu, _("Save selected to folder…"),
-                  "message-menu.save-selected-to-folder");
-    if (libbalsa_use_popover()) {
-        balsa_message->save_all_popup =
-            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_menu_append(menu, _("Save selected as…"), "save-selected");
+    g_menu_append(menu, _("Save selected to folder…"), "save-selected-to-folder");
+    balsa_message->save_all_popup =
+        libbalsa_popup_widget_new(balsa_message->treeview, G_MENU_MODEL(menu), "message-menu");
     g_object_unref(menu);
 
     gtk_widget_show_all(GTK_WIDGET(balsa_message));
@@ -1134,7 +1125,7 @@ tree_mult_selection_popup(BalsaMessage     *balsa_message,
                           GtkTreeSelection *selection)
 {
     gint selected;
-    GtkWidget *popup_menu = NULL;
+    GtkWidget *popup_widget = NULL;
 
     /* destroy left-over select list and popup... */
     g_list_free(balsa_message->save_all_list);
@@ -1151,14 +1142,14 @@ tree_mult_selection_popup(BalsaMessage     *balsa_message,
     if (selected == 1) {
         BalsaPartInfo *info = BALSA_PART_INFO(balsa_message->save_all_list->data);
 
-        popup_menu = info->popup_menu;
+        popup_widget = info->popup_widget;
         g_list_free(balsa_message->save_all_list);
         balsa_message->save_all_list = NULL;
     } else if (selected > 1) {
-        popup_menu = balsa_message->save_all_popup;
+        popup_widget = balsa_message->save_all_popup;
     }
 
-    if (popup_menu == NULL)
+    if (popup_widget == NULL)
         return;
 
     if (libbalsa_use_popover()) {
@@ -1174,10 +1165,10 @@ tree_mult_selection_popup(BalsaMessage     *balsa_message,
             rectangle.width = 0;
             rectangle.y = (int) y;
             rectangle.height = 0;
-            gtk_popover_set_pointing_to(GTK_POPOVER(popup_menu), &rectangle);
+            gtk_popover_set_pointing_to(GTK_POPOVER(popup_widget), &rectangle);
         }
 
-        gtk_popover_popup(GTK_POPOVER(popup_menu));
+        gtk_popover_popup(GTK_POPOVER(popup_widget));
     } else {
         if (event != NULL) {
             gtk_menu_popup_at_pointer(GTK_MENU(balsa_message->save_all_popup), event);
@@ -1250,7 +1241,7 @@ tree_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
             if (gtk_tree_model_get_iter (model, &iter, path)) {
                 gtk_tree_model_get(model, &iter, PART_INFO_COLUMN, &info, -1);
                 if (info != NULL) {
-                    if (info->popup_menu != NULL) {
+                    if (info->popup_widget != NULL) {
                         if (libbalsa_use_popover()) {
                             GdkRectangle rectangle;
 
@@ -1259,12 +1250,12 @@ tree_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
                             rectangle.width = 0;
                             rectangle.y = (int) y;
                             rectangle.height = 0;
-                            gtk_popover_set_pointing_to(GTK_POPOVER(info->popup_menu),
+                            gtk_popover_set_pointing_to(GTK_POPOVER(info->popup_widget),
                                                         &rectangle);
 
-                            gtk_popover_popup(GTK_POPOVER(info->popup_menu));
+                            gtk_popover_popup(GTK_POPOVER(info->popup_widget));
                         } else {
-                            gtk_menu_popup_at_pointer(GTK_MENU(info->popup_menu), event);
+                            gtk_menu_popup_at_pointer(GTK_MENU(info->popup_widget), event);
                         }
                     }
                     g_object_unref(info);
@@ -1535,7 +1526,7 @@ static void
 part_info_init(BalsaMessage * balsa_message, BalsaPartInfo * info)
 {
     info->mime_widget =
-        g_object_ref_sink(balsa_mime_widget_new(balsa_message, info->body, info->popup_menu));
+        g_object_ref_sink(balsa_mime_widget_new(balsa_message, info->body, info->popup_widget));
 }
 
 
@@ -1567,7 +1558,7 @@ add_to_attachments_popup(GMenu *menu, const gchar *label,
     item = g_menu_item_new(label, NULL);
 
     path = gtk_tree_path_to_string(info->path);
-    g_menu_item_set_action_and_target(item, "message-menu.show-part", "s", path);
+    g_menu_item_set_action_and_target(item, "show-part", "s", path);
     g_free(path);
 
     g_menu_append_item(menu, item);
@@ -1577,7 +1568,7 @@ add_to_attachments_popup(GMenu *menu, const gchar *label,
 static void
 add_toggle_inline_menu_item(GMenu *menu, BalsaMessage *balsa_message)
 {
-    g_menu_append(menu, _("force inline for all parts"), "message-menu.toggle-all-inline");
+    g_menu_append(menu, _("force inline for all parts"), "toggle-all-inline");
 
     /* Clear force-inline to be consistent with initial FALSE state of
      * check-menu-item. */
@@ -1788,18 +1779,12 @@ display_content(BalsaMessage * balsa_message)
         /* Detach any existing popup: */
         if (balsa_message->parts_popup != NULL)
             gtk_popover_set_relative_to(GTK_POPOVER(balsa_message->parts_popup), NULL);
-
-        balsa_message->parts_popup =
-            gtk_popover_new_from_model(balsa_message->attach_button,
-                                       G_MENU_MODEL(balsa_message->parts_menu));
-    } else {
-        balsa_message->parts_popup =
-            gtk_menu_new_from_model(G_MENU_MODEL(balsa_message->parts_menu));
-        gtk_menu_attach_to_widget(GTK_MENU(balsa_message->parts_popup),
-                                  balsa_message->attach_button,
-                                  NULL);
     }
 
+    balsa_message->parts_popup = libbalsa_popup_widget_new(balsa_message->attach_button,
+                                                           G_MENU_MODEL(balsa_message->parts_menu),
+                                                           "message-menu");
+
     /* Populate the parts-menu */
     display_parts(balsa_message, libbalsa_message_get_body_list(balsa_message->message), NULL, NULL);
     g_clear_object(&balsa_message->parts_menu);
@@ -1865,7 +1850,7 @@ open_with_change_state(GSimpleAction *action,
 
     g_simple_action_set_state(action, parameter);
     if (libbalsa_use_popover())
-        gtk_popover_popdown(GTK_POPOVER(info->popup_menu));
+        gtk_popover_popdown(GTK_POPOVER(info->popup_widget));
 }
 
 static void
@@ -1876,7 +1861,7 @@ copy_part_change_state(GSimpleAction *action,
     BalsaPartInfo *info = user_data;
     const gchar *url;
 
-    url = balsa_mblist_mru_get_url_from_variant(parameter, info->popup_menu);
+    url = balsa_mblist_mru_get_url_from_variant(parameter, info->popup_widget);
 
     if (url[0] != '\0') {
         balsa_mblist_mru_add(&balsa_app.folder_mru, url);
@@ -1885,7 +1870,7 @@ copy_part_change_state(GSimpleAction *action,
 
     g_simple_action_set_state(action, parameter);
     if (libbalsa_use_popover())
-        gtk_popover_popdown(GTK_POPOVER(info->popup_menu));
+        gtk_popover_popdown(GTK_POPOVER(info->popup_widget));
 }
 
 static void
@@ -1898,7 +1883,7 @@ part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
                included on shortlist, sometimes not) excluded. */
 {
     static int menu_number;
-    gchar *prefix;
+    gchar *namespace;
     GSimpleActionGroup *simple;
     static const GActionEntry entries[] = {
         {"save", save_activated},
@@ -1906,10 +1891,9 @@ part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
         {"copy-part", libbalsa_radio_activated, "s", "''", copy_part_change_state}
     };
     GMenu *menu;
-    gchar *action;
     gchar *content_type;
 
-    prefix = g_strdup_printf("menu-%d", ++menu_number);
+    namespace = g_strdup_printf("menu-%d", ++menu_number);
 
     simple = g_simple_action_group_new();
     g_action_map_add_action_entries(G_ACTION_MAP(simple),
@@ -1917,43 +1901,29 @@ part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
                                     G_N_ELEMENTS(entries),
                                     info);
     gtk_widget_insert_action_group(GTK_WIDGET(balsa_message),
-                                   prefix,
+                                   namespace,
                                    G_ACTION_GROUP(simple));
     g_object_unref(simple);
 
     menu = g_menu_new();
 
     content_type = libbalsa_message_body_get_mime_type (info->body);
-    action = g_strconcat(prefix, ".open-with", NULL);
-    libbalsa_vfs_fill_menu_by_content_type(menu, content_type, action);
-    g_free(action);
+    libbalsa_vfs_fill_menu_by_content_type(menu, content_type, "open-with");
 
-    action = g_strconcat(prefix, ".save", NULL);
-    g_menu_append(menu, _("Save…"), action);
-    g_free(action);
+    g_menu_append(menu, _("Save…"), "save");
 
     if (strcmp(content_type, "message/rfc822") == 0) {
         GMenu *submenu;
 
-        action = g_strconcat(prefix, ".copy-part", NULL);
-        submenu = balsa_mblist_mru_menu(&balsa_app.folder_mru, action);
-        g_free(action);
-
+        submenu = balsa_mblist_mru_menu(&balsa_app.folder_mru, "copy-part");
         g_menu_append_submenu(menu, _("_Copy to folder…"), G_MENU_MODEL(submenu));
     }
-
     g_free(content_type);
-    g_free(prefix);
-
-    if (libbalsa_use_popover()) {
-        info->popup_menu =
-            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);
-    }
 
+    info->popup_widget =
+        libbalsa_popup_widget_new(balsa_message->treeview, G_MENU_MODEL(menu), namespace);
     g_object_unref(menu);
+    g_free(namespace);
 }
 
 static void
@@ -1961,7 +1931,7 @@ balsa_part_info_init(BalsaPartInfo *info)
 {
     info->body = NULL;
     info->mime_widget = NULL;
-    info->popup_menu = NULL;
+    info->popup_widget = NULL;
     info->path = NULL;
 }
 
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index b04eebd31..8d492eb91 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1207,7 +1207,8 @@ bmwt_html_print_activated(GSimpleAction *action,
 static void
 bmwt_html_populate_popup_menu(BalsaMessage * bm,
                               GtkWidget    * html,
-                              GMenu        * menu)
+                              GMenu        * menu,
+                              const gchar  * namespace)
 {
     GSimpleActionGroup *simple;
     static const GActionEntry text_view_popup_entries[] = {
@@ -1230,7 +1231,7 @@ bmwt_html_populate_popup_menu(BalsaMessage * bm,
                                     G_N_ELEMENTS(text_view_popup_entries),
                                     html);
     gtk_widget_insert_action_group(GTK_WIDGET(html),
-                                   "text-view-popup",
+                                   namespace,
                                    G_ACTION_GROUP(simple));
 
     print_action = g_action_map_lookup_action(G_ACTION_MAP(simple), "print");
@@ -1238,16 +1239,16 @@ bmwt_html_populate_popup_menu(BalsaMessage * bm,
 
     section = g_menu_new();
 
-    g_menu_append(section, _("Zoom In"), "text-view-popup.zoom-in");
-    g_menu_append(section, _("Zoom Out"), "text-view-popup.zoom-out");
-    g_menu_append(section, _("Zoom 100%"), "text-view-popup.zoom-reset");
+    g_menu_append(section, _("Zoom In"), "zoom-in");
+    g_menu_append(section, _("Zoom Out"), "zoom-out");
+    g_menu_append(section, _("Zoom 100%"), "zoom-reset");
 
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
 
     if (libbalsa_html_can_select(html)) {
         section = g_menu_new();
-        g_menu_append(section, _("Select _All"), "text-view-popup.select-all");
+        g_menu_append(section, _("Select _All"), "select-all");
         g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
         g_object_unref(section);
     }
@@ -1256,19 +1257,19 @@ bmwt_html_populate_popup_menu(BalsaMessage * bm,
 
     open_menu = g_menu_new();
     libbalsa_vfs_fill_menu_by_content_type(open_menu, "text/html",
-                                           "text-view-popup.open-with");
+                                           "open-with");
 
     g_menu_append_submenu(section, _("Open…"), G_MENU_MODEL(open_menu));
     g_object_unref(open_menu);
 
-    g_menu_append(section, _("Save…"), "text-view-popup.save");
+    g_menu_append(section, _("Save…"), "save");
 
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
 
     section = g_menu_new();
 
-    g_menu_append(section, _("Print…"), "text-view-popup.print");
+    g_menu_append(section, _("Print…"), "print");
     g_simple_action_set_enabled(G_SIMPLE_ACTION(print_action),
                                 libbalsa_html_can_print(html));
 
@@ -1282,29 +1283,24 @@ static gboolean
 bmwt_html_popup_context_menu(GtkWidget    *html,
                              BalsaMessage *bm)
 {
-    GtkWidget *popup_menu;
+    GtkWidget *popup_widget;
     const GdkEvent *event;
     GdkEvent *current_event = NULL;
     gdouble x, y;
 
-    popup_menu = g_object_get_data(G_OBJECT(html), "popup-menu");
-    if (popup_menu == NULL) {
+    popup_widget = g_object_get_data(G_OBJECT(html), "popup-widget");
+    if (popup_widget == NULL) {
         GMenu *menu;
 
         menu = g_menu_new();
-        bmwt_html_populate_popup_menu(bm, html, menu);
-
-        if (libbalsa_use_popover()) {
-            popup_menu = gtk_popover_new_from_model(libbalsa_html_get_view_widget(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);
-        }
+        bmwt_html_populate_popup_menu(bm, html, menu, "text-view-popup");
+
+        popup_widget = libbalsa_popup_widget_new(libbalsa_html_get_view_widget(html),
+                                               G_MENU_MODEL(menu),
+                                               "text-view-popup");
+        g_object_unref(menu);
 
-        g_object_set_data(G_OBJECT(html), "popup-menu", popup_menu);
+        g_object_set_data(G_OBJECT(html), "popup-widget", popup_widget);
     }
 
     /* In WebKit2, the context menu signal is asynchronous, so the
@@ -1325,15 +1321,15 @@ bmwt_html_popup_context_menu(GtkWidget    *html,
             rectangle.width = 0;
             rectangle.y = (gint) y;
             rectangle.height = 0;
-            gtk_popover_set_pointing_to(GTK_POPOVER(popup_menu), &rectangle);
+            gtk_popover_set_pointing_to(GTK_POPOVER(popup_widget), &rectangle);
         }
-        gtk_popover_popup(GTK_POPOVER(popup_menu));
+        gtk_popover_popup(GTK_POPOVER(popup_widget));
     } else {
         if (event != NULL)
-            gtk_menu_popup_at_pointer(GTK_MENU(popup_menu),
+            gtk_menu_popup_at_pointer(GTK_MENU(popup_widget),
                                      (GdkEvent *) event);
         else
-            gtk_menu_popup_at_widget(GTK_MENU(popup_menu),
+            gtk_menu_popup_at_widget(GTK_MENU(popup_widget),
                                      GTK_WIDGET(bm),
                                      GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
                                      NULL);
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index ac86be1de..9f429f00d 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -1111,15 +1111,15 @@ create_context_menu(BalsaMailboxNode *mbnode,
 
     /* "New" submenu */
     submenu = g_menu_new();
-    g_menu_append(submenu, _("Local _mbox mailbox…"), "mbnode.add-mbox");
-    g_menu_append(submenu, _("Local Mail_dir mailbox…"), "mbnode.add-maildir");
-    g_menu_append(submenu, _("Local M_H mailbox…"), "mbnode.add-mh");
+    g_menu_append(submenu, _("Local _mbox mailbox…"), "add-mbox");
+    g_menu_append(submenu, _("Local Mail_dir mailbox…"), "add-maildir");
+    g_menu_append(submenu, _("Local M_H mailbox…"), "add-mh");
 
     section = g_menu_new();
-    g_menu_append(section, _("Remote IMAP _folder…"), "mbnode.add-imap-folder");
+    g_menu_append(section, _("Remote IMAP _folder…"), "add-imap-folder");
 
     if (balsa_mailbox_node_is_imap(mbnode))
-        g_menu_append(section, _("Remote IMAP _subfolder…"), "mbnode.add-imap-subfolder");
+        g_menu_append(section, _("Remote IMAP _subfolder…"), "add-imap-subfolder");
 
     g_menu_append_section(submenu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
@@ -1130,7 +1130,7 @@ create_context_menu(BalsaMailboxNode *mbnode,
 
     section = g_menu_new();
     if (mbnode == NULL) {/* clicked on the empty space */
-        g_menu_append(section, _("_Rescan"), "mbnode.rescan");
+        g_menu_append(section, _("_Rescan"), "rescan");
     } else {
         mbnode->relative_to = relative_to;
 
@@ -1138,19 +1138,19 @@ create_context_menu(BalsaMailboxNode *mbnode,
         if (g_signal_has_handler_pending(mbnode,
                                          balsa_mailbox_node_signals
                                          [SHOW_PROP_DIALOG], 0, FALSE))
-            g_menu_append(section, _("_Properties…"), "mbnode.show-properties");
+            g_menu_append(section, _("_Properties…"), "show-properties");
 
         if (g_signal_has_handler_pending(mbnode,
                                          balsa_mailbox_node_signals[APPEND_SUBTREE],
                                          0, FALSE))
-            g_menu_append(section, _("_Rescan"), "mbnode.rescan");
+            g_menu_append(section, _("_Rescan"), "rescan");
 
         if (mbnode->config_prefix != NULL)
-            g_menu_append(section, _("_Delete"), "mbnode.delete");
+            g_menu_append(section, _("_Delete"), "delete");
 
         if ((mailbox = mbnode->mailbox) != NULL) {
-            g_menu_append(section, _("_Open"), "mbnode.open");
-            g_menu_append(section, _("_Close"), "mbnode.close");
+            g_menu_append(section, _("_Open"), "open");
+            g_menu_append(section, _("_Close"), "close");
             context_menu_set_enabled(mbnode);
 
             special = (   mailbox == balsa_app.inbox
@@ -1159,19 +1159,19 @@ create_context_menu(BalsaMailboxNode *mbnode,
                        || mailbox == balsa_app.outbox
                        || mailbox == balsa_app.trash);
             if (!special && !mbnode->config_prefix)
-                g_menu_append(section, _("_Delete"), "mbnode.delete");
+                g_menu_append(section, _("_Delete"), "delete");
 
             if (!special) {
                 g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
                 g_object_unref(section);
                 section = g_menu_new();
 
-                g_menu_append(section, _("Mark as _Inbox"), "mbnode.mark-as-inbox");
-                g_menu_append(section, _("_Mark as Sentbox"), "mbnode.mark-as-sentbox");
-                g_menu_append(section, _("Mark as _Trash"), "mbnode.mark-as-trash");
-                g_menu_append(section, _("Mark as D_raftbox"), "mbnode.mark-as-draftbox");
+                g_menu_append(section, _("Mark as _Inbox"), "mark-as-inbox");
+                g_menu_append(section, _("_Mark as Sentbox"), "mark-as-sentbox");
+                g_menu_append(section, _("Mark as _Trash"), "mark-as-trash");
+                g_menu_append(section, _("Mark as D_raftbox"), "mark-as-draftbox");
             } else if (mailbox == balsa_app.trash) {
-                g_menu_append(section, _("_Empty trash"), "mbnode.empty-trash");
+                g_menu_append(section, _("_Empty trash"), "empty-trash");
             }
 
             /* FIXME : No test on mailbox type is made yet, should we ? */
@@ -1179,20 +1179,14 @@ create_context_menu(BalsaMailboxNode *mbnode,
             g_object_unref(section);
             section = g_menu_new();
 
-            g_menu_append(section, _("_Edit/Apply filters"), "mbnode.filters");
-                           // G_CALLBACK(mb_filter_cb), mbnode);
+            g_menu_append(section, _("_Edit/Apply filters"), "filters");
         }
     }
 
     g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
     g_object_unref(section);
 
-    if (libbalsa_use_popover()) {
-        context_menu = gtk_popover_new_from_model(relative_to, G_MENU_MODEL(menu));
-    } else {
-        context_menu = gtk_menu_new_from_model(G_MENU_MODEL(menu));
-        gtk_menu_attach_to_widget(GTK_MENU(context_menu), relative_to, NULL);
-    }
+    context_menu = libbalsa_popup_widget_new(relative_to, G_MENU_MODEL(menu), "mbnode");
     g_object_unref(menu);
 
     return context_menu;
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 011c90a1b..b516e85e1 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1801,19 +1801,8 @@ add_attachment(BalsaSendmsg * bsmsg, const gchar *filename,
         g_object_unref(section);
     }
 
-    if (libbalsa_use_popover()) {
-        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);
-    } else {
-        attach_data->popup_menu = gtk_menu_new();
-        gtk_menu_shell_bind_model(GTK_MENU_SHELL(attach_data->popup_menu),
-                                  G_MENU_MODEL(menu),
-                                  attachment_namespace,
-                                  TRUE);
-        gtk_menu_attach_to_widget(GTK_MENU(attach_data->popup_menu), bsmsg->tree_view, NULL);
-    }
+    attach_data->popup_menu =
+        libbalsa_popup_widget_new(bsmsg->tree_view, G_MENU_MODEL(menu), attachment_namespace);
 
     g_object_unref(menu);
     g_free(attachment_namespace);
@@ -1853,7 +1842,7 @@ add_urlref_attachment(BalsaSendmsg * bsmsg, const gchar *url)
         {"open", libbalsa_radio_activated, "s", "''", on_open_url_cb}
     };
     GMenu *menu;
-    GMenu *open_menu;
+    GMenu *section;
 
     g_debug("Trying to attach '%s'", url);
 
@@ -1889,23 +1878,23 @@ add_urlref_attachment(BalsaSendmsg * bsmsg, const gchar *url)
     g_object_unref(simple);
 
     menu = g_menu_new();
-    g_menu_append(menu, _("Remove"), "urlref-attachment.remove");
+
+    section = g_menu_new();
+    g_menu_append(section, _("Remove"), "remove");
+
+    g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
+    g_object_unref(section);
 
     /* add a separator and the usual vfs menu so the user can inspect what
        (s)he actually attached... (only for non-message attachments) */
-    open_menu = g_menu_new();
-    g_menu_append(open_menu, _("Open…"), "urlref-attachment.open");
+    section = g_menu_new();
+    g_menu_append(section, _("Open…"), "open");
 
-    g_menu_append_section(menu, NULL, G_MENU_MODEL(open_menu));
-    g_object_unref(open_menu);
+    g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
+    g_object_unref(section);
 
-    if (libbalsa_use_popover()) {
-        attach_data->popup_menu =
-            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_menu_attach_to_widget(GTK_MENU(attach_data->popup_menu), bsmsg->window, NULL);
-    }
+    attach_data->popup_menu =
+        libbalsa_popup_widget_new(bsmsg->window, G_MENU_MODEL(menu), "urlref-attachment");
     g_object_unref(menu);
 
     /* append to the list store */
diff --git a/src/toolbar-factory.c b/src/toolbar-factory.c
index b4a442ad3..ec953d5a7 100644
--- a/src/toolbar-factory.c
+++ b/src/toolbar-factory.c
@@ -639,7 +639,6 @@ tm_popup_context_menu_cb(GtkWidget    * toolbar,
                          toolbar_info * info)
 {
     GSimpleActionGroup *simple;
-    static const char namespace[] = "toolbar";
     static const GActionEntry entries[] = {
         {"set-style", libbalsa_radio_activated, "i", "-1", tm_set_style_changed},
         {"customize", tm_customize_activated}
@@ -658,7 +657,7 @@ tm_popup_context_menu_cb(GtkWidget    * toolbar,
                                     G_N_ELEMENTS(entries),
                                     info);
     set_style_action = g_action_map_lookup_action(G_ACTION_MAP(simple), "set-style");
-    gtk_widget_insert_action_group(toolbar, namespace, G_ACTION_GROUP(simple));
+    gtk_widget_insert_action_group(toolbar, "toolbar", G_ACTION_GROUP(simple));
     g_object_unref(simple);
 
     menu = g_menu_new();
@@ -727,14 +726,7 @@ tm_popup_context_menu_cb(GtkWidget    * toolbar,
         g_object_unref(section);
     }
 
-    if (libbalsa_use_popover()) {
-        popup_menu = gtk_popover_new(toolbar);
-        gtk_popover_bind_model(GTK_POPOVER(popup_menu), G_MENU_MODEL(menu), namespace);
-    } 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);
-    }
+    popup_menu = libbalsa_popup_widget_new(toolbar, G_MENU_MODEL(menu), "toolbar");
 
     g_object_unref(menu);
     info->popup_menu = popup_menu;


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