[polari] chatView: Sync maxNickChars with nick button



commit 6108cda083cb495e4792316cf7a1c9fe3e10848a
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Jan 20 03:19:03 2016 +0100

    chatView: Sync maxNickChars with nick button
    
    As the entry area now blends in with the chat log, both elements should
    use the same width for nicks to properly align the chat entry with
    messages in the log.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760872

 src/chatView.js  |   30 ++++++++++++++++++++++++++----
 src/entryArea.js |   12 +++++++++---
 src/roomStack.js |    6 ++++++
 3 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 8387b61..09d5377 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -11,6 +11,7 @@ const Tpl = imports.gi.TelepathyLogger;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const Signals = imports.signals;
 const Utils = imports.utils;
 
 const MAX_NICK_CHARS = 8;
@@ -236,6 +237,12 @@ const ChatView = new Lang.Class({
         this._pendingLogs = [];
         this._statusCount = { left: 0, joined: 0, total: 0 };
 
+        this._room.account.connect('notify::nickname', Lang.bind(this,
+            function() {
+                this._updateMaxNickChars(this._room.account.nickname.length);
+            }));
+        this._updateMaxNickChars(this._room.account.nickname.length);
+
         let isRoom = room.type == Tp.HandleType.ROOM;
         let target = new Tpl.Entity({ type: isRoom ? Tpl.EntityType.ROOM
                                                    : Tpl.EntityType.CONTACT,
@@ -493,6 +500,19 @@ const ChatView = new Lang.Class({
         return Object.keys(this._pending).length;
     },
 
+    get maxNickChars() {
+        return this._maxNickChars;
+    },
+
+    _updateMaxNickChars: function(length) {
+        if (length <= this._maxNickChars)
+            return;
+
+        this._maxNickChars = length;
+        this.emit('max-nick-chars-changed');
+        this._updateIndent();
+    },
+
     _updateIndent: function() {
         let context = this._view.get_pango_context();
         let metrics = context.get_metrics(null, null);
@@ -739,6 +759,10 @@ const ChatView = new Lang.Class({
 
         this._channel = this._room.channel;
 
+        let nick = this._channel ? this._channel.connection.self_contact.alias
+                                 : this._room.account.nickname;
+        this._updateMaxNickChars(nick.length);
+
         if (!this._channel)
             return;
 
@@ -1110,10 +1134,7 @@ const ChatView = new Lang.Class({
         }
         state.lastTimestamp = message.timestamp;
 
-        if (message.nick.length > this._maxNickChars) {
-            this._maxNickChars = message.nick.length;
-            this._updateIndent();
-        }
+        this._updateMaxNickChars(message.nick.length);
 
         let tags = [];
         if (isAction) {
@@ -1233,3 +1254,4 @@ const ChatView = new Lang.Class({
             buffer.apply_tag(tags[i], start, iter);
     }
 });
+Signals.addSignalMethods(ChatView.prototype);
diff --git a/src/entryArea.js b/src/entryArea.js
index cc4a869..a8377de 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -68,6 +68,7 @@ const EntryArea = new Lang.Class({
         delete params.room;
 
         this._ircParser = new IrcParser.IrcParser();
+        this._maxNickChars = ChatView.MAX_NICK_CHARS;
 
         this.parent(params);
 
@@ -81,7 +82,7 @@ const EntryArea = new Lang.Class({
             }));
 
         this._nickLabel.set_state_flags(Gtk.StateFlags.LINK, false);
-        this._nickLabel.width_chars = ChatView.MAX_NICK_CHARS
+        this._nickLabel.width_chars = this._maxNickChars;
 
         this._changeButton.connect('clicked', Lang.bind(this,
             function() {
@@ -136,6 +137,11 @@ const EntryArea = new Lang.Class({
         this._chatEntry.connect('unmap', Lang.bind(this, this._updateCompletions));
     },
 
+    set maxNickChars(maxChars) {
+        this._maxNickChars = maxChars;
+        this._updateNick();
+    },
+
     _updateCompletions: function() {
         let nicks = [];
 
@@ -228,7 +234,7 @@ const EntryArea = new Lang.Class({
 
 
     _setNick: function(nick) {
-        this._nickLabel.width_chars = Math.max(nick.length, ChatView.MAX_NICK_CHARS);
+        this._nickLabel.width_chars = Math.max(nick.length, this._maxNickChars);
         this._nickLabel.label = nick;
 
         let account = this._room.account;
@@ -264,7 +270,7 @@ const EntryArea = new Lang.Class({
         let nick = channel ? channel.connection.self_contact.alias
                            : this._room ? this._room.account.nickname : '';
 
-        this._nickLabel.width_chars = Math.max(nick.length, ChatView.MAX_NICK_CHARS);
+        this._nickLabel.width_chars = Math.max(nick.length, this._maxNickChars);
         this._nickLabel.label = nick;
 
         if (!this._nickEntry.is_focus)
diff --git a/src/roomStack.js b/src/roomStack.js
index 446b76a..f452824 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -6,6 +6,7 @@ const ChatroomManager = imports.chatroomManager;
 const ChatView = imports.chatView;
 const EntryArea = imports.entryArea;
 const Lang = imports.lang;
+const Signals = imports.signals;
 
 const RoomStack = new Lang.Class({
     Name: 'RoomStack',
@@ -125,6 +126,7 @@ const ChatPlaceholder = new Lang.Class({
         }
     },
 });
+Signals.addSignalMethods(ChatPlaceholder.prototype);
 
 const RoomView = new Lang.Class({
     Name: 'RoomView',
@@ -132,6 +134,10 @@ const RoomView = new Lang.Class({
     _init: function(room) {
         this._view = room ? new ChatView.ChatView(room)
                           : new ChatPlaceholder();
+        this._view.connect('max-nick-chars-changed', Lang.bind(this,
+            function() {
+                this.inputWidget.maxNickChars = this._view.maxNickChars;
+            }));
 
         this.widget = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
         this.widget.add(this._view.widget);


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