[polari/wip/fmuellner/singleton-nick-popover: 2/2] entryArea: Share a single NickPopover



commit 7d6fc96ba5ce87615f0396e57396174dd65374c0
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Nov 3 23:34:34 2017 +0100

    entryArea: Share a single NickPopover
    
    As outlined in the previous commit, there is no real need for
    keeping hidden popovers for every room around all the time.
    Just share a single popover between all entryAreas to cut down
    on the number of widgets (and the resulting overhead of GTK+
    updating their state etc.).

 src/entryArea.js | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/src/entryArea.js b/src/entryArea.js
index e0e6ec6..ae91250 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -20,6 +20,7 @@ const MAX_LINES = 5;
 
 let _checker = null;
 let _emojiPicker = null;
+let _nickPopover = null;
 
 var ChatEntry = GObject.registerClass({
     Implements: [PasteManager.DropTargetIface],
@@ -205,6 +206,7 @@ var EntryArea = GObject.registerClass({
 
         this._ircParser = new IrcParser.IrcParser(this._room);
         this._maxNickChars = ChatView.MAX_NICK_CHARS;
+        this._nickChangedId = 0;
 
         super._init(params);
 
@@ -215,6 +217,25 @@ var EntryArea = GObject.registerClass({
             this._keyPressId = this._toplevel.connect('key-press-event',
                                                       Lang.bind(this, this._onKeyPressEvent));
         });
+        this.connect('map', () => {
+            if (!_nickPopover)
+                _nickPopover = new NickPopover();
+            this._nickButton.popover = _nickPopover;
+
+            if (this._nickChangedId)
+                return;
+
+            this._nickChangedId = _nickPopover.connect('nick-changed', () => {
+                this._setNick(_nickPopover.nick);
+                this._nickButton.active = false;
+            });
+            this._updateNick();
+        });
+        this.connect('unmap', () => {
+            if (this._nickChangedId)
+                _nickPopover.disconnect(this._nickChangedId);
+            this._nickChangedId = 0;
+        });
 
         this._nickLabel.set_state_flags(Gtk.StateFlags.LINK, false);
         this._nickLabel.width_chars = this._maxNickChars;
@@ -230,13 +251,6 @@ var EntryArea = GObject.registerClass({
             w.set_state_flags (state, true);
         });
 
-        this._nickPopover = new NickPopover();
-        this._nickPopover.connect('nick-changed', () => {
-            this._setNick(this._nickPopover.nick);
-            this._nickButton.active = false;
-        });
-        this._nickButton.popover = this._nickPopover;
-
         this._chatEntry.connect('text-pasted', (entry, text, nLines) => {
             this.pasteText(text, nLines);
         });
@@ -465,6 +479,9 @@ var EntryArea = GObject.registerClass({
         this._nickLabel.width_chars = Math.max(nick.length, this._maxNickChars);
         this._nickLabel.label = nick;
 
+        if (!this.get_mapped())
+            return;
+
         let app = Gio.Application.get_default();
         app.setAccountNick(this._room.account, nick);
 
@@ -490,7 +507,8 @@ var EntryArea = GObject.registerClass({
         this._nickLabel.width_chars = Math.max(nick.length, this._maxNickChars);
         this._nickLabel.label = nick;
 
-        this._nickPopover.nick = nick;
+        if (this.get_mapped())
+            _nickPopover.nick = nick;
     }
 
     _onDestroy() {
@@ -509,5 +527,8 @@ var EntryArea = GObject.registerClass({
         if (this._keyPressId)
             this._toplevel.disconnect(this._keyPressId);
         this._keyPressId = 0;
+        if (this._nickChangedId)
+            _nickPopover.disconnect(this._nickChangedId);
+        this._nickChangedId = 0;
     }
 });


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