[polari/wip/kunaljain/polari-search-merge-results] resultView: Implement start/end buffer marks



commit 66c188e464a70b1a97a51db46556cd72e69bb7d5
Author: Kunaal Jain <kunaalus gmail com>
Date:   Sat Aug 6 23:40:48 2016 +0530

    resultView: Implement start/end buffer marks

 src/application.js |    2 +-
 src/resultList.js  |   20 ++++++++-
 src/resultStack.js |   21 +++++----
 src/resultView.js  |  119 ++++++++++++++++++++++++++++++++++++++++------------
 4 files changed, 123 insertions(+), 39 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 2608c00..a639598 100644
--- a/src/application.js
+++ b/src/application.js
@@ -122,7 +122,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('(suss)') }
+            parameter_type: GLib.VariantType.new('(sussu)') }
         ];
         actionEntries.forEach(Lang.bind(this,
             function(actionEntry) {
diff --git a/src/resultList.js b/src/resultList.js
index f5bd462..0e4121d 100644
--- a/src/resultList.js
+++ b/src/resultList.js
@@ -166,6 +166,7 @@ const ResultList = new Lang.Class({
         //this.connect('row-activated', Lang.bind(this, this._rowactivated));
         this._results = [];
         this._widgetMap = {};
+        this._channelMap = {};
         //this._keywordsAction = app.lookup_action('search-terms');
         this._app.connect('action-state-changed::search-terms', Lang.bind(this,
                           this._handleSearchChanged));
@@ -181,7 +182,7 @@ const ResultList = new Lang.Class({
     vfunc_row_selected: function(row) {
         if(!row) return;
         let rowSelectedAction = this._app.lookup_action('active-result-changed');
-        rowSelectedAction.activate(new GLib.Variant('(suss)', [row.uid, row.timestamp, row.channel, 
this._keywordsText]));
+        rowSelectedAction.activate(new GLib.Variant('(sussu)', [row.uid, row.timestamp, row.channel, 
this._keywordsText, row.rank]));
         // if (row)
         //     row.selected();
     },
@@ -292,6 +293,15 @@ const ResultList = new Lang.Class({
                 row = new ResultRow(events[i]);
                 widgetMap[uid] = row;
             }
+            print(events[i].chan);
+            print(this._channelMap[events[i].chan]);
+            if( this._channelMap[events[i].chan] != null ) {
+                print("XXXXXXXXX");
+                this._channelMap[events[i].chan]++;
+            } else {
+                this._channelMap[events[i].chan] = 0;
+            }
+            row.rank = this._channelMap[events[i].chan];
             row._content_label.label = message;
         }
 
@@ -321,6 +331,14 @@ const ResultList = new Lang.Class({
             let row;
             row = new ResultRow(events[i]);
             this._widgetMap[uid] = row;
+
+            if( this._channelMap[events[i].chan] ) {
+                this._channelMap[events[i].chan]++;
+            } else {
+                this._channelMap[events[i].chan] = 0;
+            }
+            row.rank = this._channelMap[events[i].chan];
+
             row._content_label.label = message;
             this.add(row);
         }
diff --git a/src/resultStack.js b/src/resultStack.js
index 8727b33..f944131 100644
--- a/src/resultStack.js
+++ b/src/resultStack.js
@@ -24,13 +24,13 @@ const ResultStack = new Lang.Class({
 
     },
 
-    _addView: function(id, view) {
-        this._results[id] = view;
-        this.add_named(view, id);
+    _addView: function(channel, view) {
+        this._results[channel] = view;
+        this.add_named(view, channel);
     },
 
-    _resultAdded: function(uid, timestamp, channel, keywords) {
-        this._addView(uid, new ResultView.ResultView(uid, timestamp, channel, keywords));
+    _resultAdded: function(channel) {
+        this._addView(channel, new ResultView.ResultView(channel));
     },
 
     _resultRemoved: function(row) {
@@ -39,10 +39,11 @@ const ResultStack = new Lang.Class({
     },
 
     _activeResultChanged: function(action, parameter) {
-        let [uid, timestamp, channel, keywords] = parameter.deep_unpack();
-        print(uid);
-        if(!this._results[uid])
-            this._resultAdded(uid, timestamp, channel, keywords);
-        this.set_visible_child_name(uid);
+        let [uid, timestamp, channel, keywords, rank] = parameter.deep_unpack();
+        print(channel);
+        if(!this._results[channel])
+            this._resultAdded(channel);
+        this._results[channel]._insertView(uid, timestamp, rank);
+        this.set_visible_child_name(channel);
     }
 });
diff --git a/src/resultView.js b/src/resultView.js
index e74e880..cc96270 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, keywordsText) {
+    _init: function(channel) {
         //this.parent();
         print("HELLO");
         this.parent({ hscrollbar_policy: Gtk.PolicyType.NEVER, vexpand: true });
@@ -156,9 +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._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;
@@ -169,6 +169,9 @@ const ResultView = new Lang.Class({
         this._pendingLogs = [];
         this._logWalker = null;
 
+        this._channelName = channel;
+        this._resultsAvailable = [];
+
         this._createTags();
 
         this.connect('style-updated',
@@ -194,10 +197,68 @@ const ResultView = new Lang.Class({
         this._scrollBottom = adj.upper - adj.page_size;
 
         this._hoverCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1);
-        this._rowactivated(uid, channel, timestamp);
+        // this._rowactivated(uid, channel, timestamp);
+    },
+
+    _insertView: function(uid, timestamp, rank) {
+        let found = false;
+        let exists = false;
+        let startIndex = 0;
+        print(this._resultsAvailable.length);
+        for(let i = 0; i < this._resultsAvailable.length; i++) {
+            print(this._resultsAvailable[i].rank);
+            print(rank);
+            if(this._resultsAvailable[i].rank > rank) {
+                found = true;
+                startIndex = i;
+            } else if(this._resultsAvailable[i].rank == rank) {
+                exists = true;
+                startIndex = i;
+            }
+        }
+
+        print(startIndex);
+
+        let buffer = this._view.buffer;
+        let iter = buffer.get_start_iter();
+        if(exists) {
+            let lastMark = buffer.get_mark('view-start' + this._resultsAvailable[startIndex].rank);
+            iter = buffer.get_iter_at_mark(lastMark);
+        } else if(found) {
+            let lastMark = buffer.get_mark('view-end' + this._resultsAvailable[startIndex].rank);
+            iter = buffer.get_iter_at_mark(lastMark);
+        }
+        // if(!exists)
+
+        if(!exists) {
+            buffer.create_mark('view-start' + rank, iter, false);
+            let obj = { top_query: null,
+                        bottom_query: null,
+                        rank: rank };
+            // print(this._resultsAvailable.push(obj));
+            // print(this._resultsAvailable.toString());
+            // print(this._resultsAvailable.splice(startIndex, 0, obj).toString());
+            this._resultsAvailable.splice(startIndex + 1, 0, obj);
+            print(this._resultsAvailable.length);
+        }
+        // buffer.insert(iter, String(rank), -1);
+        // buffer.insert(iter, '\n', -1);
+        if(exists)
+            buffer.move_mark_by_name('view-end'+rank, iter);
+        else
+            buffer.create_mark('view-end' + rank, iter, true);
+
+        let index;
+        for(let i = 0; i < this._resultsAvailable.length; i++) {
+            if(this._resultsAvailable[i].rank == rank) {
+                index = i;
+                break;
+            }
+        }
+        this._rowactivated(uid, this._channelName, timestamp, index);
     },
 
-    _rowactivated: function(uid, channel, timestamp) {
+    _rowactivated: function(uid, channel, timestamp, index) {
         this._uid = uid;
         this._cancellable.cancel();
         this._cancellable.reset();
@@ -249,19 +310,19 @@ const ResultView = new Lang.Class({
         //                           Lang.bind(this, this._onLogEventsReady));
         // this._logManager.query(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady));
         // this._logManager.query(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
-        let buffer = this._view.get_buffer();
-        let iter = buffer.get_end_iter();
-        buffer.set_text("",-1);
-        this._endQuery = new LogManager.GenericQuery(this._logManager._connection, 20);
-        this._endQuery.run(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+        // let buffer = this._view.get_buffer();
+        // let iter = buffer.get_end_iter();
+        // buffer.set_text("",-1);
+        this._endQuery = new LogManager.GenericQuery(this._logManager._connection, 2);
+        // this._endQuery.run(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady1, index));
         // log("!");
-        this._startQuery = new LogManager.GenericQuery(this._logManager._connection, 20);
+        this._startQuery = new LogManager.GenericQuery(this._logManager._connection, 2);
         // Mainloop.timeout_add(500, Lang.bind(this,
         //     function() {
         //         query.run(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
         //         return GLib.SOURCE_REMOVE;
         //     }));
-        this._startQuery.run(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady));
+        this._startQuery.run(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady, index));
         //print(this._endQuery.isClosed());
 
         // Mainloop.timeout_add(5000, Lang.bind(this,
@@ -374,34 +435,34 @@ const ResultView = new Lang.Class({
         this.parent();
     },
 
-    _onLogEventsReady: function(events) {
-        // print(events);
+    _onLogEventsReady: function(events, index) {
+        print("AA"+index);
         events = events.reverse();
         this._hideLoadingIndicator();
 
         this._pendingLogs = events.concat(this._pendingLogs);
-        this._insertPendingLogs();
+        this._insertPendingLogs(index);
         this._fetchingBacklog = false;
     },
 
-    _onLogEventsReady1: function(events) {
+    _onLogEventsReady1: function(events, parent, index) {
         // print(events);
         //events = events.reverse();
         this._hideLoadingIndicator1();
 
         this._pendingLogs = events.concat(this._pendingLogs);
-        this._insertPendingLogs1();
+        this._insertPendingLogs1(index);
         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;
     },
 
-    _insertPendingLogs: function() {
+    _insertPendingLogs: function(index) {
         if (this._pendingLogs.length == 0)
             return;
 
-        let index = -1;
+        // let index = -1;
         let nick = this._pendingLogs[0].sender;
         let type = this._pendingLogs[0].messageType;
     /*    if (!this._query.isClosed()) {
@@ -417,13 +478,16 @@ const ResultView = new Lang.Class({
 
         if (index < 0)
             return;*/
-            index = 0;
+            // index = 0;
         // print(this._pendingLogs);
-        let pending = this._pendingLogs.splice(index);
+        let pending = this._pendingLogs.splice(0);
         // print(this._pendingLogs);
-        print(pending);
+        // print(pending);
+        let buffer = this._view.buffer;
+        let startMark = buffer.get_mark('view-start' + this._resultsAvailable[index].rank);
+        let iter = buffer.get_iter_at_mark(startMark);
         let state = { lastNick: null, lastTimestamp: 0 };
-        let iter = this._view.buffer.get_start_iter();
+        // let iter = this._view.buffer.get_start_iter();
         for (let i = 0; i < pending.length; i++) {
             let message = { nick: pending[i].sender,
                             text: pending[i].message,
@@ -437,6 +501,7 @@ const ResultView = new Lang.Class({
             if (!iter.is_end() || i < pending.length - 1)
                 this._view.buffer.insert(iter, '\n', -1);
         }
+        buffer.move_mark_by_name('view-end'+this._resultsAvailable[index].rank, iter);
 
         if (!this._channel)
             return;
@@ -839,9 +904,9 @@ const ResultView = new Lang.Class({
 
         let text = message.text;
         let res = [], match;
-        while ((match = this._keyregExp.exec(text))){
-            res.push({ keyword: match[0], pos: match.index});
-        }
+        // 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;


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