[polari] Replace StyleContext.add/remove_class()



commit 8d067a1969d72059175f39e8aff7692a29814f6a
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Sep 25 00:34:17 2020 +0200

    Replace StyleContext.add/remove_class()
    
    The API moved to Gtk.Widget in GTK4, so switch to the corresponding
    polyfill methods.
    
    Part-of: <https://gitlab.gnome.org/GNOME/polari/-/merge_requests/228>

 src/appNotifications.js |  4 ++--
 src/chatView.js         |  4 ++--
 src/connections.js      | 10 +++++-----
 src/entryArea.js        |  8 ++++----
 src/initialSetup.js     |  5 ++---
 src/mainWindow.js       |  4 ++--
 src/roomList.js         | 16 ++++++----------
 src/roomStack.js        |  6 +++---
 src/urlPreview.js       | 11 +++++------
 src/userList.js         | 15 +++++++--------
 10 files changed, 38 insertions(+), 45 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index b0b854fe..705f7701 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -168,7 +168,7 @@ class NotificationQueue extends Gtk.Frame {
             margin_start: 24, margin_end: 24,
             visible: false,
         });
-        this.get_style_context().add_class('app-notification');
+        this.add_css_class('app-notification');
 
         this._grid = new Gtk.Grid({
             orientation: Gtk.Orientation.VERTICAL,
@@ -204,7 +204,7 @@ class CommandOutputQueue extends NotificationQueue {
         super._init();
 
         this.valign = Gtk.Align.END;
-        this.get_style_context().add_class('irc-feedback');
+        this.add_css_class('irc-feedback');
     }
 });
 
diff --git a/src/chatView.js b/src/chatView.js
index 972319bb..8587b472 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -321,7 +321,7 @@ export default GObject.registerClass({
     _init(room) {
         super._init({ hscrollbar_policy: Gtk.PolicyType.NEVER, vexpand: true });
 
-        this.get_style_context().add_class('polari-chat-view');
+        this.add_css_class('polari-chat-view');
 
         this._actionGroup = new Gio.SimpleActionGroup();
         this.insert_action_group('chatlog', this._actionGroup);
@@ -909,7 +909,7 @@ export default GObject.registerClass({
             icon_name: 'content-loading-symbolic',
             visible: true,
         });
-        indicator.get_style_context().add_class('dim-label');
+        indicator.add_css_class('dim-label');
 
         let { buffer } = this._view;
         let iter = buffer.get_start_iter();
diff --git a/src/connections.js b/src/connections.js
index 0a98e7d8..d803630d 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -121,7 +121,7 @@ export const ConnectionsList = GObject.registerClass({
             visible: true,
         }));
 
-        placeholder.get_style_context().add_class('dim-label');
+        placeholder.add_css_class('dim-label');
 
         this._list.set_placeholder(placeholder);
 
@@ -330,14 +330,14 @@ export const ConnectionDetails = GObject.registerClass({
 
     setErrorHint(hint) {
         if (hint === ErrorHint.SERVER)
-            this._serverEntry.get_style_context().add_class('error');
+            this._serverEntry.add_css_class('error');
         else
-            this._serverEntry.get_style_context().remove_class('error');
+            this._serverEntry.remove_css_class('error');
 
         if (hint === ErrorHint.NICK)
-            this._nickEntry.get_style_context().add_class('error');
+            this._nickEntry.add_css_class('error');
         else
-            this._nickEntry.get_style_context().remove_class('error');
+            this._nickEntry.remove_css_class('error');
     }
 
     _getParams() {
diff --git a/src/entryArea.js b/src/entryArea.js
index 3a6741cc..840ef55a 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -242,7 +242,7 @@ export default GObject.registerClass({
             if (this._ircParser.process(this._chatEntry.text)) {
                 this._chatEntry.text = '';
             } else {
-                this._chatEntry.get_style_context().add_class('error');
+                this._chatEntry.add_css_class('error');
                 this._chatEntry.grab_focus(); // select text
             }
         });
@@ -335,7 +335,7 @@ export default GObject.registerClass({
     }
 
     _onEntryChanged() {
-        this._chatEntry.get_style_context().remove_class('error');
+        this._chatEntry.remove_css_class('error');
     }
 
     _setPasteContent(content) {
@@ -429,9 +429,9 @@ export default GObject.registerClass({
             this._chatEntry.grab_focus();
 
         if (this.sensitive)
-            this._nickLabel.get_style_context().add_class('polari-active-nick');
+            this._nickLabel.add_css_class('polari-active-nick');
         else
-            this._nickLabel.get_style_context().remove_class('polari-active-nick');
+            this._nickLabel.remove_css_class('polari-active-nick');
     }
 
     _onChannelChanged(room) {
diff --git a/src/initialSetup.js b/src/initialSetup.js
index a1eda74c..7daf2e3e 100644
--- a/src/initialSetup.js
+++ b/src/initialSetup.js
@@ -86,11 +86,10 @@ export default GObject.registerClass({
         this._prevButton.label = isLastPage ? _('_Back') : _('_Cancel');
         this._nextButton.label = isLastPage ? _('_Done') : _('_Next');
 
-        let context = this._nextButton.get_style_context();
         if (isLastPage)
-            context.add_class('suggested-action');
+            this._nextButton.add_css_class('suggested-action');
         else
-            context.remove_class('suggested-action');
+            this._nextButton.remove_css_class('suggested-action');
 
         this._nextButton.grab_default();
         this._updateNextSensitivity();
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 8e529256..8b2ac156 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -138,9 +138,9 @@ export default GObject.registerClass({
         this._overlay.add_overlay(app.commandOutputQueue);
 
         if (app.isTestInstance)
-            this.get_style_context().add_class('test-instance');
+            this.add_css_class('test-instance');
         if (GLib.get_application_name().toLowerCase().includes('snapshot'))
-            this.get_style_context().add_class('snapshot');
+            this.add_css_class('snapshot');
 
         this._roomStack.connect('notify::view-height',
             () => this.notify('view-height'));
diff --git a/src/roomList.js b/src/roomList.js
index 43121910..36ebdb50 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -12,11 +12,10 @@ import UserStatusMonitor from './userTracker.js';
 const MIN_SPINNER_TIME = 1000000;   // in microsecond
 
 function _onPopoverVisibleChanged(popover) {
-    let context = popover.relative_to.get_style_context();
     if (popover.visible)
-        context.add_class('has-open-popup');
+        popover.relative_to.add_css_class('has-open-popup');
     else
-        context.remove_class('has-open-popup');
+        popover.relative_to.remove_css_class('has-open-popup');
 }
 
 const RoomRow = GObject.registerClass({
@@ -178,11 +177,10 @@ const RoomRow = GObject.registerClass({
         this._counter.label = nHighlights.toString();
         this._counter.opacity = nHighlights > 0 ? 1. : 0.;
 
-        let context = this.get_style_context();
         if (nPending === 0)
-            context.add_class('inactive');
+            this.add_css_class('inactive');
         else
-            context.remove_class('inactive');
+            this.remove_css_class('inactive');
     }
 
     _onChannelChanged() {
@@ -467,8 +465,7 @@ const RoomListHeader = GObject.registerClass({
         this._popoverStatus.use_markup = !isError;
 
         if (!isError) {
-            let styleContext = this._popoverStatus.get_style_context();
-            styleContext.add_class('dim-label');
+            this._popoverStatus.add_css_class('dim-label');
 
             let params = this._account.dup_parameters_vardict().deep_unpack();
             let server = params['server'].deep_unpack();
@@ -480,8 +477,7 @@ const RoomListHeader = GObject.registerClass({
             this._popoverTitle.label = accountName === server ? accountName : fullTitle;
             this._popoverStatus.label = `<sup>${this._getStatusLabel()}<${'/'}sup>`;
         } else {
-            let styleContext = this._popoverStatus.get_style_context();
-            styleContext.remove_class('dim-label');
+            this._popoverStatus.remove_css_class('dim-label');
 
             this._popoverTitle.label = `<b>${_('Connection Problem')}<${'/'}b>`;
             this._popoverStatus.label = this._getErrorLabel();
diff --git a/src/roomStack.js b/src/roomStack.js
index 40de09df..54c23ca5 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -230,7 +230,7 @@ class ChatPlaceholder extends Gtk.Overlay {
             visible: true,
         });
         title.label = `<span letter_spacing="4500">${_('Polari')}<${'/'}span>`;
-        title.get_style_context().add_class('polari-background-title');
+        title.add_css_class('polari-background-title');
 
         let description = new Gtk.Label({
             label: _('Join a room using the + button.'),
@@ -238,7 +238,7 @@ class ChatPlaceholder extends Gtk.Overlay {
             margin_top: 24, use_markup: true,
             visible: true,
         });
-        description.get_style_context().add_class('polari-background-description');
+        description.add_css_class('polari-background-description');
 
         let inputPlaceholder = new Gtk.Box({ valign: Gtk.Align.END });
         sizeGroup.add_widget(inputPlaceholder);
@@ -253,7 +253,7 @@ class ChatPlaceholder extends Gtk.Overlay {
             valign: Gtk.Align.CENTER,
             visible: true,
         });
-        grid.get_style_context().add_class('polari-background');
+        grid.add_css_class('polari-background');
         grid.attach(image, 0, 0, 1, 1);
         grid.attach(title, 1, 0, 1, 1);
         grid.attach(description, 0, 1, 2, 1);
diff --git a/src/urlPreview.js b/src/urlPreview.js
index 4e6c48b8..8df57254 100644
--- a/src/urlPreview.js
+++ b/src/urlPreview.js
@@ -115,15 +115,14 @@ export default GObject.registerClass({
             spacing: 6,
         });
 
-        let styleContext = this.get_style_context();
-        styleContext.add_class('url-preview');
-        styleContext.add_class('background');
+        this.add_css_class('url-preview');
+        this.add_css_class('background');
 
         this._imageLoaded = false;
         this._image = new Gtk.Image({
             visible: true,
         });
-        this._image.get_style_context().add_class('dim-label');
+        this._image.add_css_class('dim-label');
         this.append(this._image);
 
         this._label = new Gtk.Label({
@@ -131,7 +130,7 @@ export default GObject.registerClass({
             ellipsize: Pango.EllipsizeMode.END,
             visible: true,
         });
-        this._label.get_style_context().add_class('dim-label');
+        this._label.add_css_class('dim-label');
         this.append(this._label);
 
         this._networkMonitor = Gio.NetworkMonitor.get_default();
@@ -165,7 +164,7 @@ export default GObject.registerClass({
 
             title = pixbuf.get_option('tEXt::Title');
             this._image.set_from_pixbuf(pixbuf);
-            this._image.get_style_context().remove_class('dim-label');
+            this._image.remove_css_class('dim-label');
         } catch (e) {
             if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NETWORK_UNREACHABLE)) {
                 this._imageLoaded = false;
diff --git a/src/userList.js b/src/userList.js
index eb7b764d..ef34f2c6 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -413,13 +413,12 @@ export const UserPopover = GObject.registerClass({
             label = _('Offline');
         this._statusLabel.label = label;
 
-        const context = this._nickLabel.get_style_context();
         if (status === Tp.ConnectionPresenceType.AVAILABLE) {
-            context.remove_class('polari-inactive-nick');
-            context.add_class('polari-active-nick');
+            this._nickLabel.remove_css_class('polari-inactive-nick');
+            this._nickLabel.add_css_class('polari-active-nick');
         } else {
-            context.remove_class('polari-active-nick');
-            context.add_class('polari-inactive-nick');
+            this._nickLabel.remove_css_class('polari-active-nick');
+            this._nickLabel.add_css_class('polari-inactive-nick');
         }
     }
 
@@ -543,10 +542,10 @@ class UserListRow extends Gtk.ListBoxRow {
 
     _onExpandedChanged() {
         if (this._revealer.reveal_child) {
-            this.get_style_context().add_class('expanded');
+            this.add_css_class('expanded');
             this._arrow.icon_name = 'pan-down-symbolic';
         } else {
-            this.get_style_context().remove_class('expanded');
+            this.remove_css_class('expanded');
             this._arrow.icon_name = 'pan-end-symbolic';
             this._updateArrowVisibility();
         }
@@ -587,7 +586,7 @@ class UserList extends Gtk.ScrolledWindow {
             visible: true,
         }));
 
-        placeholder.get_style_context().add_class('placeholder');
+        placeholder.add_css_class('placeholder');
 
         this._list.set_placeholder(placeholder);
 


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