[polari] roomList: Split out row context menu



commit 5716a42fa15db819fb9394d99b2a284cb1260733
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Apr 20 14:13:47 2019 +0200

    roomList: Split out row context menu
    
    We are about to extend it a bit, so it is better off
    in its own class.
    
    https://gitlab.gnome.org/GNOME/polari/-/merge_requests/153

 src/roomList.js | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index e1470c67..f7e09418 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -216,17 +216,8 @@ var RoomRow = GObject.registerClass({
     }
 
     _showPopover() {
-        if (!this._popover) {
-            let menu = new Gio.Menu();
-            let isRoom = this._room.type === Tp.HandleType.ROOM;
-            let label = isRoom ?  _('Leave chatroom') : _('End conversation');
-            menu.append(label, `app.leave-room(("${this._room.id}", ""))`);
-
-            this._popover = Gtk.Popover.new_from_model(this, menu);
-            this._popover.connect('notify::visible',
-                _onPopoverVisibleChanged);
-            this._popover.position = Gtk.PositionType.BOTTOM;
-        }
+        if (!this._popover)
+            this._popover = new RoomRowPopover(this);
         this._popover.popup();
     }
 
@@ -237,6 +228,27 @@ var RoomRow = GObject.registerClass({
     }
 });
 
+const RoomRowPopover = GObject.registerClass(
+class RoomRowPopover extends Gtk.Popover {
+    _init(row) {
+        super._init({
+            relative_to: row,
+            position: Gtk.PositionType.BOTTOM,
+        });
+
+        this.connect('notify::visible', _onPopoverVisibleChanged);
+
+        this._row = row;
+        this._menu = new Gio.Menu();
+        const isRoom = row.room.type === Tp.HandleType.ROOM;
+
+        const label = isRoom ?  _('Leave chatroom') : _('End conversation');
+        this._menu.append(label, `app.leave-room(("${this._row.room.id}", ""))`);
+
+        this.bind_model(this._menu, null);
+    }
+});
+
 var RoomListHeader = GObject.registerClass({
     CssName: 'row',
     Template: 'resource:///org/gnome/Polari/ui/room-list-header.ui',


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