[balsa/gtk4: 51/312] pref-manager: Use GtkMenuButton




commit b272b88042d99bfd8e78aa1e2da2eca5bcd5319e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jun 15 11:42:37 2020 -0400

    pref-manager: Use GtkMenuButton
    
    Use GtkMenuButton to pop-up "Add" menus.
    
    * src/pref-manager.c (add_button_to_box): no longer used for pop-up menus;
      (add_menu_button_to_box): new function;
      (pm_grid_add_remote_mailbox_servers_group), (pm_grid_add_address_books_group): use it.

 ChangeLog          | 10 ++++++++++
 src/pref-manager.c | 51 ++++++++++++++++++++-------------------------------
 2 files changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0c53e4ff2..e583df52c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -337,6 +337,16 @@
 
        * src/main.c (balsa_startup_cb):
 
+2020-06-15  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       pref-manager: Use GtkMenuButton to pop-up "Add" menus
+
+       * src/pref-manager.c (add_button_to_box): no longer used for
+       pop-up menus;
+       (add_menu_button_to_box): new function;
+       (pm_grid_add_remote_mailbox_servers_group),
+       (pm_grid_add_address_books_group): use it.
+
 2020-06-14  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Use a BALSA_USE_POPOVER=0 environment variable to switch from
diff --git a/src/pref-manager.c b/src/pref-manager.c
index 664a40bf4..36d31d496 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -1013,12 +1013,25 @@ add_button_to_box(const gchar * label, GCallback cb, gpointer cb_data,
     g_signal_connect_swapped(button, "clicked", cb, cb_data);
     gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
 
-    if (GTK_IS_POPOVER(cb_data))
-        gtk_popover_set_relative_to(cb_data, button);
-
     return button;
 }
 
+static void
+add_menu_button_to_box(const gchar *label,
+                       GMenuModel  *menu_model,
+                       GtkWidget   *box)
+{
+    GtkWidget *menu_button;
+
+    menu_button = gtk_menu_button_new();
+    gtk_container_add(GTK_CONTAINER(menu_button), gtk_label_new_with_mnemonic(label));
+
+    gtk_menu_button_set_use_popover(GTK_MENU_BUTTON(menu_button), libbalsa_use_popover());
+    gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menu_button), menu_model);
+
+    gtk_box_pack_start(GTK_BOX(box), menu_button, FALSE, FALSE, 0);
+}
+
 static void
 add_show_menu(const char* label, gint level, GtkWidget* menu)
 {
@@ -1639,19 +1652,6 @@ address_book_set_default_cb(GtkTreeView * tree_view)
     gtk_tree_path_free(path);
 }
 
-static void
-add_menu_cb(GtkWidget * menu, GtkWidget * widget)
-{
-    if (libbalsa_use_popover()) {
-        gtk_popover_popup(GTK_POPOVER(menu));
-    } else {
-        gtk_widget_show_all(menu);
-        gtk_menu_popup_at_widget(GTK_MENU(menu), GTK_WIDGET(widget),
-                                 GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST,
-                                 NULL);
-    }
-}
-
 static void
 address_book_delete_cb(GtkTreeView * tree_view)
 {
@@ -1974,7 +1974,6 @@ pm_grid_add_remote_mailbox_servers_group(GtkWidget * grid_widget)
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
     GMenuModel *menu_model;
-    GtkWidget *server_add_menu;
 
     pm_grid_attach(grid, pm_group_label(_("Remote mailbox servers")), 0, row, 3, 1);
 
@@ -2017,13 +2016,9 @@ pm_grid_add_remote_mailbox_servers_group(GtkWidget * grid_widget)
     vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, ROW_SPACING);
 
     menu_model = server_add_menu_model(vbox);
-    if (libbalsa_use_popover())
-        server_add_menu = gtk_popover_new_from_model(NULL, menu_model);
-    else
-        server_add_menu = gtk_menu_new_from_model(menu_model);
 
-    add_button_to_box(_("_Add"), G_CALLBACK(add_menu_cb),
-                      server_add_menu, vbox);
+    add_menu_button_to_box(_("_Add"), menu_model, vbox);
+
     add_button_to_box(_("_Modify"), G_CALLBACK(server_edit_cb),
                       tree_view, vbox);
     add_button_to_box(_("_Delete"), G_CALLBACK(server_del_cb),
@@ -2766,7 +2761,6 @@ pm_grid_add_address_books_group(GtkWidget * grid_widget)
     GtkTreeViewColumn *column;
     GtkWidget *scrolledwindow;
     GMenuModel *menu_model;
-    GtkWidget *address_book_add_menu;
     GtkWidget *vbox;
 
     pm_grid_attach(grid, pm_group_label(_("Address books")), 0, row, 3, 1);
@@ -2822,16 +2816,11 @@ pm_grid_add_address_books_group(GtkWidget * grid_widget)
 
     menu_model = balsa_address_book_add_menu(address_book_change,
                                              GTK_WINDOW(property_box));
-    if (libbalsa_use_popover())
-        address_book_add_menu = gtk_popover_new_from_model(NULL, menu_model);
-    else
-        address_book_add_menu = gtk_menu_new_from_model(menu_model);
 
     vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, HIG_PADDING);
 
-    add_button_to_box(_("_Add"),
-                      G_CALLBACK(add_menu_cb),
-                      address_book_add_menu, vbox);
+    add_menu_button_to_box(_("_Add"), menu_model, vbox);
+
     add_button_to_box(_("_Modify"),
                       G_CALLBACK(address_book_edit_cb),
                       tree_view, vbox);


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