[polari/wip/fmuellner/combined-gsoc: 38/137] highlighting + scrolling



commit b71f5e9dac7d4caa52f7a8166494a41321c06c6d
Author: Kunaal Jain <kunaalus gmail com>
Date:   Tue Jul 19 12:46:43 2016 +0530

    highlighting + scrolling

 src/application.js |    2 +-
 src/resultList.js  |    4 ++-
 src/resultStack.js |    8 +++---
 src/resultView.js  |   59 ++++++++++++++++++++++++++++++++++++---------------
 4 files changed, 49 insertions(+), 24 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 9d19de7..4d7fea3 100644
--- a/src/application.js
+++ b/src/application.js
@@ -120,7 +120,7 @@ const Application = new Lang.Class({
             parameter_type: GLib.VariantType.new('s'),
             state: GLib.Variant.new('s', '') },
           { name: 'active-result-changed',
-            parameter_type: GLib.VariantType.new('(sus)') }
+            parameter_type: GLib.VariantType.new('(suss)') }
         ];
         actionEntries.forEach(Lang.bind(this,
             function(actionEntry) {
diff --git a/src/resultList.js b/src/resultList.js
index 3a9d7ab..fbd35dd 100644
--- a/src/resultList.js
+++ b/src/resultList.js
@@ -167,13 +167,14 @@ const ResultList = new Lang.Class({
                           this._handleSearchChanged));
 
         this._keywords = [];
+        this._keywordsText = '';
         this._cancellable  = new Gio.Cancellable();
     },
 
     vfunc_row_selected: function(row) {
         if(!row) return;
         let rowSelectedAction = this._app.lookup_action('active-result-changed');
-        rowSelectedAction.activate(new GLib.Variant('(sus)', [row.uid, row.timestamp, row.channel]));
+        rowSelectedAction.activate(new GLib.Variant('(suss)', [row.uid, row.timestamp, row.channel, 
this._keywordsText]));
         // if (row)
         //     row.selected();
     },
@@ -186,6 +187,7 @@ const ResultList = new Lang.Class({
         this._cancellable.cancel();
         this._cancellable.reset();
 
+        this._keywordsText = text;
         this._keywords = text == '' ? [] : text.split(/\s+/);
         log(text);
         let query = ('select ?text as ?mms ?msg as ?id ?chan as ?chan ?timestamp as ?timestamp ' +
diff --git a/src/resultStack.js b/src/resultStack.js
index 3caff88..8727b33 100644
--- a/src/resultStack.js
+++ b/src/resultStack.js
@@ -29,8 +29,8 @@ const ResultStack = new Lang.Class({
         this.add_named(view, id);
     },
 
-    _resultAdded: function(uid, timestamp, channel) {
-        this._addView(uid, new ResultView.ResultView(uid, timestamp, channel));
+    _resultAdded: function(uid, timestamp, channel, keywords) {
+        this._addView(uid, new ResultView.ResultView(uid, timestamp, channel, keywords));
     },
 
     _resultRemoved: function(row) {
@@ -39,10 +39,10 @@ const ResultStack = new Lang.Class({
     },
 
     _activeResultChanged: function(action, parameter) {
-        let [uid, timestamp, channel] = parameter.deep_unpack();
+        let [uid, timestamp, channel, keywords] = parameter.deep_unpack();
         print(uid);
         if(!this._results[uid])
-            this._resultAdded(uid, timestamp, channel);
+            this._resultAdded(uid, timestamp, channel, keywords);
         this.set_visible_child_name(uid);
     }
 });
diff --git a/src/resultView.js b/src/resultView.js
index a1ae504..e5768f8 100644
--- a/src/resultView.js
+++ b/src/resultView.js
@@ -139,7 +139,7 @@ const ResultView = new Lang.Class({
     Name: 'ResultView',
     Extends: Gtk.ScrolledWindow,
 
-    _init: function(uid, timestamp, channel) {
+    _init: function(uid, timestamp, channel, keywordsText) {
         //this.parent();
         print("HELLO");
         this.parent({ hscrollbar_policy: Gtk.PolicyType.NEVER, vexpand: true });
@@ -156,6 +156,9 @@ const ResultView = new Lang.Class({
         this._logManager = LogManager.getDefault();
         this._cancellable  = new Gio.Cancellable();
 
+        this._keywords = keywordsText == '' ? [] : keywordsText.split(/\s+/);
+        this._keyregExp = new RegExp( '(' + this._keywords.join('|')+ ')', 'gi');
+        print(this._keyregExp);
         this._active = false;
         this._toplevelFocus = false;
         this._fetchingBacklog = false;
@@ -191,14 +194,16 @@ const ResultView = new Lang.Class({
         this._scrollBottom = adj.upper - adj.page_size;
 
         this._hoverCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1);
-        this._rowactivated(channel, timestamp);
+        this._rowactivated(uid, channel, timestamp);
     },
 
-    _rowactivated: function(channel, timestamp) {
+    _rowactivated: function(uid, channel, timestamp) {
+        this._uid = uid;
         this._cancellable.cancel();
         this._cancellable.reset();
         let sparql = (
             'select nie:plainTextContent(?msg) as ?message ' +
+            '?msg as ?id ' +
             '       if (nmo:from(?msg) = nco:default-contact-me,' +
             '           "%s", nco:nickname(nmo:from(?msg))) as ?sender ' +
             // FIXME: how do we handle the "real" message type?
@@ -218,6 +223,7 @@ const ResultView = new Lang.Class({
         log(sparql);
         let sparql1 = (
             'select nie:plainTextContent(?msg) as ?message ' +
+            '?msg as ?id ' +
             '       if (nmo:from(?msg) = nco:default-contact-me,' +
             '           "%s", nco:nickname(nmo:from(?msg))) as ?sender ' +
             // FIXME: how do we handle the "real" message type?
@@ -385,6 +391,9 @@ const ResultView = new Lang.Class({
 
         this._pendingLogs = events.concat(this._pendingLogs);
         this._insertPendingLogs1();
+        let buffer = this._view.get_buffer();
+        let mark = buffer.get_mark('centre');
+        this._view.scroll_to_mark(mark, 0.0, true, 0, 0.5);
         this._fetchingBacklog = false;
     },
 
@@ -420,7 +429,8 @@ const ResultView = new Lang.Class({
                             text: pending[i].message,
                             timestamp: pending[i].timestamp,
                             messageType: pending[i].messageType,
-                            shouldHighlight: false };
+                            shouldHighlight: false,
+                            id: pending[i].id};
             this._insertMessage(iter, message, state);
             this._setNickStatus(message.nick, Tp.ConnectionPresenceType.OFFLINE);
 
@@ -476,7 +486,8 @@ const ResultView = new Lang.Class({
                             text: pending[i].message,
                             timestamp: pending[i].timestamp,
                             messageType: pending[i].messageType,
-                            shouldHighlight: false };
+                            shouldHighlight: false,
+                            id: pending[i].id};
             this._insertMessage(iter, message, state);
             this._setNickStatus(message.nick, Tp.ConnectionPresenceType.OFFLINE);
 
@@ -745,6 +756,8 @@ const ResultView = new Lang.Class({
     _insertMessage: function(iter, message, state) {
         let isAction = message.messageType == Tp.ChannelTextMessageType.ACTION;
         let needsGap = message.nick != state.lastNick || isAction;
+        print(message.id == this._uid);
+        let isCentre = message.id == this._uid;
 
         if (message.timestamp - TIMESTAMP_INTERVAL > state.lastTimestamp) {
             let tags = [this._lookupTag('timestamp')];
@@ -788,26 +801,36 @@ const ResultView = new Lang.Class({
         if (message.shouldHighlight)
             tags.push(this._lookupTag('highlight'));
 
+        if (isCentre) {
+            let buffer = this._view.get_buffer();
+            buffer.create_mark('centre', iter, true);
+        }
+
+
         // let params = this._room.account.dup_parameters_vardict().deep_unpack();
         // let server = params.server.deep_unpack();
 
         let text = message.text;
+        let res = [], match;
+        while ((match = this._keyregExp.exec(text))){
+            res.push({ keyword: match[0], pos: match.index});
+        }
         // let channels = Utils.findChannels(text, server);
         // let urls = Utils.findUrls(text).concat(channels).sort((u1,u2) => u1.pos - u2.pos);
         let pos = 0;
-        // for (let i = 0; i < urls.length; i++) {
-        //     let url = urls[i];
-        //     this._insertWithTags(iter, text.substr(pos, url.pos - pos), tags);
-        //
-        //     let tag = this._createUrlTag(url.url);
-        //     this._view.get_buffer().tag_table.add(tag);
-        //
-        //     let name = url.name ? url.name : url.url;
-        //     this._insertWithTags(iter, name,
-        //                          tags.concat(this._lookupTag('url'), tag));
-        //
-        //     pos = url.pos + name.length;
-        // }
+         for (let i = 0; i < res.length; i++) {
+            let cur = res[i];
+            this._insertWithTags(iter, text.substr(pos, cur.pos - pos), tags);
+
+            // let tag = this._createUrlTag(url.url);
+            // this._view.get_buffer().tag_table.add(tag);
+
+            // let name = url.name ? url.name : url.url;
+            this._insertWithTags(iter, cur.keyword,
+                                 tags.concat(this._lookupTag('highlight')));
+
+            pos = cur.pos + cur.keyword.length;
+        }
         this._insertWithTags(iter, text.substr(pos), tags);
     },
 


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