[geary/wip/728002-webkit2: 80/96] Minor code cleanup.



commit bd502636f76822a904de704563081db12d08045b
Author: Michael James Gratton <mike vee net>
Date:   Wed Jan 4 20:11:31 2017 +1100

    Minor code cleanup.

 src/client/composer/composer-web-view.vala         |   85 ++++++++++----------
 src/client/composer/composer-widget.vala           |    9 +-
 .../conversation-viewer/conversation-message.vala  |    1 +
 src/client/web-process/util-webkit.vala            |   33 --------
 4 files changed, 49 insertions(+), 79 deletions(-)
---
diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala
index b470c59..1ea9107 100644
--- a/src/client/composer/composer-web-view.vala
+++ b/src/client/composer/composer-web-view.vala
@@ -119,17 +119,8 @@ public class ComposerWebView : ClientWebView {
         this.key_press_event.connect(on_key_press_event);
 
         this.user_content_manager.script_message_received[COMMAND_STACK_CHANGED].connect(
-            (result) => {
-                try {
-                    string[] values = WebKitUtil.to_string(result).split(",");
-                    command_stack_changed(values[0] == "true", values[1] == "true");
-                } catch (Geary.JS.Error err) {
-                    debug("Could not get command stack state: %s", err.message);
-                } finally {
-                    result.unref();
-                }
-            });
-                    result.unref();
+            on_command_stack_changed_message
+        );
         this.user_content_manager.script_message_received[CURSOR_STYLE_CHANGED].connect(
             on_cursor_style_changed_message
         );
@@ -155,6 +146,15 @@ public class ComposerWebView : ClientWebView {
         base.load_html(HTML_BODY.printf(html));
     }
 
+    /**
+     * Sets whether the editor is in rich text or plain text mode.
+     */
+    public void set_rich_text(bool enabled) {
+        this.is_rich_text = enabled;
+        this.run_javascript.begin(
+            "geary.setRichText(%s);".printf(enabled ? "true" : "false"), null
+        );
+    }
 
     /**
      * Undoes the last edit operation.
@@ -266,37 +266,6 @@ public class ComposerWebView : ClientWebView {
     }
 
     /**
-     * Sets whether the editor is in rich text or plain text mode.
-     */
-    public void set_rich_text(bool enabled) {
-        this.is_rich_text = enabled;
-        this.run_javascript.begin(
-            "geary.setRichText(%s);".printf(enabled ? "true" : "false"), null
-        );
-    }
-
-    /**
-     * ???
-     */
-    public void linkify_document() {
-        // XXX
-    }
-
-    /**
-     * ???
-     */
-    public string get_block_quote_representation() {
-        return ""; // XXX
-    }
-
-    /**
-     * ???
-     */
-    public void undo_blockquote_style() {
-        this.run_javascript.begin("geary.undoBlockquoteStyle();", null);
-    }
-
-    /**
      * Returns the editor content as an HTML string.
      */
     public async string? get_html() throws Error {
@@ -383,11 +352,43 @@ public class ComposerWebView : ClientWebView {
     /**
      * ???
      */
+    public void undo_blockquote_style() {
+        this.run_javascript.begin("geary.undoBlockquoteStyle();", null);
+    }
+
+    /**
+     * ???
+     */
+    public void linkify_document() {
+        // XXX
+    }
+
+    /**
+     * ???
+     */
+    public string get_block_quote_representation() {
+        return ""; // XXX
+    }
+
+    /**
+     * ???
+     */
     public bool handle_key_press(Gdk.EventKey event) {
         // XXX
         return false;
     }
 
+    private void on_command_stack_changed_message(WebKit.JavascriptResult result) {
+        try {
+            string[] values = WebKitUtil.to_string(result).split(",");
+            command_stack_changed(values[0] == "true", values[1] == "true");
+        } catch (Geary.JS.Error err) {
+            debug("Could not get command stack state: %s", err.message);
+        } finally {
+            result.unref();
+        }
+    }
+
     private void on_cursor_style_changed_message(WebKit.JavascriptResult result) {
         try {
             string[] values = WebKitUtil.to_string(result).split(",");
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 64b76ec..7361fa1 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -472,14 +472,15 @@ public class ComposerWidget : Gtk.EventBox {
         this.cc_entry.changed.connect(validate_send_button);
         this.bcc_entry.changed.connect(validate_send_button);
         this.reply_to_entry.changed.connect(validate_send_button);
-        this.editor.context_menu.connect(on_context_menu);
+
         this.editor.command_stack_changed.connect(on_command_state_changed);
+        this.editor.context_menu.connect(on_context_menu);
+        this.editor.cursor_style_changed.connect(on_cursor_style_changed);
+        this.editor.get_editor_state().notify["typing-attributes"].connect(on_typing_attributes_changed);
+        this.editor.key_press_event.connect(on_editor_key_press);
         this.editor.load_changed.connect(on_load_changed);
         this.editor.mouse_target_changed.connect(on_mouse_target_changed);
-        this.editor.get_editor_state().notify["typing-attributes"].connect(on_typing_attributes_changed);
         this.editor.selection_changed.connect(on_selection_changed);
-        this.editor.cursor_style_changed.connect(on_cursor_style_changed);
-        this.editor.key_press_event.connect(on_editor_key_press);
         //this.editor.user_changed_contents.connect(reset_draft_timer);
 
         this.editor.load_html(this.body_html, this.signature_html, this.top_posting);
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index 09a4ac5..c5590cd 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -497,6 +497,7 @@ public class ConversationMessage : Gtk.Grid {
                 }
             }
 
+            // XXX WK2
             //webkit_found += this.web_view.mark_text_matches(raw_match, false, 0);
             this.web_view.get_find_controller().search(
                 raw_match,
diff --git a/src/client/web-process/util-webkit.vala b/src/client/web-process/util-webkit.vala
index 8d0aedd..1f2c923 100644
--- a/src/client/web-process/util-webkit.vala
+++ b/src/client/web-process/util-webkit.vala
@@ -205,38 +205,5 @@ namespace Util.DOM {
         return output.replace(" \01 ", "&lt;").replace(" \02 ", "&gt;");
     }
 
-    public string decorate_quotes(string text) throws Error {
-        int level = 0;
-        string outtext = "";
-        Regex quote_leader = new Regex("^(&gt;)* ?");  // Some &gt; followed by optional space
-
-        foreach (string line in text.split("\n")) {
-            MatchInfo match_info;
-            if (quote_leader.match_all(line, 0, out match_info)) {
-                int start, end, new_level;
-                match_info.fetch_pos(0, out start, out end);
-                new_level = end / 4;  // Cast to int removes 0.25 from space at end, if present
-                while (new_level > level) {
-                    outtext += "<blockquote>";
-                    level += 1;
-                }
-                while (new_level < level) {
-                    outtext += "</blockquote>";
-                    level -= 1;
-                }
-                outtext += line.substring(end);
-            } else {
-                debug("This line didn't match the quote regex: %s", line);
-                outtext += line;
-            }
-        }
-        // Close any remaining blockquotes.
-        while (level > 0) {
-            outtext += "</blockquote>";
-            level -= 1;
-        }
-        return outtext;
-    }
-
 }
 


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