[polari/wip/fmuellner/singleton-nick-popover: 1/2] entryArea: Split out NickPopover



commit cb5c1450706190cc4bf5c232ef9b7fa85ea12fbe
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Nov 3 22:40:43 2017 +0100

    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(-)
---
diff --git a/data/org.gnome.Polari.data.gresource.xml b/data/org.gnome.Polari.data.gresource.xml
index 0b43fbe..dd19367 100644
--- a/data/org.gnome.Polari.data.gresource.xml
+++ b/data/org.gnome.Polari.data.gresource.xml
@@ -12,6 +12,7 @@
     <file alias="ui/entry-area.ui" preprocess="xml-stripblanks">resources/entry-area.ui</file>
     <file alias="ui/join-room-dialog.ui" preprocess="xml-stripblanks">resources/join-room-dialog.ui</file>
     <file alias="ui/main-window.ui" preprocess="xml-stripblanks">resources/main-window.ui</file>
+    <file alias="ui/nick-popover.ui" preprocess="xml-stripblanks">resources/nick-popover.ui</file>
     <file alias="ui/room-list-header.ui" preprocess="xml-stripblanks">resources/room-list-header.ui</file>
     <file alias="ui/room-list-row.ui" preprocess="xml-stripblanks">resources/room-list-row.ui</file>
     <file alias="ui/server-room-list.ui" preprocess="xml-stripblanks">resources/server-room-list.ui</file>
diff --git a/data/resources/entry-area.ui b/data/resources/entry-area.ui
index 9de1d43..ed57aae 100644
--- a/data/resources/entry-area.ui
+++ b/data/resources/entry-area.ui
@@ -1,44 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <object class="GtkPopover" id="nickPopover">
-    <property name="position">top</property>
-    <child>
-      <object class="GtkBox">
-        <property name="visible">True</property>
-        <property name="margin">6</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">6</property>
-        <child>
-          <object class="GtkLabel">
-            <property name="visible">True</property>
-            <property name="halign">start</property>
-            <property name="hexpand">True</property>
-            <property name="label" translatable="yes">Change nickname:</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkEntry" id="nickEntry">
-            <property name="visible">True</property>
-            <property name="activates-default">True</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkButton" id="changeButton">
-            <property name="label" translatable="yes">_Change</property>
-            <property name="visible">True</property>
-            <property name="receives-default">True</property>
-            <property name="can-default">True</property>
-            <property name="halign">end</property>
-            <property name="hexpand">True</property>
-            <property name="use-underline">True</property>
-            <style>
-              <class name="suggested-action"/>
-            </style>
-          </object>
-        </child>
-      </object>
-    </child>
-  </object>
   <template class="Gjs_EntryArea" parent="GtkStack">
     <property name="visible">True</property>
     <property name="valign">end</property>
@@ -58,7 +19,6 @@
             <property name="visible">True</property>
             <property name="receives-default">True</property>
             <property name="focus-on-click">False</property>
-            <property name="popover">nickPopover</property>
             <style>
               <class name="flat"/>
               <class name="polari-nick-button"/>
diff --git a/data/resources/nick-popover.ui b/data/resources/nick-popover.ui
new file mode 100644
index 0000000..dc4bbd0
--- /dev/null
+++ b/data/resources/nick-popover.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="Gjs_NickPopover" parent="GtkPopover">
+    <property name="position">top</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="margin">6</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <property name="hexpand">True</property>
+            <property name="label" translatable="yes">Change nickname:</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkEntry" id="nickEntry">
+            <property name="visible">True</property>
+            <property name="activates-default">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="changeButton">
+            <property name="label" translatable="yes">_Change</property>
+            <property name="visible">True</property>
+            <property name="receives-default">True</property>
+            <property name="can-default">True</property>
+            <property name="halign">end</property>
+            <property name="hexpand">True</property>
+            <property name="use-underline">True</property>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/entryArea.js b/src/entryArea.js
index 2ffd30a..e0e6ec6 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() {


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