[gnome-shell-extensions] cleanup: Use regular constructors in GObject subclasses



commit 08db193b3132c92743c691fb8f86e52e0dedbfe0
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Feb 9 23:52:39 2022 +0100

    cleanup: Use regular constructors in GObject subclasses
    
    As a side-effect of supporting class fields, regular constructors
    now work in GObject subclasses. Using _init() still works and
    there's no functional difference, but it's simply much nicer
    to use the same syntax for all classes.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/215>

 extensions/apps-menu/extension.js            | 12 ++++-----
 extensions/auto-move-windows/prefs.js        | 22 ++++++++--------
 extensions/drive-menu/extension.js           |  8 +++---
 extensions/places-menu/extension.js          |  8 +++---
 extensions/user-theme/prefs.js               |  8 +++---
 extensions/window-list/extension.js          | 38 ++++++++++++++--------------
 extensions/window-list/prefs.js              |  4 +--
 extensions/window-list/windowPicker.js       | 28 ++++++++++----------
 extensions/window-list/workspaceIndicator.js | 12 ++++-----
 extensions/windowsNavigator/extension.js     |  8 +++---
 extensions/workspace-indicator/extension.js  | 12 ++++-----
 extensions/workspace-indicator/prefs.js      | 12 ++++-----
 12 files changed, 86 insertions(+), 86 deletions(-)
---
diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js
index b9c3fca..ef4741d 100644
--- a/extensions/apps-menu/extension.js
+++ b/extensions/apps-menu/extension.js
@@ -26,8 +26,8 @@ Gio._promisify(Gio._LocalFilePrototype, 'set_attributes_async', 'set_attributes_
 
 var ApplicationMenuItem = GObject.registerClass(
 class ApplicationMenuItem extends PopupMenu.PopupBaseMenuItem {
-    _init(button, app) {
-        super._init();
+    constructor(button, app) {
+        super();
         this._app = app;
         this._button = button;
 
@@ -97,8 +97,8 @@ class ApplicationMenuItem extends PopupMenu.PopupBaseMenuItem {
 
 var CategoryMenuItem = GObject.registerClass(
 class CategoryMenuItem extends PopupMenu.PopupBaseMenuItem {
-    _init(button, category) {
-        super._init();
+    constructor(button, category) {
+        super();
         this._category = category;
         this._button = button;
 
@@ -355,8 +355,8 @@ Signals.addSignalMethods(DesktopTarget.prototype);
 
 let ApplicationsButton = GObject.registerClass(
 class ApplicationsButton extends PanelMenu.Button {
-    _init() {
-        super._init(1.0, null, false);
+    constructor() {
+        super(1.0, null, false);
 
         this.setMenu(new ApplicationsMenu(this, 1.0, St.Side.TOP, this));
         Main.panel.menuManager.addMenu(this.menu);
diff --git a/extensions/auto-move-windows/prefs.js b/extensions/auto-move-windows/prefs.js
index 1e3603d..908d328 100644
--- a/extensions/auto-move-windows/prefs.js
+++ b/extensions/auto-move-windows/prefs.js
@@ -15,7 +15,7 @@ const WORKSPACE_MAX = 36; // compiled in limit of mutter
 const AutoMoveSettingsWidget = GObject.registerClass(
 class AutoMoveSettingsWidget extends Adw.PreferencesGroup {
     static _classInit(klass) {
-        super._classInit(klass);
+        klass = super._classInit(klass);
 
         klass.install_action('rules.add', null, self => self._addNewRule());
         klass.install_action('rules.remove', 's',
@@ -25,8 +25,8 @@ class AutoMoveSettingsWidget extends Adw.PreferencesGroup {
         return klass;
     }
 
-    _init() {
-        super._init({
+    constructor() {
+        super({
             title: _('Workspace Rules'),
         });
 
@@ -125,8 +125,8 @@ const WorkspaceSelector = GObject.registerClass({
         return klass;
     }
 
-    _init() {
-        super._init();
+    constructor() {
+        super();
 
         this.layout_manager.spacing = 6;
 
@@ -180,8 +180,8 @@ const RuleRow = GObject.registerClass({
             1, WORKSPACE_MAX, 1),
     },
 }, class RuleRow extends Adw.ActionRow {
-    _init(appInfo, value) {
-        super._init({
+    constructor(appInfo, value) {
+        super({
             activatable: false,
             title: appInfo.get_display_name(),
             value,
@@ -221,8 +221,8 @@ const RuleRow = GObject.registerClass({
 
 const NewRuleRow = GObject.registerClass(
 class NewRuleRow extends Gtk.ListBoxRow {
-    _init() {
-        super._init({
+    constructor() {
+        super({
             action_name: 'rules.add',
             child: new Gtk.Image({
                 icon_name: 'list-add-symbolic',
@@ -240,8 +240,8 @@ class NewRuleRow extends Gtk.ListBoxRow {
 
 const NewRuleDialog = GObject.registerClass(
 class NewRuleDialog extends Gtk.AppChooserDialog {
-    _init(parent) {
-        super._init({
+    constructor(parent) {
+        super({
             transient_for: parent,
             modal: true,
         });
diff --git a/extensions/drive-menu/extension.js b/extensions/drive-menu/extension.js
index 75e7763..7c74b4c 100644
--- a/extensions/drive-menu/extension.js
+++ b/extensions/drive-menu/extension.js
@@ -14,8 +14,8 @@ Gio._promisify(Gio.File.prototype, 'query_filesystem_info_async');
 
 var MountMenuItem = GObject.registerClass(
 class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
-    _init(mount) {
-        super._init({
+    constructor(mount) {
+        super({
             style_class: 'drive-menu-item',
         });
 
@@ -135,8 +135,8 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
 
 let DriveMenu = GObject.registerClass(
 class DriveMenu extends PanelMenu.Button {
-    _init() {
-        super._init(0.0, _('Removable devices'));
+    constructor() {
+        super(0.0, _('Removable devices'));
 
         let icon = new St.Icon({
             icon_name: 'media-eject-symbolic',
diff --git a/extensions/places-menu/extension.js b/extensions/places-menu/extension.js
index 3fe9d9f..d263686 100644
--- a/extensions/places-menu/extension.js
+++ b/extensions/places-menu/extension.js
@@ -18,8 +18,8 @@ const PLACE_ICON_SIZE = 16;
 
 var PlaceMenuItem = GObject.registerClass(
 class PlaceMenuItem extends PopupMenu.PopupBaseMenuItem {
-    _init(info) {
-        super._init({
+    constructor(info) {
+        super({
             style_class: 'place-menu-item',
         });
         this._info = info;
@@ -84,8 +84,8 @@ const SECTIONS = [
 
 let PlacesMenu = GObject.registerClass(
 class PlacesMenu extends PanelMenu.Button {
-    _init() {
-        super._init(0.0, _('Places'));
+    constructor() {
+        super(0.0, _('Places'));
 
         let label = new St.Label({
             text: _('Places'),
diff --git a/extensions/user-theme/prefs.js b/extensions/user-theme/prefs.js
index 4177683..94e2d3e 100644
--- a/extensions/user-theme/prefs.js
+++ b/extensions/user-theme/prefs.js
@@ -17,8 +17,8 @@ Gio._promisify(Gio.FileEnumerator.prototype, 'next_files_async');
 
 const UserThemePrefsWidget = GObject.registerClass(
 class UserThemePrefsWidget extends Adw.PreferencesGroup {
-    _init() {
-        super._init({ title: 'Themes' });
+    constructor() {
+        super({ title: 'Themes' });
 
         this._actionGroup = new Gio.SimpleActionGroup();
         this.insert_action_group('theme', this._actionGroup);
@@ -105,13 +105,13 @@ class UserThemePrefsWidget extends Adw.PreferencesGroup {
 
 const ThemeRow = GObject.registerClass(
 class ThemeRow extends Adw.ActionRow {
-    _init(name) {
+    constructor(name) {
         const check = new Gtk.CheckButton({
             action_name: 'theme.name',
             action_target: new GLib.Variant('s', name),
         });
 
-        super._init({
+        super({
             title: name || 'Default',
             activatable_widget: check,
         });
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
index f872ef7..7b83313 100644
--- a/extensions/window-list/extension.js
+++ b/extensions/window-list/extension.js
@@ -108,15 +108,15 @@ class WindowContextMenu extends PopupMenu.PopupMenu {
 
 const WindowTitle = GObject.registerClass(
 class WindowTitle extends St.BoxLayout {
-    _init(metaWindow) {
-        this._metaWindow = metaWindow;
-
-        super._init({
+    constructor(metaWindow) {
+        super({
             style_class: 'window-button-box',
             x_expand: true,
             y_expand: true,
         });
 
+        this._metaWindow = metaWindow;
+
         this._icon = new St.Bin({ style_class: 'window-button-icon' });
         this.add(this._icon);
         this.label_actor = new St.Label({ y_align: Clutter.ActorAlign.CENTER });
@@ -187,18 +187,18 @@ const BaseButton = GObject.registerClass({
             false),
     },
 }, class BaseButton extends St.Button {
-    _init(perMonitor, monitorIndex) {
-        this._perMonitor = perMonitor;
-        this._monitorIndex = monitorIndex;
-        this._ignoreWorkspace = false;
-
-        super._init({
+    constructor(perMonitor, monitorIndex) {
+        super({
             style_class: 'window-button',
             can_focus: true,
             x_expand: true,
             button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
         });
 
+        this._perMonitor = perMonitor;
+        this._monitorIndex = monitorIndex;
+        this._ignoreWorkspace = false;
+
         this.connect('notify::allocation',
             this._updateIconGeometry.bind(this));
         this.connect('clicked', this._onClicked.bind(this));
@@ -349,8 +349,8 @@ const BaseButton = GObject.registerClass({
 
 const WindowButton = GObject.registerClass(
 class WindowButton extends BaseButton {
-    _init(metaWindow, perMonitor, monitorIndex) {
-        super._init(perMonitor, monitorIndex);
+    constructor(metaWindow, perMonitor, monitorIndex) {
+        super(perMonitor, monitorIndex);
 
         this.metaWindow = metaWindow;
         this._skipTaskbarId = metaWindow.connect('notify::skip-taskbar', () => {
@@ -485,8 +485,8 @@ class AppContextMenu extends PopupMenu.PopupMenu {
 
 const AppButton = GObject.registerClass(
 class AppButton extends BaseButton {
-    _init(app, perMonitor, monitorIndex) {
-        super._init(perMonitor, monitorIndex);
+    constructor(app, perMonitor, monitorIndex) {
+        super(perMonitor, monitorIndex);
 
         this.app = app;
         this._updateVisibility();
@@ -675,11 +675,8 @@ class AppButton extends BaseButton {
 
 const WindowList = GObject.registerClass(
 class WindowList extends St.Widget {
-    _init(perMonitor, monitor) {
-        this._perMonitor = perMonitor;
-        this._monitor = monitor;
-
-        super._init({
+    constructor(perMonitor, monitor) {
+        super({
             name: 'panel',
             style_class: 'bottom-panel solid',
             reactive: true,
@@ -688,6 +685,9 @@ class WindowList extends St.Widget {
         });
         this.connect('destroy', this._onDestroy.bind(this));
 
+        this._perMonitor = perMonitor;
+        this._monitor = monitor;
+
         let box = new St.BoxLayout({ x_expand: true, y_expand: true });
         this.add_actor(box);
 
diff --git a/extensions/window-list/prefs.js b/extensions/window-list/prefs.js
index ab58152..e6c8750 100644
--- a/extensions/window-list/prefs.js
+++ b/extensions/window-list/prefs.js
@@ -14,8 +14,8 @@ function init() {
 
 const WindowListPrefsWidget = GObject.registerClass(
 class WindowListPrefsWidget extends Adw.PreferencesPage {
-    _init() {
-        super._init();
+    constructor() {
+        super();
 
         this._actionGroup = new Gio.SimpleActionGroup();
         this.insert_action_group('window-list', this._actionGroup);
diff --git a/extensions/window-list/windowPicker.js b/extensions/window-list/windowPicker.js
index 658a5db..e4c2c98 100644
--- a/extensions/window-list/windowPicker.js
+++ b/extensions/window-list/windowPicker.js
@@ -15,11 +15,10 @@ const {
 
 let MyWorkspacesDisplay = GObject.registerClass(
 class MyWorkspacesDisplay extends WorkspacesDisplay {
-    _init(controls, overviewAdjustment) {
+    constructor(controls, overviewAdjustment) {
         let workspaceManager = global.workspace_manager;
 
-        this._overviewAdjustment = overviewAdjustment;
-        this._workspaceAdjustment = new St.Adjustment({
+        const workspaceAdjustment = new St.Adjustment({
             value: workspaceManager.get_active_workspace_index(),
             lower: 0,
             page_increment: 1,
@@ -28,14 +27,15 @@ class MyWorkspacesDisplay extends WorkspacesDisplay {
             upper: workspaceManager.n_workspaces,
         });
 
+        super(controls, workspaceAdjustment, overviewAdjustment);
+
+        this._workspaceAdjustment = workspaceAdjustment;
+        this._workspaceAdjustment.actor = this;
+
         this._nWorkspacesChangedId =
             workspaceManager.connect('notify::n-workspaces',
                 this._updateAdjustment.bind(this));
 
-        super._init(controls, this._workspaceAdjustment, this._overviewAdjustment);
-
-        this._workspaceAdjustment.actor = this;
-
         this.add_constraint(
             new Layout.MonitorConstraint({
                 primary: true,
@@ -79,8 +79,8 @@ class MyWorkspacesDisplay extends WorkspacesDisplay {
 
 const MyWorkspace = GObject.registerClass(
 class MyWorkspace extends Workspace.Workspace {
-    _init(...args) {
-        super._init(...args);
+    constructor(...args) {
+        super(...args);
 
         this._adjChangedId =
             this._overviewAdjustment.connect('notify::value', () => {
@@ -145,15 +145,15 @@ var WindowPicker = GObject.registerClass({
         'open-state-changed': { param_types: [GObject.TYPE_BOOLEAN] },
     },
 }, class extends Clutter.Actor {
-    _init() {
+    constructor() {
+        super({ reactive: true });
+
         this._visible = false;
         this._modal = false;
 
         this._overlayKeyId = 0;
         this._stageKeyPressId = 0;
 
-        super._init({ reactive: true });
-
         this._adjustment = new OverviewAdjustment(this);
 
         this.connect('destroy', this._onDestroy.bind(this));
@@ -315,7 +315,7 @@ var WindowPicker = GObject.registerClass({
 
 var WindowPickerToggle = GObject.registerClass(
 class WindowPickerToggle extends St.Button {
-    _init() {
+    constructor() {
         let iconBin = new St.Widget({
             layout_manager: new Clutter.BinLayout(),
         });
@@ -327,7 +327,7 @@ class WindowPickerToggle extends St.Button {
             x_align: Clutter.ActorAlign.CENTER,
             y_align: Clutter.ActorAlign.CENTER,
         }));
-        super._init({
+        super({
             style_class: 'window-picker-toggle',
             child: iconBin,
             visible: !Main.sessionMode.hasOverview,
diff --git a/extensions/window-list/workspaceIndicator.js b/extensions/window-list/workspaceIndicator.js
index 06646cc..610c3aa 100644
--- a/extensions/window-list/workspaceIndicator.js
+++ b/extensions/window-list/workspaceIndicator.js
@@ -16,8 +16,8 @@ const MAX_THUMBNAILS = 6;
 
 let WindowPreview = GObject.registerClass(
 class WindowPreview extends St.Button {
-    _init(window) {
-        super._init({
+    constructor(window) {
+        super({
             style_class: 'window-list-window-preview',
         });
 
@@ -103,8 +103,8 @@ class WorkspaceLayout extends Clutter.LayoutManager {
 
 let WorkspaceThumbnail = GObject.registerClass(
 class WorkspaceThumbnail extends St.Button {
-    _init(index) {
-        super._init({
+    constructor(index) {
+        super({
             style_class: 'workspace',
             child: new Clutter.Actor({
                 layout_manager: new WorkspaceLayout(),
@@ -245,8 +245,8 @@ class WorkspaceThumbnail extends St.Button {
 
 var WorkspaceIndicator = GObject.registerClass(
 class WorkspaceIndicator extends PanelMenu.Button {
-    _init() {
-        super._init(0.0, _('Workspace Indicator'), true);
+    constructor() {
+        super(0.0, _('Workspace Indicator'), true);
         this.setMenu(new PopupMenu.PopupMenu(this, 0.0, St.Side.BOTTOM));
         this.add_style_class_name('window-list-workspace-indicator');
         this.remove_style_class_name('panel-button');
diff --git a/extensions/windowsNavigator/extension.js b/extensions/windowsNavigator/extension.js
index a2cab42..c3c0faf 100644
--- a/extensions/windowsNavigator/extension.js
+++ b/extensions/windowsNavigator/extension.js
@@ -11,8 +11,8 @@ const WINDOW_SLOT = 4;
 
 var MyWorkspace = GObject.registerClass(
 class MyWorkspace extends Workspace.Workspace {
-    _init(...args) {
-        super._init(...args);
+    constructor(...args) {
+        super(...args);
 
         if (this.metaWorkspace && this.metaWorkspace.index() < 9) {
             this._tip = new St.Label({
@@ -119,8 +119,8 @@ class MyWorkspace extends Workspace.Workspace {
 
 var MyWorkspacesView = GObject.registerClass(
 class MyWorkspacesView extends WorkspacesView.WorkspacesView {
-    _init(...args) {
-        super._init(...args);
+    constructor(...args) {
+        super(...args);
 
         this._pickWorkspace = false;
         this._pickWindow = false;
diff --git a/extensions/workspace-indicator/extension.js b/extensions/workspace-indicator/extension.js
index a2c95b6..07d01a4 100644
--- a/extensions/workspace-indicator/extension.js
+++ b/extensions/workspace-indicator/extension.js
@@ -21,8 +21,8 @@ const MAX_THUMBNAILS = 6;
 
 let WindowPreview = GObject.registerClass(
 class WindowPreview extends St.Button {
-    _init(window) {
-        super._init({
+    constructor(window) {
+        super({
             style_class: 'workspace-indicator-window-preview',
         });
 
@@ -108,8 +108,8 @@ class WorkspaceLayout extends Clutter.LayoutManager {
 
 let WorkspaceThumbnail = GObject.registerClass(
 class WorkspaceThumbnail extends St.Button {
-    _init(index) {
-        super._init({
+    constructor(index) {
+        super({
             style_class: 'workspace',
             child: new Clutter.Actor({
                 layout_manager: new WorkspaceLayout(),
@@ -250,8 +250,8 @@ class WorkspaceThumbnail extends St.Button {
 
 let WorkspaceIndicator = GObject.registerClass(
 class WorkspaceIndicator extends PanelMenu.Button {
-    _init() {
-        super._init(0.0, _('Workspace Indicator'));
+    constructor() {
+        super(0.0, _('Workspace Indicator'));
 
         let container = new St.Widget({
             layout_manager: new Clutter.BinLayout(),
diff --git a/extensions/workspace-indicator/prefs.js b/extensions/workspace-indicator/prefs.js
index 8baa9de..dcc3848 100644
--- a/extensions/workspace-indicator/prefs.js
+++ b/extensions/workspace-indicator/prefs.js
@@ -26,8 +26,8 @@ class WorkspaceSettingsWidget extends Adw.PreferencesGroup {
         return klass;
     }
 
-    _init() {
-        super._init({
+    constructor() {
+        super({
             title: _('Workspace Names'),
         });
 
@@ -89,8 +89,8 @@ class WorkspaceSettingsWidget extends Adw.PreferencesGroup {
 
 const WorkspaceRow = GObject.registerClass(
 class WorkspaceRow extends Adw.PreferencesRow {
-    _init(name) {
-        super._init({ name });
+    constructor(name) {
+        super({ name });
 
         const box = new Gtk.Box({
             spacing: 12,
@@ -167,8 +167,8 @@ class WorkspaceRow extends Adw.PreferencesRow {
 
 const NewWorkspaceRow = GObject.registerClass(
 class NewWorkspaceRow extends Adw.PreferencesRow {
-    _init() {
-        super._init({
+    constructor() {
+        super({
             action_name: 'workspaces.add',
             child: new Gtk.Image({
                 icon_name: 'list-add-symbolic',


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