Refactor: Move GObject.registerClass calls into static init. blocks

Do that since it standardizes the code and also is just cleaner.
This commit is contained in:
Julian 2023-10-04 03:56:33 +02:00
parent a77c6d2f2b
commit 5ea8f4aabe
Signed by: julian
GPG Key ID: 094C2AC34192FA11
4 changed files with 54 additions and 46 deletions

View File

@ -10,11 +10,15 @@ import * as Main from "resource:///org/gnome/shell/ui/main.js";
* what is really useable by the other extension code. * what is really useable by the other extension code.
* It's basically a heavy wrapper around the box orders stored in the settings. * It's basically a heavy wrapper around the box orders stored in the settings.
*/ */
const BoxOrderManager = GObject.registerClass({ export default class BoxOrderManager extends GObject.Object {
static {
GObject.registerClass({
Signals: { Signals: {
"appIndicatorReady": {} "appIndicatorReady": {}
} }
}, class BoxOrderManager extends GObject.Object { }, this);
}
#appIndicatorReadyHandlerIdMap; #appIndicatorReadyHandlerIdMap;
#appIndicatorItemApplicationRoleMap; #appIndicatorItemApplicationRoleMap;
#settings; #settings;
@ -267,6 +271,4 @@ const BoxOrderManager = GObject.registerClass({
saveBoxOrderToSettings(boxOrders.center, "center"); saveBoxOrderToSettings(boxOrders.center, "center");
saveBoxOrderToSettings(boxOrders.right, "right"); saveBoxOrderToSettings(boxOrders.right, "right");
} }
}); }
export default BoxOrderManager;

View File

@ -9,7 +9,9 @@ import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/
import PrefsBoxOrderItemRow from "./PrefsBoxOrderItemRow.js"; import PrefsBoxOrderItemRow from "./PrefsBoxOrderItemRow.js";
import PrefsBoxOrderListEmptyPlaceholder from "./PrefsBoxOrderListEmptyPlaceholder.js"; import PrefsBoxOrderListEmptyPlaceholder from "./PrefsBoxOrderListEmptyPlaceholder.js";
const PrefsBoxOrderListBox = GObject.registerClass({ export default class PrefsBoxOrderListBox extends Gtk.ListBox {
static {
GObject.registerClass({
GTypeName: "PrefsBoxOrderListBox", GTypeName: "PrefsBoxOrderListBox",
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-list-box.ui", GLib.UriFlags.NONE), Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-list-box.ui", GLib.UriFlags.NONE),
Properties: { Properties: {
@ -26,7 +28,9 @@ const PrefsBoxOrderListBox = GObject.registerClass({
param_types: [PrefsBoxOrderItemRow, GObject.TYPE_STRING] param_types: [PrefsBoxOrderItemRow, GObject.TYPE_STRING]
} }
} }
}, class PrefsBoxOrderListBox extends Gtk.ListBox { }, this);
}
#settings; #settings;
#rowSignalHandlerIds = new Map(); #rowSignalHandlerIds = new Map();
@ -143,6 +147,4 @@ const PrefsBoxOrderListBox = GObject.registerClass({
} }
} }
} }
}); }
export default PrefsBoxOrderListBox;

View File

@ -4,10 +4,14 @@ import Gtk from "gi://Gtk";
import GObject from "gi://GObject"; import GObject from "gi://GObject";
import GLib from "gi://GLib"; import GLib from "gi://GLib";
const PrefsBoxOrderListEmptyPlaceholder = GObject.registerClass({ export default class PrefsBoxOrderListEmptyPlaceholder extends Gtk.Box {
static {
GObject.registerClass({
GTypeName: "PrefsBoxOrderListEmptyPlaceholder", GTypeName: "PrefsBoxOrderListEmptyPlaceholder",
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-list-empty-placeholder.ui", GLib.UriFlags.NONE) Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-list-empty-placeholder.ui", GLib.UriFlags.NONE)
}, class PrefsBoxOrderListEmptyPlaceholder extends Gtk.Box { }, this);
}
// Handle a new drop on `this` properly. // Handle a new drop on `this` properly.
// `value` is the thing getting dropped. // `value` is the thing getting dropped.
onDrop(_target, value, _x, _y) { onDrop(_target, value, _x, _y) {
@ -28,6 +32,4 @@ const PrefsBoxOrderListEmptyPlaceholder = GObject.registerClass({
valueListBox.saveBoxOrderToSettings(); valueListBox.saveBoxOrderToSettings();
valueListBox.determineRowMoveActionEnable(); valueListBox.determineRowMoveActionEnable();
} }
}); }
export default PrefsBoxOrderListEmptyPlaceholder;

View File

@ -11,7 +11,9 @@ import PrefsBoxOrderListEmptyPlaceholder from "./PrefsBoxOrderListEmptyPlacehold
// Imports to make UI file work. // Imports to make UI file work.
import PrefsBoxOrderListBox from "./PrefsBoxOrderListBox.js"; import PrefsBoxOrderListBox from "./PrefsBoxOrderListBox.js";
const PrefsPage = GObject.registerClass({ export default class PrefsPage extends Adw.PreferencesPage {
static {
GObject.registerClass({
GTypeName: "PrefsPage", GTypeName: "PrefsPage",
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-page.ui", GLib.UriFlags.NONE), Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-page.ui", GLib.UriFlags.NONE),
InternalChildren: [ InternalChildren: [
@ -19,7 +21,9 @@ const PrefsPage = GObject.registerClass({
"center-box-order-list-box", "center-box-order-list-box",
"right-box-order-list-box" "right-box-order-list-box"
] ]
}, class PrefsPage extends Adw.PreferencesPage { }, this);
}
constructor(params = {}) { constructor(params = {}) {
super(params); super(params);
@ -172,6 +176,4 @@ const PrefsPage = GObject.registerClass({
return; return;
} }
} }
}); }
export default PrefsPage;