[gnome-shell-extensions/wip/fmuellner/js-cleanup: 6/7] cleanup: Port GObject classes to ES6 classes
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/fmuellner/js-cleanup: 6/7] cleanup: Port GObject classes to ES6 classes
- Date: Fri, 24 Nov 2017 17:05:49 +0000 (UTC)
commit 824c0460347cfab9c62f4bea97b851a1517980d1
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Oct 28 01:05:11 2017 +0200
cleanup: Port GObject classes to ES6 classes
GJS added API for defining GObject classes with ES6 class syntax
last cycle, use it to port the remaining Lang.Class classes to
the new syntax.
https://bugzilla.gnome.org/show_bug.cgi?id=790301
extensions/alternate-tab/prefs.js | 11 ++++-----
extensions/auto-move-windows/prefs.js | 24 +++++++++----------
extensions/example/prefs.js | 9 +++----
extensions/window-list/prefs.js | 9 +++----
extensions/workspace-indicator/prefs.js | 42 ++++++++++++++-------------------
5 files changed, 39 insertions(+), 56 deletions(-)
---
diff --git a/extensions/alternate-tab/prefs.js b/extensions/alternate-tab/prefs.js
index dda78ee..3b9149e 100644
--- a/extensions/alternate-tab/prefs.js
+++ b/extensions/alternate-tab/prefs.js
@@ -21,13 +21,10 @@ const MODES = {
'both': N_("Thumbnail and application icon"),
};
-const AltTabSettingsWidget = new GObject.Class({
- Name: 'AlternateTab.Prefs.AltTabSettingsWidget',
- GTypeName: 'AltTabSettingsWidget',
- Extends: Gtk.Grid,
-
+const AltTabSettingsWidget = GObject.registerClass(
+class AltTabSettingsWidget extends Gtk.Grid {
_init(params) {
- this.parent(params);
+ super._init(params);
this.margin = 24;
this.row_spacing = 6;
this.orientation = Gtk.Orientation.VERTICAL;
@@ -69,7 +66,7 @@ const AltTabSettingsWidget = new GObject.Class({
margin_top: 6 });
this._settings.bind(SETTINGS_CURRENT_WORKSPACE_ONLY, check, 'active', Gio.SettingsBindFlags.DEFAULT);
this.add(check);
- },
+ }
});
function init() {
diff --git a/extensions/auto-move-windows/prefs.js b/extensions/auto-move-windows/prefs.js
index 52e25fd..16c0416 100644
--- a/extensions/auto-move-windows/prefs.js
+++ b/extensions/auto-move-windows/prefs.js
@@ -26,13 +26,11 @@ const Columns = {
ADJUSTMENT: 4
};
-const Widget = new GObject.Class({
- Name: 'AutoMoveWindows.Prefs.Widget',
+const Widget = GObject.registerClass({
GTypeName: 'AutoMoveWindowsPrefsWidget',
- Extends: Gtk.Grid,
-
+}, class Widget extends Gtk.Grid {
_init(params) {
- this.parent(params);
+ super._init(params);
this.set_orientation(Gtk.Orientation.VERTICAL);
this._settings = Convenience.getSettings();
@@ -95,7 +93,7 @@ const Widget = new GObject.Class({
this._changedPermitted = true;
this._refresh();
- },
+ }
_createNew() {
let dialog = new Gtk.Dialog({ title: _("Create new matching rule"),
@@ -158,7 +156,7 @@ const Widget = new GObject.Class({
dialog.destroy();
});
dialog.show_all();
- },
+ }
_deleteSelected() {
let [any, model, iter] = this._treeView.get_selection().get_selected();
@@ -171,7 +169,7 @@ const Widget = new GObject.Class({
this._changedPermitted = true;
this._store.remove(iter);
}
- },
+ }
_workspaceEdited(renderer, pathString, text) {
let index = parseInt(text);
@@ -185,7 +183,7 @@ const Widget = new GObject.Class({
this._changeItem(appInfo.get_id(), index);
this._store.set_value(iter, Columns.WORKSPACE, index);
this._changedPermitted = true;
- },
+ }
_refresh() {
if (!this._changedPermitted)
@@ -215,18 +213,18 @@ const Widget = new GObject.Class({
if (validItems.length != currentItems.length) // some items were filtered out
this._settings.set_strv(SETTINGS_KEY, validItems);
- },
+ }
_checkId(id) {
let items = this._settings.get_strv(SETTINGS_KEY);
return !items.some(i => i.startsWith(id + ':'));
- },
+ }
_appendItem(id, workspace) {
let currentItems = this._settings.get_strv(SETTINGS_KEY);
currentItems.push(id + ':' + workspace);
this._settings.set_strv(SETTINGS_KEY, currentItems);
- },
+ }
_removeItem(id) {
let currentItems = this._settings.get_strv(SETTINGS_KEY);
@@ -236,7 +234,7 @@ const Widget = new GObject.Class({
return;
currentItems.splice(index, 1);
this._settings.set_strv(SETTINGS_KEY, currentItems);
- },
+ }
_changeItem(id, workspace) {
let currentItems = this._settings.get_strv(SETTINGS_KEY);
diff --git a/extensions/example/prefs.js b/extensions/example/prefs.js
index 40ff041..c5023fd 100644
--- a/extensions/example/prefs.js
+++ b/extensions/example/prefs.js
@@ -16,13 +16,10 @@ function init() {
Convenience.initTranslations();
}
-const ExamplePrefsWidget = new GObject.Class({
- Name: 'Example.Prefs.Widget',
- GTypeName: 'ExamplePrefsWidget',
- Extends: Gtk.Grid,
-
+const ExamplePrefsWidget = GObject.registerClass(
+class ExamplePrefsWidget extends Gtk.Grid {
_init(params) {
- this.parent(params);
+ super._init(params);
this.margin = 12;
this.row_spacing = this.column_spacing = 6;
this.set_orientation(Gtk.Orientation.VERTICAL);
diff --git a/extensions/window-list/prefs.js b/extensions/window-list/prefs.js
index c5e13ee..bc1abcd 100644
--- a/extensions/window-list/prefs.js
+++ b/extensions/window-list/prefs.js
@@ -16,13 +16,10 @@ function init() {
Convenience.initTranslations();
}
-const WindowListPrefsWidget = new GObject.Class({
- Name: 'WindowList.Prefs.Widget',
- GTypeName: 'WindowListPrefsWidget',
- Extends: Gtk.Grid,
-
+const WindowListPrefsWidget = GObject.registerClass(
+class WindowListPrefsWidget extends Gtk.Grid {
_init(params) {
- this.parent(params);
+ super._init(params);
this.margin = 24;
this.row_spacing = 6;
diff --git a/extensions/workspace-indicator/prefs.js b/extensions/workspace-indicator/prefs.js
index 3dbde70..cfb6d8c 100644
--- a/extensions/workspace-indicator/prefs.js
+++ b/extensions/workspace-indicator/prefs.js
@@ -17,19 +17,16 @@ const Convenience = Me.imports.convenience;
const WORKSPACE_SCHEMA = 'org.gnome.desktop.wm.preferences';
const WORKSPACE_KEY = 'workspace-names';
-const WorkspaceNameModel = new GObject.Class({
- Name: 'WorkspaceIndicator.WorkspaceNameModel',
- GTypeName: 'WorkspaceNameModel',
- Extends: Gtk.ListStore,
-
- Columns: {
- LABEL: 0,
- },
-
+const WorkspaceNameModel = GObject.registerClass(
+class WorkspaceNameModel extends Gtk.ListStore {
_init(params) {
- this.parent(params);
+ super._init(params);
this.set_column_types([GObject.TYPE_STRING]);
+ this.Columns = {
+ LABEL: 0,
+ };
+
this._settings = new Gio.Settings({ schema_id: WORKSPACE_SCHEMA });
//this._settings.connect('changed::workspace-names', Lang.bind(this, this._reloadFromSettings));
@@ -40,7 +37,7 @@ const WorkspaceNameModel = new GObject.Class({
this.connect('row-changed', Lang.bind(this, this._onRowChanged));
this.connect('row-inserted', Lang.bind(this, this._onRowInserted));
this.connect('row-deleted', Lang.bind(this, this._onRowDeleted));
- },
+ }
_reloadFromSettings() {
if (this._preventChanges)
@@ -67,7 +64,7 @@ const WorkspaceNameModel = new GObject.Class({
}
this._preventChanges = false;
- },
+ }
_onRowChanged(self, path, iter) {
if (this._preventChanges)
@@ -88,7 +85,7 @@ const WorkspaceNameModel = new GObject.Class({
this._settings.set_strv(WORKSPACE_KEY, names);
this._preventChanges = false;
- },
+ }
_onRowInserted(self, path, iter) {
if (this._preventChanges)
@@ -103,7 +100,7 @@ const WorkspaceNameModel = new GObject.Class({
this._settings.set_strv(WORKSPACE_KEY, names);
this._preventChanges = false;
- },
+ }
_onRowDeleted(self, path) {
if (this._preventChanges)
@@ -125,16 +122,13 @@ const WorkspaceNameModel = new GObject.Class({
this._settings.set_strv(WORKSPACE_KEY, names);
this._preventChanges = false;
- },
+ }
});
-const WorkspaceSettingsWidget = new GObject.Class({
- Name: 'WorkspaceIndicator.WorkspaceSettingsWidget',
- GTypeName: 'WorkspaceSettingsWidget',
- Extends: Gtk.Grid,
-
+const WorkspaceSettingsWidget = GObject.registerClass(
+class WorkspaceSettingsWidget extends Gtk.Grid {
_init(params) {
- this.parent(params);
+ super._init(params);
this.margin = 12;
this.orientation = Gtk.Orientation.VERTICAL;
@@ -181,14 +175,14 @@ const WorkspaceSettingsWidget = new GObject.Class({
delButton.sensitive = selection.count_selected_rows() > 0;
this.add(toolbar);
- },
+ }
_cellEdited(renderer, path, new_text) {
let [ok, iter] = this._store.get_iter_from_string(path);
if (ok)
this._store.set(iter, [this._store.Columns.LABEL], [new_text]);
- },
+ }
_newClicked() {
let iter = this._store.append();
@@ -196,7 +190,7 @@ const WorkspaceSettingsWidget = new GObject.Class({
let label = _("Workspace %d").format(index + 1);
this._store.set(iter, [this._store.Columns.LABEL], [label]);
- },
+ }
_delClicked() {
let [any, model, iter] = this._treeView.get_selection().get_selected();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]