[balsa/popover: 40/70] pref-manager: Use GtkMenuButton



commit df7aca4724bf8ce49c1d88be19746e7524f852ae
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 4826cd596..ab5c34731 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -84,6 +84,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 4a339a81e..16645c041 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -1012,12 +1012,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)
 {
@@ -1638,19 +1651,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)
 {
@@ -1973,7 +1973,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);
 
@@ -2016,13 +2015,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),
@@ -2722,7 +2717,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);
@@ -2778,16 +2772,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]