[polari] Stop using Gtk.Container methods



commit 54fed521c4be0b25e1bb5390d59e2b1f187530da
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Sep 25 00:26:46 2020 +0200

    Stop using Gtk.Container methods
    
    Gtk.Container is gone in GTK4. To prepare for this, replace all
    usage with the polyfill methods we added earlier.
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/228>

 src/appNotifications.js | 25 +++++++++++++------------
 src/chatView.js         |  2 +-
 src/connections.js      | 16 ++++++++--------
 src/roomList.js         |  6 +++---
 src/roomStack.js        |  8 ++++----
 src/tabCompletion.js    | 16 ++++++++--------
 src/urlPreview.js       |  4 ++--
 src/userList.js         | 30 +++++++++++++++---------------
 8 files changed, 54 insertions(+), 53 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 13069ec1..b0b854fe 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -38,9 +38,9 @@ class MessageNotification extends AppNotification {
         this._box = new Gtk.Box({ spacing: 12, visible: true });
 
         if (iconName)
-            this._box.add(new Gtk.Image({ icon_name: iconName, visible: true }));
+            this._box.append(new Gtk.Image({ icon_name: iconName, visible: true }));
 
-        this._box.add(new Gtk.Label({
+        this._box.append(new Gtk.Label({
             label,
             hexpand: true,
             ellipsize: Pango.EllipsizeMode.END,
@@ -52,7 +52,7 @@ class MessageNotification extends AppNotification {
         closeButton.connect('clicked', this.close.bind(this));
         this._box.pack_end(closeButton, false, false, 0);
 
-        this.add(this._box);
+        this.set_child(this._box);
         this.show();
     }
 
@@ -65,7 +65,7 @@ class MessageNotification extends AppNotification {
             this.close();
         });
 
-        this._box.add(button);
+        this._box.append(button);
     }
 });
 
@@ -121,7 +121,7 @@ class SimpleOutput extends CommandOutputNotification {
             visible: true,
             wrap: true,
         });
-        this.add(label);
+        this.set_child(label);
         this.show();
     }
 });
@@ -154,7 +154,7 @@ class GridOutput extends CommandOutputNotification {
             }
             row++;
         }
-        this.add(grid);
+        this.set_child(grid);
         this.show();
     }
 });
@@ -174,11 +174,12 @@ class NotificationQueue extends Gtk.Frame {
             orientation: Gtk.Orientation.VERTICAL,
             row_spacing: 6, visible: true,
         });
-        this.add(this._grid);
+        this.set_child(this._grid);
     }
 
     addNotification(notification) {
-        this._grid.add(notification);
+        this._grid.attach_next_to(notification,
+            null, Gtk.PositionType.BOTTOM, 1, 1);
 
         notification.connect('notify::visible',
             this._onChildVisibleChanged.bind(this));
@@ -192,7 +193,7 @@ class NotificationQueue extends Gtk.Frame {
         this._grid.remove(child);
         child.run_dispose();
 
-        if (this._grid.get_children().length === 0)
+        if (this._grid.get_first_child() === null)
             this.hide();
     }
 });
@@ -231,7 +232,7 @@ export const MessageInfoBar = GObject.registerClass({
         super._init(Object.assign(defaultParams, params));
 
         let box = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
-        this.get_content_area().add(box);
+        this.get_content_area().append(box);
 
         this._titleLabel = new Gtk.Label({
             halign: Gtk.Align.START,
@@ -241,7 +242,7 @@ export const MessageInfoBar = GObject.registerClass({
             wrap: true,
             visible: true,
         });
-        box.add(this._titleLabel);
+        box.append(this._titleLabel);
 
         this._subtitleLabel = new Gtk.Label({
             halign: Gtk.Align.START,
@@ -250,7 +251,7 @@ export const MessageInfoBar = GObject.registerClass({
             ellipsize: Pango.EllipsizeMode.END,
             visible: true,
         });
-        box.add(this._subtitleLabel);
+        box.append(this._subtitleLabel);
 
         this.connect('response', () => (this.revealed = false));
 
diff --git a/src/chatView.js b/src/chatView.js
index 222c7192..972319bb 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -360,7 +360,7 @@ export default GObject.registerClass({
             null);
         this._view.add_events(Gdk.EventMask.LEAVE_NOTIFY_MASK |
                               Gdk.EventMask.ENTER_NOTIFY_MASK);
-        this.add(this._view);
+        this.set_child(this._view);
         this.show();
 
         this._createTags();
diff --git a/src/connections.js b/src/connections.js
index a2c62d6f..0a98e7d8 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -50,9 +50,9 @@ class ConnectionRow extends Gtk.ListBoxRow {
             margin_bottom: 12,
             visible: true,
         });
-        this.add(box);
+        this.set_child(box);
 
-        box.add(new Gtk.Label({ label: name, halign: Gtk.Align.START, visible: true }));
+        box.append(new Gtk.Label({ label: name, halign: Gtk.Align.START, visible: true }));
 
         let insensitiveDesc = new Gtk.Label({
             label: _('Already added'),
@@ -60,7 +60,7 @@ class ConnectionRow extends Gtk.ListBoxRow {
             halign: Gtk.Align.END,
             visible: false,
         });
-        box.add(insensitiveDesc);
+        box.append(insensitiveDesc);
 
         this.show();
 
@@ -96,7 +96,7 @@ export const ConnectionsList = GObject.registerClass({
 
         this._list = new Gtk.ListBox({ visible: true });
         this._list.connect('row-activated', this._onRowActivated.bind(this));
-        this.add(this._list);
+        this.set_child(this._list);
 
         this._rows = new Map();
 
@@ -111,12 +111,12 @@ export const ConnectionsList = GObject.registerClass({
             orientation: Gtk.Orientation.VERTICAL,
             visible: true,
         });
-        placeholder.add(new Gtk.Image({
+        placeholder.append(new Gtk.Image({
             icon_name: 'edit-find-symbolic',
             pixel_size: 115,
             visible: true,
         }));
-        placeholder.add(new Gtk.Label({
+        placeholder.append(new Gtk.Label({
             label: _('No results.'),
             visible: true,
         }));
@@ -193,7 +193,7 @@ export const ConnectionsList = GObject.registerClass({
     }
 
     _networksChanged() {
-        this._list.foreach(w => {
+        [...this._list].forEach(w => {
             this._list.remove(w);
             w.run_dispose();
         });
@@ -211,7 +211,7 @@ export const ConnectionsList = GObject.registerClass({
                 id: network.id,
                 sensitive,
             }));
-            this._list.add(this._rows.get(network.id));
+            this._list.append(this._rows.get(network.id));
         });
     }
 
diff --git a/src/roomList.js b/src/roomList.js
index 9c3ee757..43121910 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -632,7 +632,7 @@ class RoomList extends Gtk.ListBox {
     }
 
     _roomToRowIndex(index) {
-        let roomRows = this.get_children().filter(r => r instanceof RoomRow);
+        let roomRows = [...this].filter(r => r instanceof RoomRow);
         return index < roomRows.length ? roomRows[index].get_index() : -1;
     }
 
@@ -708,7 +708,7 @@ class RoomList extends Gtk.ListBox {
         placeholder.account = account;
 
         this._placeholders.set(account, placeholder);
-        this.add(placeholder);
+        this.append(placeholder);
 
         placeholder.connect('notify::visible', () => {
             this.invalidate_sort();
@@ -733,7 +733,7 @@ class RoomList extends Gtk.ListBox {
             return;
 
         let row = new RoomRow(room);
-        this.add(row);
+        this.append(row);
         this._roomRows.set(room.id, row);
 
         row.connect('destroy', w => this._roomRows.delete(w.room.id));
diff --git a/src/roomStack.js b/src/roomStack.js
index 4d29be70..40de09df 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -258,7 +258,7 @@ class ChatPlaceholder extends Gtk.Overlay {
         grid.attach(title, 1, 0, 1, 1);
         grid.attach(description, 0, 1, 2, 1);
         inputPlaceholder.show();
-        this.add(grid);
+        this.set_child(grid);
         this.add_overlay(inputPlaceholder);
         this.show();
     }
@@ -270,7 +270,7 @@ class RoomView extends Gtk.Overlay {
         super._init({ name: `RoomView ${room.display_name}` });
 
         let box = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, visible: true });
-        this.add(box);
+        this.set_child(box);
 
         if (room.type === Tp.HandleType.CONTACT)
             this.add_overlay(new SavePasswordConfirmationBar(room));
@@ -278,14 +278,14 @@ class RoomView extends Gtk.Overlay {
         this.add_overlay(new ChannelErrorBar(room));
 
         this._view = new ChatView(room);
-        box.add(this._view);
+        box.append(this._view);
 
         this._entryArea = new EntryArea({
             room,
             sensitive: false,
             visible: true,
         });
-        box.add(this._entryArea);
+        box.append(this._entryArea);
 
         this._view.bind_property('max-nick-chars',
             this._entryArea, 'max-nick-chars',
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index 26386366..7d4784a5 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -28,7 +28,7 @@ export default class TabCompletion {
         this._list.set_filter_func(this._filter.bind(this));
         this._list.connect('row-selected', this._onRowSelected.bind(this));
         this._list.connect('row-activated', this._stop.bind(this));
-        this._popup.add(this._list);
+        this._popup.set_child(this._list);
 
         this._widgetMap = new Map();
         this._previousWasCommand = false;
@@ -38,7 +38,7 @@ export default class TabCompletion {
             let row = new Gtk.ListBoxRow();
             row._text = `/${commands[i]}`;
             row._casefoldedText = row._text.toLowerCase();
-            row.add(new Gtk.Label({
+            row.set_child(new Gtk.Label({
                 label: row._text,
                 halign: Gtk.Align.START,
                 margin_start: 6,
@@ -46,7 +46,7 @@ export default class TabCompletion {
                 visible: true,
             }));
             row.show();
-            this._list.add(row);
+            this._list.append(row);
         }
     }
 
@@ -89,7 +89,7 @@ export default class TabCompletion {
                 row = new Gtk.ListBoxRow();
                 row._text = nick;
                 row._casefoldedText = row._text.toLowerCase();
-                row.add(new Gtk.Label({
+                row.set_child(new Gtk.Label({
                     label: row._text,
                     halign: Gtk.Align.START,
                     margin_start: 6,
@@ -104,7 +104,7 @@ export default class TabCompletion {
         this._widgetMap = widgetMap;
 
         // All remaining rows except those with IRC commands are going unused
-        this._list.foreach(r => {
+        [...this._list].forEach(r => {
             if (r._text.startsWith('/'))
                 return;
             this._list.remove(r);
@@ -113,7 +113,7 @@ export default class TabCompletion {
 
         for (let i = 0; i < completions.length; i++) {
             let row = this._widgetMap.get(completions[i]);
-            this._list.add(row);
+            this._list.append(row);
         }
         this._canComplete = completions.length > 0;
     }
@@ -210,7 +210,7 @@ export default class TabCompletion {
 
         this._list.invalidate_filter();
 
-        let visibleRows = this._list.get_children().filter(c => c.get_child_visible());
+        let visibleRows = [...this._list].filter(c => c.get_child_visible());
         let nVisibleRows = visibleRows.length;
 
         if (nVisibleRows === 0)
@@ -226,7 +226,7 @@ export default class TabCompletion {
     }
 
     _moveSelection(count) {
-        const rows = this._list.get_children().filter(c => c.get_child_visible());
+        const rows = [...this._list].filter(c => c.get_child_visible());
         const current = this._list.get_selected_row();
         const index = current ? rows.findIndex(r => r === current) : 0;
         const newIndex = (index + rows.length + count) % rows.length;
diff --git a/src/urlPreview.js b/src/urlPreview.js
index 328d3f03..4e6c48b8 100644
--- a/src/urlPreview.js
+++ b/src/urlPreview.js
@@ -124,7 +124,7 @@ export default GObject.registerClass({
             visible: true,
         });
         this._image.get_style_context().add_class('dim-label');
-        this.add(this._image);
+        this.append(this._image);
 
         this._label = new Gtk.Label({
             halign: Gtk.Align.START,
@@ -132,7 +132,7 @@ export default GObject.registerClass({
             visible: true,
         });
         this._label.get_style_context().add_class('dim-label');
-        this.add(this._label);
+        this.append(this._label);
 
         this._networkMonitor = Gio.NetworkMonitor.get_default();
         this._networkChangedId = this._networkMonitor.connect('network-changed',
diff --git a/src/userList.js b/src/userList.js
index 071a87ad..eb7b764d 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -49,14 +49,14 @@ class UserListPopover extends Gtk.Popover {
             margin_bottom: 6,
             visible: true,
         });
-        this.add(this._box);
+        this.set_child(this._box);
 
         this._revealer = new Gtk.Revealer({ visible: true });
-        this._box.add(this._revealer);
+        this._box.append(this._revealer);
 
         this._entry = new Gtk.SearchEntry({ visible: true });
         this._entry.connect('search-changed', this._updateFilter.bind(this));
-        this._revealer.add(this._entry);
+        this._revealer.set_child(this._entry);
     }
 
     _activeRoomChanged() {
@@ -90,7 +90,7 @@ class UserListPopover extends Gtk.Popover {
             return;
 
         this._userList = new UserList(room);
-        this._box.add(this._userList);
+        this._box.append(this._userList);
 
         this._userList.vadjustment.connect('changed',
             this._updateEntryVisibility.bind(this));
@@ -463,7 +463,7 @@ class UserListRow extends Gtk.ListBoxRow {
 
     _createWidget() {
         let vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, visible: true });
-        this.add(vbox);
+        this.set_child(vbox);
 
         let hbox = new Gtk.Box({
             margin_end: 12,
@@ -486,12 +486,12 @@ class UserListRow extends Gtk.ListBoxRow {
             max_width_chars: MAX_USERS_WIDTH_CHARS,
             visible: true,
         });
-        hbox.add(this._label);
-        hbox.add(this._arrow);
-        vbox.add(hbox);
+        hbox.append(this._label);
+        hbox.append(this._arrow);
+        vbox.append(hbox);
 
         this._revealer = new Gtk.Revealer({ reveal_child: false, visible: true });
-        vbox.add(this._revealer);
+        vbox.append(this._revealer);
 
         this.show();
     }
@@ -504,7 +504,7 @@ class UserListRow extends Gtk.ListBoxRow {
 
         this._revealer.bind_property('reveal-child', details, 'expanded', 0);
 
-        this._revealer.add(details);
+        this._revealer.set_child(details);
     }
 
     shouldShow() {
@@ -565,7 +565,7 @@ class UserList extends Gtk.ScrolledWindow {
         });
 
         this._list = new Gtk.ListBox({ vexpand: true });
-        this.add(this._list);
+        this.set_child(this._list);
         let placeholder = new Gtk.Box({
             halign: Gtk.Align.CENTER,
             valign: Gtk.Align.CENTER,
@@ -577,12 +577,12 @@ class UserList extends Gtk.ScrolledWindow {
             spacing: 6,
             visible: true,
         });
-        placeholder.add(new Gtk.Image({
+        placeholder.append(new Gtk.Image({
             icon_name: 'edit-find-symbolic',
             pixel_size: 64,
             visible: true,
         }));
-        placeholder.add(new Gtk.Label({
+        placeholder.append(new Gtk.Label({
             label: _('No Results'),
             visible: true,
         }));
@@ -663,7 +663,7 @@ class UserList extends Gtk.ScrolledWindow {
     }
 
     _onChannelChanged(room) {
-        this._list.foreach(w => {
+        [...this._list].forEach(w => {
             this._list.remove(w);
             w.run_dispose();
         });
@@ -680,7 +680,7 @@ class UserList extends Gtk.ScrolledWindow {
     _addMember(member) {
         let row = new UserListRow(member);
         this._rows.set(member, row);
-        this._list.add(row);
+        this._list.append(row);
     }
 
     _removeMember(member) {


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