From 38217bcdc2b91519516afab576ed34f80dd5b5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 3 Nov 2017 22:40:43 +0100 Subject: [PATCH 1/2] entryArea: Split out NickPopover The popover for changing the nick is currently handled entirely as part of the entryArea, which means we have to keep one popover for every room around, even though they don't carry any room-specific state and we never show more than one at any given time. Splitting out the NickPopover decouples it from the entryArea, which will allow us to share a single one in the future. --- data/org.gnome.Polari.data.gresource.xml | 1 + data/resources/entry-area.ui | 40 --------------- data/resources/nick-popover.ui | 42 ++++++++++++++++ src/entryArea.js | 62 ++++++++++++++++++++---- 4 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 data/resources/nick-popover.ui diff --git a/data/org.gnome.Polari.data.gresource.xml b/data/org.gnome.Polari.data.gresource.xml index 0b43fbec..dd19367f 100644 --- a/data/org.gnome.Polari.data.gresource.xml +++ b/data/org.gnome.Polari.data.gresource.xml @@ -12,6 +12,7 @@ resources/entry-area.ui resources/join-room-dialog.ui resources/main-window.ui + resources/nick-popover.ui resources/room-list-header.ui resources/room-list-row.ui resources/server-room-list.ui diff --git a/data/resources/entry-area.ui b/data/resources/entry-area.ui index 9de1d438..ed57aaea 100644 --- a/data/resources/entry-area.ui +++ b/data/resources/entry-area.ui @@ -1,44 +1,5 @@ - - top - - - True - 6 - vertical - 6 - - - True - start - True - Change nickname: - - - - - True - True - - - - - _Change - True - True - True - end - True - True - - - - - - + diff --git a/src/entryArea.js b/src/entryArea.js index 2ffd30a7..e0e6ec6d 100644 --- a/src/entryArea.js +++ b/src/entryArea.js @@ -135,14 +135,57 @@ var ChatEntry = GObject.registerClass({ } }); +var NickPopover = GObject.registerClass({ + Template: 'resource:///org/gnome/Polari/ui/nick-popover.ui', + InternalChildren: ['nickEntry', + 'changeButton'], + Properties: { + nick: GObject.ParamSpec.string('nick', + 'nick', + 'nick', + GObject.ParamFlags.READWRITE | + GObject.ParamFlags.EXPLICIT_NOTIFY, + '') + }, + Signals: { 'nick-changed': {} } +}, class NickPopover extends Gtk.Popover { + _init() { + this._nick = ''; + + super._init(); + + this.set_default_widget(this._changeButton); + + this._changeButton.connect('clicked', () => { + if (!this._nickEntry.text) + return; + + this._nick = this._nickEntry.text; + this.emit('nick-changed'); + }); + } + + get nick() { + return this._nick; + } + + set nick(nick) { + if (this._nick == nick) + return; + + if (!this._nickEntry['is-focus']) + this._nickEntry.text = nick; + this._nick = nick; + + this.notify('nick'); + } +}); + var EntryArea = GObject.registerClass({ Template: 'resource:///org/gnome/Polari/ui/entry-area.ui', InternalChildren: ['chatEntry', 'nickButton', 'nickLabel', - 'nickPopover', - 'nickEntry', - 'changeButton', 'pasteBox', 'confirmLabel', 'uploadLabel', @@ -187,12 +230,12 @@ var EntryArea = GObject.registerClass({ w.set_state_flags (state, true); }); - this._changeButton.connect('clicked', () => { - if (this._nickEntry.text) - this._setNick(this._nickEntry.text); - this._nickButton.active = false; + this._nickPopover = new NickPopover(); + this._nickPopover.connect('nick-changed', () => { + this._setNick(this._nickPopover.nick); + this._nickButton.active = false; }); - this._nickPopover.set_default_widget(this._changeButton); + this._nickButton.popover = this._nickPopover; this._chatEntry.connect('text-pasted', (entry, text, nLines) => { this.pasteText(text, nLines); @@ -447,8 +490,7 @@ var EntryArea = GObject.registerClass({ this._nickLabel.width_chars = Math.max(nick.length, this._maxNickChars); this._nickLabel.label = nick; - if (!this._nickEntry['is-focus']) - this._nickEntry.text = nick; + this._nickPopover.nick = nick; } _onDestroy() { -- GitLab From f80294828aca8209982703eab0887578b53f15be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 3 Nov 2017 23:34:34 +0100 Subject: [PATCH 2/2] 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 e0e6ec6d..ae912501 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; } }); -- GitLab