[evolution] I#1505 - Mail: Prefer existing message window on message open
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#1505 - Mail: Prefer existing message window on message open
- Date: Tue, 25 May 2021 11:50:07 +0000 (UTC)
commit 2129be64b38b9a45cb9d8b68fa3f7357ebb7e252
Author: Milan Crha <mcrha redhat com>
Date: Tue May 25 13:48:01 2021 +0200
I#1505 - Mail: Prefer existing message window on message open
Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1505
src/mail/e-mail-reader-utils.c | 14 +++++++++
src/mail/e-mail-reader.c | 13 ++++++++
src/mail/em-utils.c | 67 ++++++++++++++++++++++++++++++++++++++++++
src/mail/em-utils.h | 4 +++
4 files changed, 98 insertions(+)
---
diff --git a/src/mail/e-mail-reader-utils.c b/src/mail/e-mail-reader-utils.c
index b15001e277..7af1c7a4ee 100644
--- a/src/mail/e-mail-reader-utils.c
+++ b/src/mail/e-mail-reader-utils.c
@@ -1410,6 +1410,7 @@ e_mail_reader_open_selected (EMailReader *reader)
GPtrArray *views;
GPtrArray *uids;
guint ii = 0;
+ gboolean prefer_existing;
g_return_val_if_fail (E_IS_MAIL_READER (reader), 0);
@@ -1435,6 +1436,8 @@ e_mail_reader_open_selected (EMailReader *reader)
goto exit;
}
+ prefer_existing = !E_IS_MAIL_BROWSER (window);
+
views = g_ptr_array_new ();
/* For vfolders we need to edit the original, not the vfolder copy. */
@@ -1479,6 +1482,17 @@ e_mail_reader_open_selected (EMailReader *reader)
GtkWidget *browser;
MessageList *ml;
+ if (prefer_existing) {
+ EMailBrowser *mail_browser;
+
+ mail_browser = em_utils_find_message_window (E_MAIL_FORMATTER_MODE_NORMAL, folder,
uid);
+
+ if (mail_browser) {
+ gtk_window_present (GTK_WINDOW (mail_browser));
+ continue;
+ }
+ }
+
browser = e_mail_browser_new (backend, E_MAIL_FORMATTER_MODE_NORMAL);
ml = MESSAGE_LIST (e_mail_reader_get_message_list (
diff --git a/src/mail/e-mail-reader.c b/src/mail/e-mail-reader.c
index ac49eb20d8..7011250c51 100644
--- a/src/mail/e-mail-reader.c
+++ b/src/mail/e-mail-reader.c
@@ -2200,6 +2200,19 @@ action_mail_show_source_cb (GtkAction *action,
g_return_if_fail (uids != NULL && uids->len == 1);
message_uid = g_ptr_array_index (uids, 0);
+ if (!E_IS_MAIL_BROWSER (e_mail_reader_get_window (reader))) {
+ EMailBrowser *mail_browser;
+
+ mail_browser = em_utils_find_message_window (E_MAIL_FORMATTER_MODE_SOURCE, folder,
message_uid);
+
+ if (mail_browser) {
+ gtk_window_present (GTK_WINDOW (mail_browser));
+ g_ptr_array_unref (uids);
+ g_clear_object (&folder);
+ return;
+ }
+ }
+
browser = e_mail_browser_new (backend, E_MAIL_FORMATTER_MODE_SOURCE);
ml = MESSAGE_LIST (e_mail_reader_get_message_list (E_MAIL_READER (browser)));
diff --git a/src/mail/em-utils.c b/src/mail/em-utils.c
index 1be0785b12..876fce7f4e 100644
--- a/src/mail/em-utils.c
+++ b/src/mail/em-utils.c
@@ -2020,3 +2020,70 @@ em_utils_account_path_to_folder_uri (CamelSession *session,
return folder_uri;
}
+
+EMailBrowser *
+em_utils_find_message_window (EMailFormatterMode display_mode,
+ CamelFolder *folder,
+ const gchar *message_uid)
+{
+ EShell *shell;
+ GList *windows, *link;
+
+ g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+ g_return_val_if_fail (message_uid != NULL, NULL);
+
+ shell = e_shell_get_default ();
+ windows = gtk_application_get_windows (GTK_APPLICATION (shell));
+
+ for (link = windows; link; link = g_list_next (link)) {
+ GtkWindow *window = link->data;
+
+ if (E_IS_MAIL_BROWSER (window)) {
+ EMailBrowser *browser = E_MAIL_BROWSER (window);
+ gboolean matched = FALSE;
+
+ if (e_mail_browser_get_display_mode (browser) == display_mode) {
+ CamelFolder *tmp_folder;
+ GPtrArray *uids;
+
+ tmp_folder = e_mail_reader_ref_folder (E_MAIL_READER (browser));
+ uids = e_mail_reader_get_selected_uids (E_MAIL_READER (browser));
+
+ if (uids->len == 1) {
+ const gchar *uid = g_ptr_array_index (uids, 0);
+
+ matched = g_strcmp0 (message_uid, uid) == 0 &&
+ folder == tmp_folder;
+
+ if (!matched) {
+ CamelFolder *real_folder = NULL, *tmp_real_folder = NULL;
+ gchar *real_uid = NULL, *tmp_real_uid = NULL;
+
+ if (CAMEL_IS_VEE_FOLDER (folder))
+ em_utils_get_real_folder_and_message_uid (folder,
message_uid, &real_folder, NULL, &real_uid);
+
+ if (CAMEL_IS_VEE_FOLDER (tmp_folder))
+ em_utils_get_real_folder_and_message_uid (tmp_folder,
uid, &tmp_real_folder, NULL, &tmp_real_uid);
+
+ matched = (real_folder || tmp_real_folder) &&
+ (real_folder ? real_folder : folder) ==
(tmp_real_folder ? tmp_real_folder : tmp_folder) &&
+ g_strcmp0 (real_uid ? real_uid : message_uid,
tmp_real_uid ? tmp_real_uid : uid) == 0;
+
+ g_clear_object (&tmp_real_folder);
+ g_clear_object (&real_folder);
+ g_free (tmp_real_uid);
+ g_free (real_uid);
+ }
+ }
+
+ g_ptr_array_unref (uids);
+ g_clear_object (&tmp_folder);
+ }
+
+ if (matched)
+ return browser;
+ }
+ }
+
+ return NULL;
+}
diff --git a/src/mail/em-utils.h b/src/mail/em-utils.h
index ee1bebbf49..e000ef43d6 100644
--- a/src/mail/em-utils.h
+++ b/src/mail/em-utils.h
@@ -28,6 +28,7 @@
#include <libemail-engine/libemail-engine.h>
+#include <mail/e-mail-browser.h>
#include <mail/e-mail-reader.h>
#include <mail/em-folder-tree.h>
@@ -122,6 +123,9 @@ gchar * em_utils_build_export_basename (CamelFolder *folder,
gchar * em_utils_account_path_to_folder_uri
(CamelSession *session,
const gchar *account_path); /* On This
Computer/Inbox/Subfolder... */
+EMailBrowser * em_utils_find_message_window (EMailFormatterMode display_mode,
+ CamelFolder *folder,
+ const gchar *message_uid);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]