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. Fixes https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/30
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user