[polari] js: Only destroy() toplevel windows



commit 274b986dc46d11660de2fc7d626fc7cdd00b08db
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Sep 21 20:01:33 2020 +0200

    js: Only destroy() toplevel windows
    
    In GTK4, destroy() moved from Widget to Window. Non-toplevels should
    be removed from their parent and unreffed (or garbage-collected).
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/225>

 src/appNotifications.js | 13 ++++++++++---
 src/connections.js      |  5 ++++-
 src/roomList.js         | 10 ++++++----
 src/roomStack.js        |  5 ++++-
 src/tabCompletion.js    |  6 ++++--
 src/userList.js         | 11 ++++++++---
 6 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 7c8cd760..dfb2fb76 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -24,7 +24,7 @@ const AppNotification = GObject.registerClass({
 
     _onChildRevealed() {
         if (!this.child_revealed)
-            this.destroy();
+            this.hide();
     }
 });
 
@@ -178,11 +178,18 @@ class NotificationQueue extends Gtk.Frame {
     addNotification(notification) {
         this._grid.add(notification);
 
-        notification.connect('destroy', this._onChildDestroy.bind(this));
+        notification.connect('notify::visible',
+            this._onChildVisibleChanged.bind(this));
         this.show();
     }
 
-    _onChildDestroy() {
+    _onChildVisibleChanged(child) {
+        if (child.visible)
+            return;
+
+        this._grid.remove(child);
+        child.run_dispose();
+
         if (this._grid.get_children().length === 0)
             this.hide();
     }
diff --git a/src/connections.js b/src/connections.js
index d921e4d4..6d939268 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -192,7 +192,10 @@ export const ConnectionsList = GObject.registerClass({
     }
 
     _networksChanged() {
-        this._list.foreach(w => w.destroy());
+        this._list.foreach(w => {
+            this._list.remove(w);
+            w.run_dispose();
+        });
 
         let { accounts } = this._accountsMonitor;
         let usedNetworks = accounts.filter(a => a.predefined).map(a => a.service);
diff --git a/src/roomList.js b/src/roomList.js
index d2081c0e..a93e29dc 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -694,7 +694,8 @@ class RoomList extends Gtk.ListBox {
             return;
 
         this._placeholders.delete(account);
-        placeholder.destroy();
+        this.remove(placeholder);
+        placeholder.run_dispose();
     }
 
     _roomAdded(roomManager, room) {
@@ -715,7 +716,8 @@ class RoomList extends Gtk.ListBox {
             return;
 
         this._moveSelectionFromRow(row);
-        row.destroy();
+        this.remove(row);
+        row.run_dispose();
         this._roomRows.delete(room.id);
         this._updatePlaceholderVisibility(room.account);
     }
@@ -757,8 +759,8 @@ class RoomList extends Gtk.ListBox {
         let oldHeader = row.get_header();
 
         if (beforeAccount === account) {
-            if (oldHeader)
-                oldHeader.destroy();
+            row.set_header(null);
+            oldHeader?.run_dispose();
             return;
         }
 
diff --git a/src/roomStack.js b/src/roomStack.js
index 3106c401..d299e7ec 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -76,8 +76,11 @@ export default GObject.registerClass({
     }
 
     _roomRemoved(roomManager, room) {
-        this._rooms.get(room.id).destroy();
+        const view = this._rooms.get(room.id);
         this._rooms.delete(room.id);
+
+        this.remove(view);
+        view.run_dispose();
     }
 
     _activeRoomChanged() {
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index 9807cd5e..32875682 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -97,8 +97,10 @@ export default class TabCompletion {
 
         // All remaining rows except those with IRC commands are going unused
         this._list.foreach(r => {
-            if (!r._text.startsWith('/'))
-                r.destroy();
+            if (r._text.startsWith('/'))
+                return;
+            this._list.remove(r);
+            r.run_dispose();
         });
 
         for (let i = 0; i < completions.length; i++) {
diff --git a/src/userList.js b/src/userList.js
index fefc31ee..d42d1c47 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -64,7 +64,8 @@ class UserListPopover extends Gtk.Popover {
         this._entry.text = '';
 
         if (this._userList)
-            this._userList.destroy();
+            this._box.remove(this._userList);
+        this._userList?.run_dispose();
         this._userList = null;
     }
 
@@ -655,7 +656,10 @@ class UserList extends Gtk.ScrolledWindow {
     }
 
     _onChannelChanged(room) {
-        this._list.foreach(w => w.destroy());
+        this._list.foreach(w => {
+            this._list.remove(w);
+            w.run_dispose();
+        });
         this._rows.clear();
 
         if (!room.channel)
@@ -675,7 +679,8 @@ class UserList extends Gtk.ScrolledWindow {
     _removeMember(member) {
         let row = this._rows.get(member);
         if (row)
-            row.destroy();
+            this._list.remove(row);
+        row?.run_dispose();
         this._rows.delete(member);
     }
 


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