[balsa/popover: 10/32] Various: Adapt to MRU menu changes



commit 86478f84e205bc7b49a818240423af6c8c60a8de
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue May 5 10:54:43 2020 -0400

    Various: Adapt to MRU menu changes

 src/balsa-index.c               | 25 ++++++++++++++-----------
 src/balsa-message.c             | 12 ++++++++----
 src/balsa-mime-widget-message.c | 18 ++++++++++++------
 src/message-window.c            | 13 ++++++++-----
 4 files changed, 42 insertions(+), 26 deletions(-)
---
diff --git a/src/balsa-index.c b/src/balsa-index.c
index f143d637a..45874bc58 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -1918,14 +1918,19 @@ move_to_change_state(GSimpleAction *action,
                      GVariant      *parameter,
                      gpointer       user_data)
 {
-    BalsaIndex *index = user_data;
-    const gchar *url = g_variant_get_string(parameter, NULL);
-    LibBalsaMailbox *mailbox = balsa_find_mailbox_by_url(url);
-
-    if (balsa_mailbox_node_get_mailbox(index->mailbox_node) != mailbox) {
-        GArray *selected = balsa_index_selected_msgnos_new(index);
-        balsa_index_transfer(index, selected, mailbox, FALSE);
-        balsa_index_selected_msgnos_free(index, selected);
+    BalsaIndex *bindex = user_data;
+    LibBalsaMailbox *mailbox;
+
+    mailbox =
+        balsa_mblist_mru_get_mailbox_from_variant(parameter, GTK_WIDGET(bindex));
+
+    if (mailbox != NULL) {
+        balsa_mblist_mru_add(&balsa_app.folder_mru, libbalsa_mailbox_get_url(mailbox));
+        if (mailbox != balsa_mailbox_node_get_mailbox(bindex->mailbox_node)) {
+            GArray *selected = balsa_index_selected_msgnos_new(bindex);
+            balsa_index_transfer(bindex, selected, mailbox, FALSE);
+            balsa_index_selected_msgnos_free(bindex, selected);
+        }
     }
 }
 
@@ -1990,9 +1995,7 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent *event)
     g_object_unref(simple);
 
     mru_menu =
-        balsa_mblist_mru_menu(GTK_WINDOW
-                              (gtk_widget_get_toplevel(GTK_WIDGET(index))),
-                              &balsa_app.folder_mru, "bndx-popup.move-to");
+        balsa_mblist_mru_menu(&balsa_app.folder_mru, "bndx-popup.move-to");
     submenu = gtk_menu_new_from_model(G_MENU_MODEL(mru_menu));
     g_object_unref(mru_menu);
 
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 3dd761cd4..89d21726f 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -1640,10 +1640,15 @@ copy_part_change_state(GSimpleAction *action,
                        GVariant      *parameter,
                        gpointer       user_data)
 {
-    const gchar *url = g_variant_get_string(parameter, NULL);
     BalsaPartInfo *info = user_data;
+    const gchar *url;
 
-    balsa_message_copy_part(url, info->body);
+    url = balsa_mblist_mru_get_url_from_variant(parameter, info->popup_menu);
+
+    if (url[0] != '\0') {
+        balsa_mblist_mru_add(&balsa_app.folder_mru, url);
+        balsa_message_copy_part(url, info->body);
+    }
 
     g_simple_action_set_state(action, parameter);
 }
@@ -1689,8 +1694,7 @@ part_create_menu(BalsaMessage *balsa_message, BalsaPartInfo *info)
         GMenu *submenu;
 
         submenu =
-            balsa_mblist_mru_menu(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(balsa_message))),
-                                  &balsa_app.folder_mru, "part-menu.copy-part");
+            balsa_mblist_mru_menu(&balsa_app.folder_mru, "part-menu.copy-part");
 
         g_menu_append_submenu(menu, _("_Copy to folder…"), G_MENU_MODEL(submenu));
     }
diff --git a/src/balsa-mime-widget-message.c b/src/balsa-mime-widget-message.c
index 6189116e6..0b33c24d4 100644
--- a/src/balsa-mime-widget-message.c
+++ b/src/balsa-mime-widget-message.c
@@ -442,15 +442,20 @@ copy_change_state(GSimpleAction *action,
                   GVariant      *parameter,
                   gpointer       user_data)
 {
-    const gchar *url = g_variant_get_string(parameter, NULL);
     LibBalsaMessageBody *part = user_data;
+    const gchar *url =
+        balsa_mblist_mru_get_url_from_variant(parameter, part->user_data);
 
-    balsa_message_copy_part(url, part);
+    if (url[0] != '\0') {
+        balsa_mblist_mru_add(&balsa_app.folder_mru, url);
+        balsa_message_copy_part(url, part);
+    }
 }
 
 static void
 bm_header_extend_popup(GtkWidget * widget, GtkMenu * menu, gpointer arg)
 {
+    LibBalsaMessageBody *part = arg;
     GSimpleActionGroup *simple;
     static const GActionEntry header_popup_entries[] = {
         {"copy", libbalsa_radio_activated, "s", "''", copy_change_state},
@@ -459,12 +464,14 @@ bm_header_extend_popup(GtkWidget * widget, GtkMenu * menu, gpointer arg)
     GtkWidget *menu_item, *submenu;
     GtkWidget *separator = gtk_separator_menu_item_new();
 
+    part->user_data = widget;
+
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator);
     gtk_widget_show(separator);
     menu_item = gtk_menu_item_new_with_label(_("Reply…"));
     g_signal_connect(menu_item, "activate",
                      G_CALLBACK(bm_header_ctx_menu_reply),
-                     arg);
+                     part);
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
     gtk_widget_show(menu_item);
 
@@ -472,15 +479,14 @@ bm_header_extend_popup(GtkWidget * widget, GtkMenu * menu, gpointer arg)
     g_action_map_add_action_entries(G_ACTION_MAP(simple),
                                     header_popup_entries,
                                     G_N_ELEMENTS(header_popup_entries),
-                                    arg);
+                                    part);
     gtk_widget_insert_action_group(widget,
                                    "header-popup",
                                    G_ACTION_GROUP(simple));
     g_object_unref(simple);
 
     mru_menu =
-        balsa_mblist_mru_menu(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
-                              &balsa_app.folder_mru, "header-popup.copy");
+        balsa_mblist_mru_menu(&balsa_app.folder_mru, "header-popup.copy");
     submenu = gtk_menu_new_from_model(G_MENU_MODEL(mru_menu));
     g_object_unref(mru_menu);
 
diff --git a/src/message-window.c b/src/message-window.c
index fdf587ae9..719b1f5ef 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -804,10 +804,14 @@ move_to_change_state(GSimpleAction *action,
                      gpointer       user_data)
 {
     MessageWindow *mw = user_data;
-    const gchar *url = g_variant_get_string(parameter, NULL);
-    LibBalsaMailbox *mailbox = balsa_find_mailbox_by_url(url);
+    LibBalsaMailbox *mailbox;
+
+    mailbox = balsa_mblist_mru_get_mailbox_from_variant(parameter, mw->window);
 
-    message_window_move_message(mw, mailbox);
+    if (mailbox != NULL) {
+        balsa_mblist_mru_add(&balsa_app.folder_mru, libbalsa_mailbox_get_url(mailbox));
+        message_window_move_message(mw, mailbox);
+    }
 }
 
 void
@@ -906,8 +910,7 @@ message_window_new(LibBalsaMailbox * mailbox, guint msgno)
     g_object_unref(simple);
 
     mru_menu =
-        balsa_mblist_mru_menu(GTK_WINDOW(window),
-                              &balsa_app.folder_mru, "message-window.move-to");
+        balsa_mblist_mru_menu(&balsa_app.folder_mru, "message-window.move-to");
     submenu = gtk_menu_new_from_model(G_MENU_MODEL(mru_menu));
     g_object_unref(mru_menu);
 


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