[polari/wip/raresv/GSoC: 7/11] chatView: split out _createNickTag() and _onNickTagClicked()
- From: Rares Visalom <raresvisalom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/raresv/GSoC: 7/11] chatView: split out _createNickTag() and _onNickTagClicked()
- Date: Mon, 22 Aug 2016 22:25:33 +0000 (UTC)
commit 09b40e80a5f79be1cd3285984440fb7b43eaf506
Author: raresv <rares visalom gmail com>
Date: Sat Aug 20 19:48:23 2016 +0300
chatView: split out _createNickTag() and _onNickTagClicked()
The code that creates the tag is not complicated or long, but it's
definitely a lot better to split that out into the _createNickTag()
method, as the code is cleaner this way. The _onNickTagClicked()
method is responsible for creating the popover at the right position
upon clicking a nickTag. The popover is created only once for each
nickTag, but it is created on demand, i.e. when the _onNickTagClicked()
is run for the first time.
src/chatView.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 46 insertions(+), 7 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 08f823a..243da46 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -15,6 +15,7 @@ const PasteManager = imports.pasteManager;
const Signals = imports.signals;
const Utils = imports.utils;
const UserTracker = imports.userTracker;
+const UserList = imports.userList;
const MAX_NICK_CHARS = 8;
const IGNORE_STATUS_TIME = 5;
@@ -1159,10 +1160,13 @@ const ChatView = new Lang.Class({
let tags = [this._lookupTag('nick')];
let nickTagName = this._getNickTagName(message.nick);
let nickTag = this._lookupTag(nickTagName);
+ let buffer = this._view.get_buffer();
if (!nickTag) {
- nickTag = this._createNickTag(message.nick);
- this._view.get_buffer().get_tag_table().add(nickTag);
+ nickTag = this._createNickTag(nickTagName);
+ buffer.get_tag_table().add(nickTag);
+
+ this._updateNickTag(nickTag, this._userTracker.getNickStatus(message.nick));
}
tags.push(nickTag);
if (needsGap)
@@ -1215,13 +1219,48 @@ const ChatView = new Lang.Class({
tag.foreground_rgba = this._inactiveNickColor;
},
- _createNickTag: function(nickName) {
- let nickTagName = this._getNickTagName(nickName);
+ _createNickTag: function(name) {
+ let tag = new ButtonTag({ name: name });
+ tag.connect('clicked', Lang.bind(this, this._onNickTagClicked));
+ return tag;
+ },
- let tag = new Gtk.TextTag({ name: nickTagName });
- this._updateNickTag(tag, this._userTracker.getNickStatus(nickName));
+ _onNickTagClicked: function(tag) {
+ let view = this._view;
+ let event = Gtk.get_current_event();
+ let [, eventX, eventY] = event.get_coords();
+ let [x, y] = view.window_to_buffer_coords(Gtk.TextWindowType.WIDGET,
+ eventX, eventY);
+ let [inside, start] = view.get_iter_at_location(x, y);
+ let end = start.copy();
- return tag;
+ if (!start.starts_tag(tag))
+ start.backward_to_tag_toggle(tag);
+
+ if (!end.ends_tag(tag))
+ end.forward_to_tag_toggle(tag);
+
+ let rect1 = view.get_iter_location(start);
+ let rect2 = view.get_iter_location(end);
+
+ [rect1.y, rect1.height] = view.get_line_yrange(start);
+
+ [rect1.x, rect1.y] = view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect1.x, rect1.y);
+ [rect2.x, rect2.y] = view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect2.x, rect2.y);
+ rect1.width = rect2.x - rect1.x;
+
+ //TODO: special chars?
+ let actualNickName = view.get_buffer().get_slice(start, end, false);
+
+ if (!tag._popover)
+ tag._popover = new UserList.UserPopover({ relative_to: this._view,
+ userTracker: this._userTracker,
+ room: this._room });
+
+ tag._popover.nickname = actualNickName;
+
+ tag._popover.pointing_to = rect1;
+ tag._popover.show();
},
_createUrlTag: function(url) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]