[polari/wip/kunaaljain/squashed-branch: 2/2] Merging result work
- From: Kunal Jain <kunaljain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/kunaaljain/squashed-branch: 2/2] Merging result work
- Date: Fri, 26 Aug 2016 16:32:19 +0000 (UTC)
commit 72bbae0afbbd5b72f8f3c90c3b0794d75271a380
Author: Kunaal Jain <kunaalus gmail com>
Date: Sat Aug 6 23:40:48 2016 +0530
Merging result work
src/application.js | 2 +-
src/resultList.js | 23 ++++++-
src/resultStack.js | 21 +++---
src/resultView.js | 183 ++++++++++++++++++++++++++++++++++++++++++----------
4 files changed, 181 insertions(+), 48 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 9f32786..c41e439 100644
--- a/src/resultList.js
+++ b/src/resultList.js
@@ -88,6 +88,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));
@@ -103,7 +104,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();
},
@@ -214,6 +215,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;
}
@@ -226,9 +236,10 @@ const ResultList = new Lang.Class({
this.add(row);
}
+ // Select first result
if(events.length > 0) {
let row = this._widgetMap[events[0].id];
- this.select_row(row);
+ // this.select_row(row);
}
this._showList();
@@ -243,6 +254,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 7bc01f3..22be3ef 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,10 @@ const ResultView = new Lang.Class({
this._pendingLogs = [];
this._logWalker = null;
+ this._channelName = channel;
+ this._resultsAvailable = [];
+ this._seenMessages = {};
+
this._createTags();
this.connect('style-updated',
@@ -194,10 +198,90 @@ 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);
+ buffer.delete_mark(lastMark);
+ }
+ // if(!exists)
+
+ if(!exists) {
+ let tags = [this._lookupTag('separator')];
+ this._insertWithTags(iter,'\n',tags);
+ buffer.create_mark('view-start' + rank, iter, true);
+ 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);
+
+ let rankTag = new Gtk.TextTag({ name: 'result'+rank, invisible: true });
+ this._view.get_buffer().get_tag_table().add(rankTag);
+ }
+
+ if(found && !exists) {
+ iter.backward_line();
+ buffer.create_mark('view-end' + this._resultsAvailable[startIndex].rank, iter, false);
+ }
+ // buffer.insert(iter, String(rank), -1);
+ // buffer.insert(iter, '\n', -1);
+ // if(exists)
+ // buffer.move_mark_by_name('view-end'+rank, iter);
+ // else
+ if(!exists)
+ buffer.create_mark('view-end' + rank, iter, false);
+
+ let index;
+ for(let i = 0; i < this._resultsAvailable.length; i++) {
+ if(this._resultsAvailable[i].rank == rank) {
+ index = i;
+ // break;
+ rankTag = this._lookupTag('result'+this._resultsAvailable[i].rank);
+ rankTag.invisible = false;
+ } else {
+ rankTag = this._lookupTag('result'+this._resultsAvailable[i].rank);
+ rankTag.invisible = true;
+ }
+ }
+ this._rank = rank;
+ if(!exists) this._rowactivated(uid, this._channelName, timestamp, rank);
+ else {
+ this._startQuery = this._resultsAvailable[index].top_query;
+ this._endQuery = this._resultsAvailable[index].bottom_query;
+ }
},
- _rowactivated: function(uid, channel, timestamp) {
+ _rowactivated: function(uid, channel, timestamp, rank) {
this._uid = uid;
this._cancellable.cancel();
this._cancellable.reset();
@@ -249,11 +333,11 @@ 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);
+ // 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));
+ this._endQuery.run(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady1, rank));
// log("!");
this._startQuery = new LogManager.GenericQuery(this._logManager._connection, 20);
// Mainloop.timeout_add(500, Lang.bind(this,
@@ -261,7 +345,15 @@ const ResultView = new Lang.Class({
// 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, rank));
+ for(let i = 0; i < this._resultsAvailable.length; i++) {
+ if(this._resultsAvailable[i].rank == rank) {
+ index = i;
+ break;
+ }
+ }
+ this._resultsAvailable[index].top_query = this._startQuery;
+ this._resultsAvailable[index].bottom_query = this._endQuery;
//print(this._endQuery.isClosed());
// Mainloop.timeout_add(5000, Lang.bind(this,
@@ -302,7 +394,9 @@ const ResultView = new Lang.Class({
{ name: 'indicator-line',
pixels_above_lines: 24 },
{ name: 'loading',
- justification: Gtk.Justification.CENTER }
+ justification: Gtk.Justification.CENTER },
+ { name: 'separator',
+ invisible: true }
];
tags.forEach(function(tagProps) {
tagTable.add(new Gtk.TextTag(tagProps));
@@ -374,34 +468,34 @@ const ResultView = new Lang.Class({
this.parent();
},
- _onLogEventsReady: function(events) {
- // print(events);
+ _onLogEventsReady: function(events, rank) {
+ print("AA"+rank);
events = events.reverse();
this._hideLoadingIndicator();
this._pendingLogs = events.concat(this._pendingLogs);
- this._insertPendingLogs();
+ this._insertPendingLogs(rank);
this._fetchingBacklog = false;
},
- _onLogEventsReady1: function(events) {
+ _onLogEventsReady1: function(events, rank) {
// print(events);
//events = events.reverse();
this._hideLoadingIndicator1();
this._pendingLogs = events.concat(this._pendingLogs);
- this._insertPendingLogs1();
+ this._insertPendingLogs1(rank);
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(rank) {
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,26 +511,33 @@ 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' + 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,
timestamp: pending[i].timestamp,
messageType: pending[i].messageType,
shouldHighlight: false,
- id: pending[i].id};
+ id: pending[i].id,
+ rank: rank};
this._insertMessage(iter, message, state);
this._setNickStatus(message.nick, Tp.ConnectionPresenceType.OFFLINE);
- if (!iter.is_end() || i < pending.length - 1)
- this._view.buffer.insert(iter, '\n', -1);
+ if (!iter.is_end() || i < pending.length - 1) {
+ let tags = [this._lookupTag('result'+rank)];
+ this._insertWithTags(iter,'\n',tags);
+ }
}
+ // buffer.move_mark_by_name('view-end'+rank, iter);
if (!this._channel)
return;
@@ -454,7 +555,7 @@ const ResultView = new Lang.Class({
}
},
- _insertPendingLogs1: function() {
+ _insertPendingLogs1: function(rank) {
if (this._pendingLogs.length == 0)
return;
@@ -480,19 +581,23 @@ const ResultView = new Lang.Class({
// print(this._pendingLogs);
// print(pending);
let state = { lastNick: null, lastTimestamp: 0 };
- let iter = this._view.buffer.get_end_iter();
+ let buffer = this._view.buffer;
+ let endMark = buffer.get_mark('view-end' + rank);
+ let iter = buffer.get_iter_at_mark(endMark);
for (let i = 0; i < pending.length; i++) {
let message = { nick: pending[i].sender,
text: pending[i].message,
timestamp: pending[i].timestamp,
messageType: pending[i].messageType,
shouldHighlight: false,
- id: pending[i].id};
+ id: pending[i].id,
+ rank: rank};
this._insertMessage(iter, message, state);
this._setNickStatus(message.nick, Tp.ConnectionPresenceType.OFFLINE);
//if (!iter.is_end() || i < pending.length - 1)
- this._view.buffer.insert(iter, '\n', -1);
+ let tags = [this._lookupTag('result'+rank)];
+ this._insertWithTags(iter,'\n',tags);
}
if (!this._channel)
@@ -561,6 +666,7 @@ const ResultView = new Lang.Class({
},
_onScroll: function(w, event) {
+ print("was onscroll" +this.vadjustment.value);
let [hasDir, dir] = event.get_scroll_direction();
if (hasDir && (dir != Gdk.ScrollDirection.UP || dir != Gdk.ScrollDirection.DOWN) )
return Gdk.EVENT_PROPAGATE;
@@ -604,6 +710,7 @@ const ResultView = new Lang.Class({
},
_fetchBacklog: function() {
+ print("was at backlog" + this.vadjustment.value + this._fetchingBacklog);
if (this.vadjustment.value != 0 &&
this.vadjustment.value != this._scrollBottom)
return Gdk.EVENT_PROPAGATE;
@@ -617,13 +724,15 @@ const ResultView = new Lang.Class({
this._showLoadingIndicator();
Mainloop.timeout_add(500, Lang.bind(this,
function() {
- this._startQuery.next(10,this._cancellable,Lang.bind(this, this._onLogEventsReady));
+ this._startQuery.next(10,this._cancellable,Lang.bind(this, this._onLogEventsReady,
this._rank));
}));
} else {
+ // this._fetchingBacklog = false;
+ // return Gdk.EVENT_STOP;
this._showLoadingIndicator1();
Mainloop.timeout_add(500, Lang.bind(this,
function() {
- this._endQuery.next(10,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+ this._endQuery.next(10,this._cancellable,Lang.bind(this, this._onLogEventsReady1,
this._rank));
}));
}
return Gdk.EVENT_STOP;
@@ -706,9 +815,11 @@ const ResultView = new Lang.Class({
let isAction = message.messageType == Tp.ChannelTextMessageType.ACTION;
let needsGap = message.nick != state.lastNick || isAction;
let isCentre = message.id == this._uid;
+ let rank = message.rank;
if (message.timestamp - TIMESTAMP_INTERVAL > state.lastTimestamp) {
let tags = [this._lookupTag('timestamp')];
+ tags.push(this._lookupTag('result'+rank));
if (needsGap)
tags.push(this._lookupTag('gap'));
needsGap = false;
@@ -721,6 +832,7 @@ const ResultView = new Lang.Class({
// this._updateMaxNickChars(message.nick.length);
let tags = [];
+ tags.push(this._lookupTag('result'+rank));
if (isAction) {
message.text = "%s %s".format(message.nick, message.text);
state.lastNick = null;
@@ -730,6 +842,7 @@ const ResultView = new Lang.Class({
} else {
if (state.lastNick != message.nick) {
let tags = [this._lookupTag('nick')];
+ tags.push(this._lookupTag('result'+rank));
let nickTagName = this._getNickTagName(message.nick);
let nickTag = this._lookupTag(nickTagName);
@@ -760,9 +873,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]