[polari] ircParser: Take entry



commit 7d860655444fb959632d618e0f01a39ad1b3a1f0
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Feb 13 01:06:51 2022 +0100

    ircParser: Take entry
    
    Instead of driving the parser from the entry, pass the entry at
    construction time and handle events internally. This is similar
    to what we do with tab completion, and likewise will allows us
    to attach a popover to the entry.
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/247>

 src/entryArea.js | 11 +----------
 src/ircParser.js | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/src/entryArea.js b/src/entryArea.js
index 805754d0..ce6154c3 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -184,7 +184,6 @@ class EntryArea extends Gtk.Stack {
         super(params);
 
         this._room = room;
-        this._ircParser = new IrcParser(this._room);
 
         this.connect('destroy', this._onDestroy.bind(this));
         this.connect('notify::sensitive', this._onSensitiveChanged.bind(this));
@@ -253,15 +252,6 @@ class EntryArea extends Gtk.Stack {
 
         this._chatEntry.connect('changed', this._onEntryChanged.bind(this));
 
-        this._chatEntry.connect('activate', () => {
-            if (this._ircParser.process(this._chatEntry.text)) {
-                this._chatEntry.text = '';
-            } else {
-                this._chatEntry.add_css_class('error');
-                this._chatEntry.grab_focus(); // select text
-            }
-        });
-
         this._cancelButton.connect('clicked', this._onCancelClicked.bind(this));
         this._pasteButton.connect('clicked', this._onPasteClicked.bind(this));
 
@@ -281,6 +271,7 @@ class EntryArea extends Gtk.Stack {
         if (!this._room)
             return;
 
+        this._ircParser = new IrcParser(this._chatEntry, this._room);
         this._completion = new TabCompletion(this._chatEntry);
         this._membersChangedId = this._room.connect('members-changed',
             this._updateCompletions.bind(this));
diff --git a/src/ircParser.js b/src/ircParser.js
index 4d2760e6..b66874b2 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -49,10 +49,20 @@ const UNKNOWN_COMMAND_MESSAGE =
 const ROOM_PREFIXES = ['#', '&', '+', '!'];
 
 export default class IrcParser {
-    constructor(room) {
+    constructor(entry, room) {
         this._app = Gio.Application.get_default();
         this._roomManager = RoomManager.getDefault();
         this._room = room;
+        this._entry = entry;
+
+        this._entry.connect('activate', async () => {
+            if (await this._process(this._entry.text)) {
+                this._entry.text = '';
+            } else {
+                this._entry.add_css_class('error');
+                this._entry.grab_focus(); // select text
+            }
+        });
     }
 
     _createFeedbackLabel(text) {
@@ -67,7 +77,7 @@ export default class IrcParser {
         return new AppNotifications.GridOutput(header, items);
     }
 
-    async process(text) {
+    async _process(text) {
         if (!this._room || !this._room.channel || !text.length)
             return true;
 


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