[evolution/gnome-3-36] I#906 - composer-plain-text-starts-preformatted is not followed when replying to HTML emails
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-36] I#906 - composer-plain-text-starts-preformatted is not followed when replying to HTML emails
- Date: Wed, 20 May 2020 10:31:36 +0000 (UTC)
commit 63ef9a5dceb25aaf35088cb965ce6b0ea655b16e
Author: Milan Crha <mcrha redhat com>
Date: Wed May 20 12:34:59 2020 +0200
I#906 - composer-plain-text-starts-preformatted is not followed when replying to HTML emails
Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/906
src/mail/e-mail-notes.c | 37 ++++++++++++++++++++++++++-------
src/modules/mail/e-mail-shell-backend.c | 36 ++++++++++++++++++++++++++------
2 files changed, 60 insertions(+), 13 deletions(-)
---
diff --git a/src/mail/e-mail-notes.c b/src/mail/e-mail-notes.c
index a730afd101..1b532b07df 100644
--- a/src/mail/e-mail-notes.c
+++ b/src/mail/e-mail-notes.c
@@ -924,15 +924,39 @@ e_mail_notes_editor_init (EMailNotesEditor *notes_editor)
static gboolean
set_preformatted_block_format_on_idle_cb (gpointer user_data)
{
- EContentEditor *cnt_editor = user_data;
+ GWeakRef *weakref = user_data;
+ EContentEditor *cnt_editor;
+
+ g_return_val_if_fail (weakref != NULL, FALSE);
- g_return_val_if_fail (E_IS_CONTENT_EDITOR (cnt_editor), FALSE);
+ cnt_editor = g_weak_ref_get (weakref);
- e_content_editor_set_block_format (cnt_editor, E_CONTENT_EDITOR_BLOCK_FORMAT_PRE);
+ if (cnt_editor) {
+ e_content_editor_set_block_format (cnt_editor, E_CONTENT_EDITOR_BLOCK_FORMAT_PRE);
+ e_content_editor_set_changed (cnt_editor, FALSE);
+ e_content_editor_clear_undo_redo_history (cnt_editor);
+
+ g_object_unref (cnt_editor);
+ }
return FALSE;
}
+static void
+schedule_set_preformatted_block_format_on_load_finished_cb (EContentEditor *cnt_editor,
+ gpointer user_data)
+{
+ g_return_if_fail (E_IS_CONTENT_EDITOR (cnt_editor));
+
+ if (!e_content_editor_get_html_mode (cnt_editor)) {
+ g_idle_add_full (G_PRIORITY_LOW, set_preformatted_block_format_on_idle_cb,
+ e_weak_ref_new (cnt_editor), (GDestroyNotify) e_weak_ref_free);
+ }
+
+ g_signal_handlers_disconnect_by_func (cnt_editor,
+ G_CALLBACK (schedule_set_preformatted_block_format_on_load_finished_cb), NULL);
+}
+
static EMailNotesEditor *
e_mail_notes_editor_new_with_editor (EHTMLEditor *html_editor,
GtkWindow *parent,
@@ -1086,10 +1110,9 @@ e_mail_notes_editor_new_with_editor (EHTMLEditor *html_editor,
settings = e_util_ref_settings ("org.gnome.evolution.mail");
e_content_editor_set_html_mode (cnt_editor, g_settings_get_boolean (settings, "composer-send-html"));
- if (!g_settings_get_boolean (settings, "composer-send-html") &&
- g_settings_get_boolean (settings, "composer-plain-text-starts-preformatted")) {
- g_idle_add_full (G_PRIORITY_LOW, set_preformatted_block_format_on_idle_cb,
- g_object_ref (cnt_editor), g_object_unref);
+ if (g_settings_get_boolean (settings, "composer-plain-text-starts-preformatted")) {
+ g_signal_connect (cnt_editor, "load-finished",
+ G_CALLBACK (schedule_set_preformatted_block_format_on_load_finished_cb), NULL);
}
g_object_unref (settings);
diff --git a/src/modules/mail/e-mail-shell-backend.c b/src/modules/mail/e-mail-shell-backend.c
index 12c38fe3ec..898d4e3e4a 100644
--- a/src/modules/mail/e-mail-shell-backend.c
+++ b/src/modules/mail/e-mail-shell-backend.c
@@ -521,15 +521,39 @@ mail_shell_backend_window_weak_notify_cb (EShell *shell,
static gboolean
set_preformatted_block_format_on_idle_cb (gpointer user_data)
{
- EContentEditor *cnt_editor = user_data;
+ GWeakRef *weakref = user_data;
+ EContentEditor *cnt_editor;
- g_return_val_if_fail (E_IS_CONTENT_EDITOR (cnt_editor), FALSE);
+ g_return_val_if_fail (weakref != NULL, FALSE);
- e_content_editor_set_block_format (cnt_editor, E_CONTENT_EDITOR_BLOCK_FORMAT_PRE);
+ cnt_editor = g_weak_ref_get (weakref);
+
+ if (cnt_editor) {
+ e_content_editor_set_block_format (cnt_editor, E_CONTENT_EDITOR_BLOCK_FORMAT_PRE);
+ e_content_editor_set_changed (cnt_editor, FALSE);
+ e_content_editor_clear_undo_redo_history (cnt_editor);
+
+ g_object_unref (cnt_editor);
+ }
return FALSE;
}
+static void
+schedule_set_preformatted_block_format_on_load_finished_cb (EContentEditor *cnt_editor,
+ gpointer user_data)
+{
+ g_return_if_fail (E_IS_CONTENT_EDITOR (cnt_editor));
+
+ if (!e_content_editor_get_html_mode (cnt_editor)) {
+ g_idle_add_full (G_PRIORITY_LOW, set_preformatted_block_format_on_idle_cb,
+ e_weak_ref_new (cnt_editor), (GDestroyNotify) e_weak_ref_free);
+ }
+
+ g_signal_handlers_disconnect_by_func (cnt_editor,
+ G_CALLBACK (schedule_set_preformatted_block_format_on_load_finished_cb), NULL);
+}
+
static void
mail_shell_backend_window_added_cb (GtkApplication *application,
GtkWindow *window,
@@ -568,9 +592,9 @@ mail_shell_backend_window_added_cb (GtkApplication *application,
e_content_editor_set_html_mode (cnt_editor, use_html);
- if (!use_html && use_preformatted) {
- g_idle_add_full (G_PRIORITY_LOW, set_preformatted_block_format_on_idle_cb,
- g_object_ref (cnt_editor), g_object_unref);
+ if (use_preformatted) {
+ g_signal_connect (cnt_editor, "load-finished",
+ G_CALLBACK (schedule_set_preformatted_block_format_on_load_finished_cb),
NULL);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]