cleanup: Port GObject classes to JS6 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://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
This commit is contained in:
Florian Müllner
2017-10-31 02:23:39 +01:00
committed by Georges Basile Stavracas Neto
parent bacfdbbb03
commit e68dfed1f7
43 changed files with 1036 additions and 1235 deletions

View File

@ -1,16 +1,14 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Clutter = imports.gi.Clutter;
const GObject = imports.gi.GObject;
const IBus = imports.gi.IBus;
const Keyboard = imports.ui.status.keyboard;
const Lang = imports.lang;
const Signals = imports.signals;
var InputMethod = new Lang.Class({
Name: 'InputMethod',
Extends: Clutter.InputMethod,
var InputMethod = GObject.registerClass(
class InputMethod extends Clutter.InputMethod {
_init() {
this.parent();
super._init();
this._hints = 0;
this._purpose = 0;
this._currentFocus = null;
@ -29,11 +27,11 @@ var InputMethod = new Lang.Class({
if (this._ibus.is_connected())
this._onConnected();
},
}
get currentFocus() {
return this._currentFocus;
},
}
_updateCapabilities() {
let caps = 0;
@ -48,16 +46,16 @@ var InputMethod = new Lang.Class({
if (this._context)
this._context.set_capabilities(caps);
},
}
_onSourceChanged() {
this._currentSource = this._inputSourceManager.currentSource;
},
}
_onConnected() {
this._ibus.create_input_context_async ('gnome-shell', -1, null,
this._setContext.bind(this));
},
}
_setContext(bus, res) {
this._context = this._ibus.create_input_context_async_finish(res);
@ -69,7 +67,7 @@ var InputMethod = new Lang.Class({
this._context.connect('forward-key-event', this._onForwardKeyEvent.bind(this));
this._updateCapabilities();
},
}
_clear() {
this._context = null;
@ -78,20 +76,20 @@ var InputMethod = new Lang.Class({
this._preeditStr = ''
this._preeditPos = 0;
this._preeditVisible = false;
},
}
_emitRequestSurrounding() {
if (this._context.needs_surrounding_text())
this.emit('request-surrounding');
},
}
_onCommitText(context, text) {
this.commit(text.get_text());
},
}
_onDeleteSurroundingText(context) {
this.delete_surrounding();
},
}
_onUpdatePreeditText(context, text, pos, visible) {
if (text == null)
@ -107,17 +105,17 @@ var InputMethod = new Lang.Class({
this._preeditStr = preedit;
this._preeditPos = pos;
this._preeditVisible = visible;
},
}
_onShowPreeditText(context) {
this._preeditVisible = true;
this.set_preedit_text(this._preeditStr, this._preeditPos);
},
}
_onHidePreeditText(context) {
this.set_preedit_text(null, this._preeditPos);
this._preeditVisible = false;
},
}
_onForwardKeyEvent(context, keyval, keycode, state) {
let press = (state & IBus.ModifierType.RELEASE_MASK) == 0;
@ -131,7 +129,7 @@ var InputMethod = new Lang.Class({
time = global.display.get_current_time_roundtrip();
this.forward_key(keyval, keycode + 8, state & Clutter.ModifierType.MODIFIER_MASK, time, press);
},
}
vfunc_focus_in(focus) {
this._currentFocus = focus;
@ -140,7 +138,7 @@ var InputMethod = new Lang.Class({
this._updateCapabilities();
this._emitRequestSurrounding();
}
},
}
vfunc_focus_out() {
this._currentFocus = null;
@ -154,7 +152,7 @@ var InputMethod = new Lang.Class({
this.set_preedit_text(null, 0);
this._preeditStr = null;
}
},
}
vfunc_reset() {
if (this._context) {
@ -167,7 +165,7 @@ var InputMethod = new Lang.Class({
this.set_preedit_text(null, 0);
this._preeditStr = null;
}
},
}
vfunc_set_cursor_location(rect) {
if (this._context) {
@ -175,7 +173,7 @@ var InputMethod = new Lang.Class({
rect.get_width(), rect.get_height());
this._emitRequestSurrounding();
}
},
}
vfunc_set_surrounding(text, cursor, anchor) {
if (!this._context || !text)
@ -183,7 +181,7 @@ var InputMethod = new Lang.Class({
let ibusText = IBus.Text.new_from_string(text);
this._context.set_surrounding_text(ibusText, cursor, anchor);
},
}
vfunc_update_content_hints(hints) {
let ibusHints = 0;
@ -203,7 +201,7 @@ var InputMethod = new Lang.Class({
this._hints = ibusHints;
if (this._context)
this._context.set_content_type(this._purpose, this._hints);
},
}
vfunc_update_content_purpose(purpose) {
let ibusPurpose = 0;
@ -229,7 +227,7 @@ var InputMethod = new Lang.Class({
this._purpose = ibusPurpose;
if (this._context)
this._context.set_content_type(this._purpose, this._hints);
},
}
vfunc_filter_key_event(event) {
if (!this._context)
@ -256,5 +254,5 @@ var InputMethod = new Lang.Class({
}
});
return true;
},
}
});

View File

@ -3,7 +3,6 @@ const Clutter = imports.gi.Clutter;
const Gdm = imports.gi.Gdm;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Meta = imports.gi.Meta;
const GObject = imports.gi.GObject;
@ -44,9 +43,7 @@ function getDefault() {
return _singleton;
}
const SystemActions = new Lang.Class({
Name: 'SystemActions',
Extends: GObject.Object,
const SystemActions = GObject.registerClass({
Properties: {
'can-power-off': GObject.ParamSpec.boolean('can-power-off',
'can-power-off',
@ -83,10 +80,10 @@ const SystemActions = new Lang.Class({
'orientation-lock-icon',
GObject.ParamFlags.READWRITE,
null)
},
}
}, class SystemActions extends GObject.Object {
_init() {
this.parent();
super._init();
this._canHavePowerOff = true;
this._canHaveSuspend = true;
@ -186,35 +183,35 @@ const SystemActions = new Lang.Class({
Main.sessionMode.connect('updated', () => { this._sessionUpdated(); });
this._sessionUpdated();
},
}
get can_power_off() {
return this._actions.get(POWER_OFF_ACTION_ID).available;
},
}
get can_suspend() {
return this._actions.get(SUSPEND_ACTION_ID).available;
},
}
get can_lock_screen() {
return this._actions.get(LOCK_SCREEN_ACTION_ID).available;
},
}
get can_switch_user() {
return this._actions.get(SWITCH_USER_ACTION_ID).available;
},
}
get can_logout() {
return this._actions.get(LOGOUT_ACTION_ID).available;
},
}
get can_lock_orientation() {
return this._actions.get(LOCK_ORIENTATION_ACTION_ID).available;
},
}
get orientation_lock_icon() {
return this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName;
},
}
_sensorProxyAppeared() {
this._sensorProxy = new SensorProxy(Gio.DBus.system, SENSOR_BUS_NAME, SENSOR_OBJECT_PATH,
@ -227,7 +224,7 @@ const SystemActions = new Lang.Class({
() => { this._updateOrientationLock(); });
this._updateOrientationLock();
});
},
}
_updateOrientationLock() {
let available = false;
@ -238,7 +235,7 @@ const SystemActions = new Lang.Class({
this._actions.get(LOCK_ORIENTATION_ACTION_ID).available = available;
this.notify('can-lock-orientation');
},
}
_updateOrientationLockIcon() {
let locked = this._orientationSettings.get_boolean('orientation-lock');
@ -247,14 +244,14 @@ const SystemActions = new Lang.Class({
this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName = iconName;
this.notify('orientation-lock-icon');
},
}
_sessionUpdated() {
this._updateLockScreen();
this._updatePowerOff();
this._updateSuspend();
this._updateMultiUser();
},
}
forceUpdate() {
// Whether those actions are available or not depends on both lockdown
@ -262,7 +259,7 @@ const SystemActions = new Lang.Class({
// latter, so their value may be outdated; force an update now
this._updateHaveShutdown();
this._updateHaveSuspend();
},
}
getMatchingActions(terms) {
// terms is a list of strings
@ -275,15 +272,15 @@ const SystemActions = new Lang.Class({
results.push(key);
return results;
},
}
getName(id) {
return this._actions.get(id).name;
},
}
getIconName(id) {
return this._actions.get(id).iconName;
},
}
activateAction(id) {
switch (id) {
@ -306,14 +303,14 @@ const SystemActions = new Lang.Class({
this.activateLockOrientation();
break;
}
},
}
_updateLockScreen() {
let showLock = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
this._actions.get(LOCK_SCREEN_ACTION_ID).available = showLock && allowLockScreen && LoginManager.canLock();
this.notify('can-lock-screen');
},
}
_updateHaveShutdown() {
this._session.CanShutdownRemote((result, error) => {
@ -323,7 +320,7 @@ const SystemActions = new Lang.Class({
this._canHavePowerOff = result[0];
this._updatePowerOff();
});
},
}
_updatePowerOff() {
let disabled = Main.sessionMode.isLocked ||
@ -331,7 +328,7 @@ const SystemActions = new Lang.Class({
this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
this._actions.get(POWER_OFF_ACTION_ID).available = this._canHavePowerOff && !disabled;
this.notify('can-power-off');
},
}
_updateHaveSuspend() {
this._loginManager.canSuspend(
@ -340,7 +337,7 @@ const SystemActions = new Lang.Class({
this._suspendNeedsAuth = needsAuth;
this._updateSuspend();
});
},
}
_updateSuspend() {
let disabled = (Main.sessionMode.isLocked &&
@ -349,12 +346,12 @@ const SystemActions = new Lang.Class({
this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
this._actions.get(SUSPEND_ACTION_ID).available = this._canHaveSuspend && !disabled;
this.notify('can-suspend');
},
}
_updateMultiUser() {
this._updateLogout();
this._updateSwitchUser();
},
}
_updateSwitchUser() {
let allowSwitch = !this._lockdownSettings.get_boolean(DISABLE_USER_SWITCH_KEY);
@ -366,7 +363,7 @@ const SystemActions = new Lang.Class({
this.notify('can-switch-user');
return visible;
},
}
_updateLogout() {
let user = this._userManager.get_user(GLib.get_user_name());
@ -384,7 +381,7 @@ const SystemActions = new Lang.Class({
this.notify('can-logout');
return visible;
},
}
activateLockOrientation() {
if (!this._actions.get(LOCK_ORIENTATION_ACTION_ID).available)
@ -392,14 +389,14 @@ const SystemActions = new Lang.Class({
let locked = this._orientationSettings.get_boolean('orientation-lock');
this._orientationSettings.set_boolean('orientation-lock', !locked);
},
}
activateLockScreen() {
if (!this._actions.get(LOCK_SCREEN_ACTION_ID).available)
throw new Error('The lock-screen action is not available!');
Main.screenShield.lock(true);
},
}
activateSwitchUser() {
if (!this._actions.get(SWITCH_USER_ACTION_ID).available)
@ -412,7 +409,7 @@ const SystemActions = new Lang.Class({
Gdm.goto_login_session_sync(null);
return false;
});
},
}
activateLogout() {
if (!this._actions.get(LOGOUT_ACTION_ID).available)
@ -420,14 +417,14 @@ const SystemActions = new Lang.Class({
Main.overview.hide();
this._session.LogoutRemote(0);
},
}
activatePowerOff() {
if (!this._actions.get(POWER_OFF_ACTION_ID).available)
throw new Error('The power-off action is not available!');
this._session.ShutdownRemote(0);
},
}
activateSuspend() {
if (!this._actions.get(SUSPEND_ACTION_ID).available)

View File

@ -4,7 +4,7 @@ const Clutter = imports.gi.Clutter;
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const GObject = imports.gi.GObject;
const Mainloop = imports.mainloop;
const Signals = imports.signals;
const Shell = imports.gi.Shell;
@ -348,12 +348,10 @@ function insertSorted(array, val, cmp) {
return pos;
}
var CloseButton = new Lang.Class({
Name: 'CloseButton',
Extends: St.Button,
var CloseButton = GObject.registerClass(
class CloseButton extends St.Button {
_init(boxpointer) {
this.parent({ style_class: 'notification-close'});
super._init({ style_class: 'notification-close'});
// This is a bit tricky. St.Bin has its own x-align/y-align properties
// that compete with Clutter's properties. This should be fixed for
@ -370,7 +368,7 @@ var CloseButton = new Lang.Class({
this._boxPointer = boxpointer;
if (boxpointer)
this._boxPointer.connect('arrow-side-changed', this._sync.bind(this));
},
}
_computeBoxPointerOffset() {
if (!this._boxPointer || !this._boxPointer.actor.get_stage())
@ -381,7 +379,7 @@ var CloseButton = new Lang.Class({
return this._boxPointer.getArrowHeight();
else
return 0;
},
}
_sync() {
let themeNode = this.get_theme_node();
@ -389,12 +387,12 @@ var CloseButton = new Lang.Class({
let offY = this._computeBoxPointerOffset();
this.translation_x = themeNode.get_length('-shell-close-overlap-x')
this.translation_y = themeNode.get_length('-shell-close-overlap-y') + offY;
},
}
vfunc_style_changed() {
this._sync();
this.parent();
},
super.vfunc_style_changed();
}
});
function makeCloseButton(boxpointer) {