[geary] Fix ComposerWebView considering itself edited when in plain text mode.



commit fe7a83d644932b75903b7e4ea46e0b86fbed19b0
Author: Michael James Gratton <mike vee net>
Date:   Wed Feb 7 15:27:47 2018 +1100

    Fix ComposerWebView considering itself edited when in plain text mode.
    
    Now that we're not using show_all() on the main window any more, we can
    safely set up the UI for both rich text editing and bcc/reply-to fields
    when first constructing the composer, rather than once it has loaded and
    been shown. Since we're not setting plain text mode after it's loaded,
    the body is not getting modified after loading and hence not being
    flagged as being non-empty.
    
    This also stops Geary prompting to close new, blank composer, and stops it
    from saving drafts for same.
    
    * src/client/composer/composer-widget.vala (ComposerWidget): Set rich
      text and extended fields action states when constructed. Set delete
      quote trigger when composer content has loaded, not when the page load
      has finished. Remove now redundant page-load-and-realised handler.
    
    * src/client/composer/composer-web-view.vala (ClientWebView): Observe
      rich text mode and set the appropriate class on the body when loading
      it up front. Don't try to update rich text mode if the body hasn't been
      loaded.

 src/client/composer/composer-web-view.vala |    9 +++++--
 src/client/composer/composer-widget.vala   |   34 +++++++++-------------------
 2 files changed, 17 insertions(+), 26 deletions(-)
---
diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala
index d5b656b..816de42 100644
--- a/src/client/composer/composer-web-view.vala
+++ b/src/client/composer/composer-web-view.vala
@@ -144,7 +144,7 @@ public class ComposerWebView : ClientWebView {
                               string quote,
                               bool top_posting,
                               bool is_draft) {
-        const string HTML_PRE = """<html><body dir="auto">""";
+        const string HTML_PRE = """<html><body class="%s" dir="auto">""";
         const string HTML_POST = """</body></html>""";
         const string BODY_PRE = """
 <div id="geary-body">""";
@@ -160,7 +160,8 @@ public class ComposerWebView : ClientWebView {
         const string SPACER = "<div><br /></div>";
 
         StringBuilder html = new StringBuilder();
-        html.append(HTML_PRE);
+        string body_class = (this.is_rich_text) ? "" : "plain";
+        html.append(HTML_PRE.printf(body_class));
         if (!is_draft) {
             html.append(BODY_PRE);
             bool have_body = !Geary.String.is_empty(body);
@@ -204,7 +205,9 @@ public class ComposerWebView : ClientWebView {
      */
     public void set_rich_text(bool enabled) {
         this.is_rich_text = enabled;
-        this.call.begin(Geary.JS.callable("geary.setRichText").bool(enabled), null);
+        if (this.is_content_loaded) {
+            this.call.begin(Geary.JS.callable("geary.setRichText").bool(enabled), null);
+        }
     }
 
     /**
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 261f0ef..d02454c 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -510,7 +510,7 @@ public class ComposerWidget : Gtk.EventBox {
         this.editor.document_modified.connect(() => { draft_changed(); });
         this.editor.get_editor_state().notify["typing-attributes"].connect(on_typing_attributes_changed);
         this.editor.key_press_event.connect(on_editor_key_press_event);
-        this.editor.load_changed.connect(on_load_changed);
+        this.editor.content_loaded.connect(on_content_loaded);
         this.editor.mouse_target_changed.connect(on_mouse_target_changed);
         this.editor.selection_changed.connect(on_selection_changed);
 
@@ -838,8 +838,14 @@ public class ComposerWidget : Gtk.EventBox {
         insert_action_group("cmp", this.actions);
         this.header.insert_action_group("cmh", this.actions);
 
-        get_action(ACTION_CLOSE_AND_SAVE).set_enabled(false);
+        this.actions.change_action_state(
+            ACTION_SHOW_EXTENDED, false
+        );
+        this.actions.change_action_state(
+            ACTION_COMPOSE_AS_HTML, this.config.compose_as_html
+        );
 
+        get_action(ACTION_CLOSE_AND_SAVE).set_enabled(false);
         get_action(ACTION_UNDO).set_enabled(false);
         get_action(ACTION_REDO).set_enabled(false);
 
@@ -872,30 +878,12 @@ public class ComposerWidget : Gtk.EventBox {
         return false;
     }
 
-    private void on_load_changed(WebKit.WebView view, WebKit.LoadEvent event) {
-        if (event == WebKit.LoadEvent.FINISHED) {
-            if (get_realized())
-                on_load_finished_and_realized();
-            else
-                realize.connect(on_load_finished_and_realized);
-        }
-    }
-
-    private void on_load_finished_and_realized() {
-        // This is safe to call even when this connection hasn't been made.
-        realize.disconnect(on_load_finished_and_realized);
-
-        this.actions.change_action_state(
-            ACTION_SHOW_EXTENDED, false
-        );
-        this.actions.change_action_state(
-            ACTION_COMPOSE_AS_HTML, this.config.compose_as_html
-        );
-
-        if (can_delete_quote)
+    private void on_content_loaded() {
+        if (this.can_delete_quote) {
             this.editor.selection_changed.connect(
                 () => { this.can_delete_quote = false; }
             );
+        }
     }
 
     private void show_attachment_overlay(bool visible) {


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