[geary/wip/765516-gtk-widget-conversation-viewer: 67/112] Re-enable search highlighting in conversation view.



commit fe35b541fca7f06e90c6214b1238fb77f599d271
Author: Michael James Gratton <mike vee net>
Date:   Sun Jun 19 23:33:46 2016 +1000

    Re-enable search highlighting in conversation view.
    
    * src/client/conversation-viewer/conversation-viewer.vala
      (ConversationViewer::highlight_search_terms, ConversationViewer::on_reset):
      Move webkit-specific code to ConversationMessage, invoke each message view
      in each email view to update its highlighting.
    
    * src/client/conversation-viewer/conversation-email.vala
      (ConversationEmail): Rename conversation_messages to attached_messages,
      make it a RO public property so the viewer can access it, use a private
      shadown property otherwise.
    
    * src/client/conversation-viewer/conversation-email.vala
      (ConversationMessage): Add methods for highlighting/unmarking search
      terms.

 .../conversation-viewer/conversation-email.vala    |   19 +++++++++-----
 .../conversation-viewer/conversation-message.vala  |   27 ++++++++++++++++++++
 .../conversation-viewer/conversation-viewer.vala   |   25 +++++++++++------
 3 files changed, 55 insertions(+), 16 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index f8d0c2f..1ac1a2f 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -60,16 +60,21 @@ public class ConversationEmail : Gtk.Box {
     // Is the message body shown or not?
     public bool is_message_body_visible = false;
 
-    // Widget displaying the email's primary message
+    // View displaying the email's primary message
     public ConversationMessage primary_message { get; private set; }
 
-    // Contacts for the email's account
-    private Geary.ContactStore contact_store;
+    // Views for messages that are attachments
+    public Gee.List<ConversationMessage> attached_messages {
+        owned get { return this._attached_messages.read_only_view; }
+    }
 
-    // Messages that have been attached to this one
-    private Gee.List<ConversationMessage> conversation_messages =
+    // Backing for attached_messages
+    private Gee.List<ConversationMessage> _attached_messages =
         new Gee.LinkedList<ConversationMessage>();
 
+    // Contacts for the email's account
+    private Geary.ContactStore contact_store;
+
     // Attachment ids that have been displayed inline
     private Gee.HashSet<string> inlined_content_ids = new Gee.HashSet<string>();
 
@@ -266,7 +271,7 @@ public class ConversationEmail : Gtk.Box {
             ConversationMessage conversation_message =
                 new ConversationMessage(sub_message, contact_store, false);
             sub_messages_box.pack_start(conversation_message, false, false, 0);
-            this.conversation_messages.add(conversation_message);
+            this._attached_messages.add(conversation_message);
         }
 
         pack_start(primary_message, true, true, 0);
@@ -279,7 +284,7 @@ public class ConversationEmail : Gtk.Box {
             load_cancelled
         );
         yield primary_message.load_message_body(load_cancelled);
-        foreach (ConversationMessage message in conversation_messages) {
+        foreach (ConversationMessage message in this._attached_messages) {
             yield message.load_avatar(
                 GearyApplication.instance.controller.avatar_session,
                 load_cancelled
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index da80c3c..8633066 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -359,6 +359,33 @@ public class ConversationMessage : Gtk.Box {
         web_view.load_string(body_text, "text/html", "UTF8", "");
     }
 
+    public void highlight_search_terms(Gee.Set<string> search_matches) {
+        // XXX Need to highlight subject, sender and recipient matches too
+
+        // Remove existing highlights.
+        web_view.unmark_text_matches();
+
+        // Webkit's highlighting is ... weird.  In order to actually see
+        // all the highlighting you're applying, it seems necessary to
+        // start with the shortest string and work up.  If you don't, it
+        // seems that shorter strings will overwrite longer ones, and
+        // you're left with incomplete highlighting.
+        Gee.ArrayList<string> ordered_matches = new Gee.ArrayList<string>();
+        ordered_matches.add_all(search_matches);
+        ordered_matches.sort((a, b) => a.length - b.length);
+
+        foreach(string match in ordered_matches) {
+            web_view.mark_text_matches(match, false, 0);
+        }
+
+        web_view.set_highlight_text_matches(true);
+    }
+
+    public void unmark_search_terms() {
+        web_view.set_highlight_text_matches(false);
+        web_view.unmark_text_matches();
+    }
+
     private SimpleAction add_action(string name, bool enabled) {
         SimpleAction action = new SimpleAction(name, null);
         action.set_enabled(enabled);
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index 6a21db6..a14ac5c 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -500,9 +500,6 @@ public class ConversationViewer : Gtk.Stack {
         if (query == null)
             return;
 
-        // Remove existing highlights.
-        //web_view.unmark_text_matches();
-
         // List all IDs of emails we're viewing.
         Gee.Collection<Geary.EmailIdentifier> ids = new Gee.ArrayList<Geary.EmailIdentifier>();
         foreach (Geary.Email email in emails)
@@ -552,10 +549,14 @@ public class ConversationViewer : Gtk.Stack {
         ordered_matches.sort((a, b) => a.length - b.length);
 
         if (!cancellable.is_cancelled()) {
-            foreach(string match in ordered_matches)
-                //web_view.mark_text_matches(match, false, 0);
-
-            //web_view.set_highlight_text_matches(true);
+            foreach (Geary.Email email in emails) {
+                ConversationEmail email_view = conversation_email_for_id(email.id);
+                email_view.primary_message
+                    .highlight_search_terms(search_matches);
+                foreach (ConversationMessage message_view in email_view.attached_messages) {
+                    message_view.highlight_search_terms(search_matches);
+                }
+            }
         }
     }
 
@@ -713,9 +714,15 @@ public class ConversationViewer : Gtk.Stack {
 
     // State reset.
     private uint on_reset(uint state, uint event, void *user, Object? object) {
-        //web_view.set_highlight_text_matches(false);
         //web_view.allow_collapsing(true);
-        //web_view.unmark_text_matches();
+
+        foreach (Geary.Email email in emails) {
+            ConversationEmail email_view = conversation_email_for_id(email.id);
+            email_view.primary_message.unmark_search_terms();
+            foreach (ConversationMessage message_view in email_view.attached_messages) {
+                message_view.unmark_search_terms();
+            }
+        }
 
         if (search_folder != null) {
             search_folder = null;


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