cleanup: Use method syntax

Modern javascript has a short-hand for function properties, embrace
it for better readability and to prepare for an eventual port to
ES6 classes.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
This commit is contained in:
Florian Müllner
2017-10-31 01:03:21 +01:00
committed by Florian Müllner
parent cff0b81f32
commit 76f09b1e49
116 changed files with 3140 additions and 3140 deletions

View File

@ -72,14 +72,14 @@ var Urgency = {
var FocusGrabber = new Lang.Class({
Name: 'FocusGrabber',
_init: function(actor) {
_init(actor) {
this._actor = actor;
this._prevKeyFocusActor = null;
this._focusActorChangedId = 0;
this._focused = false;
},
grabFocus: function() {
grabFocus() {
if (this._focused)
return;
@ -93,7 +93,7 @@ var FocusGrabber = new Lang.Class({
this._focused = true;
},
_focusUngrabbed: function() {
_focusUngrabbed() {
if (!this._focused)
return false;
@ -106,13 +106,13 @@ var FocusGrabber = new Lang.Class({
return true;
},
_focusActorChanged: function() {
_focusActorChanged() {
let focusedActor = global.stage.get_key_focus();
if (!focusedActor || !this._actor.contains(focusedActor))
this._focusUngrabbed();
},
ungrabFocus: function() {
ungrabFocus() {
if (!this._focusUngrabbed())
return;
@ -135,7 +135,7 @@ var FocusGrabber = new Lang.Class({
var NotificationPolicy = new Lang.Class({
Name: 'NotificationPolicy',
_init: function(params) {
_init(params) {
params = Params.parse(params, { enable: true,
enableSound: true,
showBanners: true,
@ -148,8 +148,8 @@ var NotificationPolicy = new Lang.Class({
// Do nothing for the default policy. These methods are only useful for the
// GSettings policy.
store: function() { },
destroy: function() { }
store() { },
destroy() { }
});
Signals.addSignalMethods(NotificationPolicy.prototype);
@ -157,7 +157,7 @@ var NotificationGenericPolicy = new Lang.Class({
Name: 'NotificationGenericPolicy',
Extends: NotificationPolicy,
_init: function() {
_init() {
// Don't chain to parent, it would try setting
// our properties to the defaults
@ -167,13 +167,13 @@ var NotificationGenericPolicy = new Lang.Class({
this._masterSettings.connect('changed', Lang.bind(this, this._changed));
},
store: function() { },
store() { },
destroy: function() {
destroy() {
this._masterSettings.run_dispose();
},
_changed: function(settings, key) {
_changed(settings, key) {
this.emit('policy-changed', key);
},
@ -206,7 +206,7 @@ var NotificationApplicationPolicy = new Lang.Class({
Name: 'NotificationApplicationPolicy',
Extends: NotificationPolicy,
_init: function(id) {
_init(id) {
// Don't chain to parent, it would try setting
// our properties to the defaults
@ -221,7 +221,7 @@ var NotificationApplicationPolicy = new Lang.Class({
this._settings.connect('changed', Lang.bind(this, this._changed));
},
store: function() {
store() {
this._settings.set_string('application-id', this.id + '.desktop');
let apps = this._masterSettings.get_strv('application-children');
@ -231,18 +231,18 @@ var NotificationApplicationPolicy = new Lang.Class({
}
},
destroy: function() {
destroy() {
this._masterSettings.run_dispose();
this._settings.run_dispose();
},
_changed: function(settings, key) {
_changed(settings, key) {
this.emit('policy-changed', key);
if (key == 'enable')
this.emit('enable-changed');
},
_canonicalizeId: function(id) {
_canonicalizeId(id) {
// Keys are restricted to lowercase alphanumeric characters and dash,
// and two dashes cannot be in succession
return id.toLowerCase().replace(/[^a-z0-9\-]/g, '-').replace(/--+/g, '-');
@ -331,7 +331,7 @@ var NotificationApplicationPolicy = new Lang.Class({
var Notification = new Lang.Class({
Name: 'Notification',
_init: function(source, title, banner, params) {
_init(source, title, banner, params) {
this.source = source;
this.title = title;
this.urgency = Urgency.NORMAL;
@ -363,7 +363,7 @@ var Notification = new Lang.Class({
// Updates the notification by regenerating its icon and updating
// the title/banner. If @params.clear is %true, it will also
// remove any additional actors/action buttons previously added.
update: function(title, banner, params) {
update(title, banner, params) {
params = Params.parse(params, { gicon: null,
secondaryGIcon: null,
bannerMarkup: false,
@ -403,7 +403,7 @@ var Notification = new Lang.Class({
// addAction:
// @label: the label for the action's button
// @callback: the callback for the action
addAction: function(label, callback) {
addAction(label, callback) {
this.actions.push({ label: label, callback: callback });
},
@ -418,23 +418,23 @@ var Notification = new Lang.Class({
this.emit('acknowledged-changed');
},
setUrgency: function(urgency) {
setUrgency(urgency) {
this.urgency = urgency;
},
setResident: function(resident) {
setResident(resident) {
this.resident = resident;
},
setTransient: function(isTransient) {
setTransient(isTransient) {
this.isTransient = isTransient;
},
setForFeedback: function(forFeedback) {
setForFeedback(forFeedback) {
this.forFeedback = forFeedback;
},
playSound: function() {
playSound() {
if (this._soundPlayed)
return;
@ -471,17 +471,17 @@ var Notification = new Lang.Class({
// the source (which will create a NotificationBanner),
// so customization can be done by subclassing either
// Notification or Source
createBanner: function() {
createBanner() {
return this.source.createBanner(this);
},
activate: function() {
activate() {
this.emit('activated');
if (!this.resident)
this.destroy();
},
destroy: function(reason) {
destroy(reason) {
if (!reason)
reason = NotificationDestroyedReason.DISMISSED;
this.emit('destroy', reason);
@ -493,7 +493,7 @@ var NotificationBanner = new Lang.Class({
Name: 'NotificationBanner',
Extends: Calendar.NotificationMessage,
_init: function(notification) {
_init(notification) {
this.parent(notification);
this.actor.can_focus = false;
@ -514,12 +514,12 @@ var NotificationBanner = new Lang.Class({
}));
},
_onDestroy: function() {
_onDestroy() {
this.parent();
this.notification.disconnect(this._activatedId);
},
_onUpdated: function(n, clear) {
_onUpdated(n, clear) {
this.parent(n, clear);
if (clear) {
@ -532,14 +532,14 @@ var NotificationBanner = new Lang.Class({
this._addSecondaryIcon();
},
_addActions: function() {
_addActions() {
this.notification.actions.forEach(Lang.bind(this,
function(action) {
this.addAction(action.label, action.callback);
}));
},
_addSecondaryIcon: function() {
_addSecondaryIcon() {
if (this.notification.secondaryGIcon) {
let icon = new St.Icon({ gicon: this.notification.secondaryGIcon,
x_align: Clutter.ActorAlign.END });
@ -547,7 +547,7 @@ var NotificationBanner = new Lang.Class({
}
},
addButton: function(button, callback) {
addButton(button, callback) {
if (!this._buttonBox) {
this._buttonBox = new St.BoxLayout({ style_class: 'notification-actions',
x_expand: true });
@ -575,7 +575,7 @@ var NotificationBanner = new Lang.Class({
return button;
},
addAction: function(label, callback) {
addAction(label, callback) {
let button = new St.Button({ style_class: 'notification-button',
label: label,
x_expand: true,
@ -588,7 +588,7 @@ var NotificationBanner = new Lang.Class({
var SourceActor = new Lang.Class({
Name: 'SourceActor',
_init: function(source, size) {
_init(source, size) {
this._source = source;
this._size = size;
@ -613,27 +613,27 @@ var SourceActor = new Lang.Class({
this._updateIcon();
},
setIcon: function(icon) {
setIcon(icon) {
this._iconBin.child = icon;
this._iconSet = true;
},
_getPreferredWidth: function (actor, forHeight, alloc) {
_getPreferredWidth(actor, forHeight, alloc) {
let [min, nat] = this._iconBin.get_preferred_width(forHeight);
alloc.min_size = min; alloc.nat_size = nat;
},
_getPreferredHeight: function (actor, forWidth, alloc) {
_getPreferredHeight(actor, forWidth, alloc) {
let [min, nat] = this._iconBin.get_preferred_height(forWidth);
alloc.min_size = min; alloc.nat_size = nat;
},
_allocate: function(actor, box, flags) {
_allocate(actor, box, flags) {
// the iconBin should fill our entire box
this._iconBin.allocate(box, flags);
},
_updateIcon: function() {
_updateIcon() {
if (this._actorDestroyed)
return;
@ -646,7 +646,7 @@ var SourceActorWithLabel = new Lang.Class({
Name: 'SourceActorWithLabel',
Extends: SourceActor,
_init: function(source, size) {
_init(source, size) {
this.parent(source, size);
this._counterLabel = new St.Label({ x_align: Clutter.ActorAlign.CENTER,
@ -675,7 +675,7 @@ var SourceActorWithLabel = new Lang.Class({
});
},
_allocate: function(actor, box, flags) {
_allocate(actor, box, flags) {
this.parent(actor, box, flags);
let childBox = new Clutter.ActorBox();
@ -699,7 +699,7 @@ var SourceActorWithLabel = new Lang.Class({
this._counterBin.allocate(childBox, flags);
},
_updateCount: function() {
_updateCount() {
if (this._actorDestroyed)
return;
@ -720,7 +720,7 @@ var Source = new Lang.Class({
SOURCE_ICON_SIZE: 48,
_init: function(title, iconName) {
_init(title, iconName) {
this.title = title;
this.iconName = iconName;
@ -743,36 +743,36 @@ var Source = new Lang.Class({
return this.count > 1;
},
countUpdated: function() {
countUpdated() {
this.emit('count-updated');
},
_createPolicy: function() {
_createPolicy() {
return new NotificationPolicy();
},
setTitle: function(newTitle) {
setTitle(newTitle) {
this.title = newTitle;
this.emit('title-changed');
},
createBanner: function(notification) {
createBanner(notification) {
return new NotificationBanner(notification);
},
// Called to create a new icon actor.
// Provides a sane default implementation, override if you need
// something more fancy.
createIcon: function(size) {
createIcon(size) {
return new St.Icon({ gicon: this.getIcon(),
icon_size: size });
},
getIcon: function() {
getIcon() {
return new Gio.ThemedIcon({ name: this.iconName });
},
_onNotificationDestroy: function(notification) {
_onNotificationDestroy(notification) {
let index = this.notifications.indexOf(notification);
if (index < 0)
return;
@ -784,7 +784,7 @@ var Source = new Lang.Class({
this.countUpdated();
},
pushNotification: function(notification) {
pushNotification(notification) {
if (this.notifications.indexOf(notification) >= 0)
return;
@ -799,7 +799,7 @@ var Source = new Lang.Class({
this.countUpdated();
},
notify: function(notification) {
notify(notification) {
notification.acknowledged = false;
this.pushNotification(notification);
@ -810,7 +810,7 @@ var Source = new Lang.Class({
}
},
destroy: function(reason) {
destroy(reason) {
this.policy.destroy();
let notifications = this.notifications;
@ -822,15 +822,15 @@ var Source = new Lang.Class({
this.emit('destroy', reason);
},
iconUpdated: function() {
iconUpdated() {
this.emit('icon-updated');
},
// To be overridden by subclasses
open: function() {
open() {
},
destroyNonResidentNotifications: function() {
destroyNonResidentNotifications() {
for (let i = this.notifications.length - 1; i >= 0; i--)
if (!this.notifications[i].resident)
this.notifications[i].destroy();
@ -843,7 +843,7 @@ Signals.addSignalMethods(Source.prototype);
var MessageTray = new Lang.Class({
Name: 'MessageTray',
_init: function() {
_init() {
this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) {
this._onStatusChanged(proxy.status);
}));
@ -953,15 +953,15 @@ var MessageTray = new Lang.Class({
this._sessionUpdated();
},
_sessionUpdated: function() {
_sessionUpdated() {
this._updateState();
},
_onDragBegin: function() {
_onDragBegin() {
Shell.util_set_hidden_from_pick(this.actor, true);
},
_onDragEnd: function() {
_onDragEnd() {
Shell.util_set_hidden_from_pick(this.actor, false);
},
@ -973,7 +973,7 @@ var MessageTray = new Lang.Class({
this._bannerBin.set_x_align(align);
},
_onNotificationKeyRelease: function(actor, event) {
_onNotificationKeyRelease(actor, event) {
if (event.get_key_symbol() == Clutter.KEY_Escape && event.get_state() == 0) {
this._expireNotification();
return Clutter.EVENT_STOP;
@ -982,7 +982,7 @@ var MessageTray = new Lang.Class({
return Clutter.EVENT_PROPAGATE;
},
_expireNotification: function() {
_expireNotification() {
this._notificationExpired = true;
this._updateState();
},
@ -998,11 +998,11 @@ var MessageTray = new Lang.Class({
this._updateState();
},
contains: function(source) {
contains(source) {
return this._sources.has(source);
},
add: function(source) {
add(source) {
if (this.contains(source)) {
log('Trying to re-add source ' + source.title);
return;
@ -1016,7 +1016,7 @@ var MessageTray = new Lang.Class({
this._onSourceEnableChanged(source.policy, source);
},
_addSource: function(source) {
_addSource(source) {
let obj = {
source: source,
notifyId: 0,
@ -1031,7 +1031,7 @@ var MessageTray = new Lang.Class({
this.emit('source-added', source);
},
_removeSource: function(source) {
_removeSource(source) {
let obj = this._sources.get(source);
this._sources.delete(source);
@ -1041,11 +1041,11 @@ var MessageTray = new Lang.Class({
this.emit('source-removed', source);
},
getSources: function() {
getSources() {
return [...this._sources.keys()];
},
_onSourceEnableChanged: function(policy, source) {
_onSourceEnableChanged(policy, source) {
let wasEnabled = this.contains(source);
let shouldBeEnabled = policy.enable;
@ -1057,11 +1057,11 @@ var MessageTray = new Lang.Class({
}
},
_onSourceDestroy: function(source) {
_onSourceDestroy(source) {
this._removeSource(source);
},
_onNotificationDestroy: function(notification) {
_onNotificationDestroy(notification) {
if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
this._updateNotificationTimeout(0);
this._notificationRemoved = true;
@ -1076,7 +1076,7 @@ var MessageTray = new Lang.Class({
}
},
_onNotify: function(source, notification) {
_onNotify(source, notification) {
if (this._notification == notification) {
// If a notification that is being shown is updated, we update
// how it is shown and extend the time until it auto-hides.
@ -1102,7 +1102,7 @@ var MessageTray = new Lang.Class({
this._updateState();
},
_resetNotificationLeftTimeout: function() {
_resetNotificationLeftTimeout() {
this._useLongerNotificationLeftTimeout = false;
if (this._notificationLeftTimeoutId) {
Mainloop.source_remove(this._notificationLeftTimeoutId);
@ -1112,7 +1112,7 @@ var MessageTray = new Lang.Class({
}
},
_onNotificationHoverChanged: function() {
_onNotificationHoverChanged() {
if (this._bannerBin.hover == this._notificationHovered)
return;
@ -1156,7 +1156,7 @@ var MessageTray = new Lang.Class({
}
},
_onStatusChanged: function(status) {
_onStatusChanged(status) {
if (status == GnomeSession.PresenceStatus.BUSY) {
// remove notification and allow the summary to be closed now
this._updateNotificationTimeout(0);
@ -1171,7 +1171,7 @@ var MessageTray = new Lang.Class({
this._updateState();
},
_onNotificationLeftTimeout: function() {
_onNotificationLeftTimeout() {
let [x, y, mods] = global.get_pointer();
// We extend the timeout once if the mouse moved no further than MOUSE_LEFT_ACTOR_THRESHOLD to either side.
if (this._notificationLeftMouseX > -1 &&
@ -1193,7 +1193,7 @@ var MessageTray = new Lang.Class({
return GLib.SOURCE_REMOVE;
},
_escapeTray: function() {
_escapeTray() {
this._pointerInNotification = false;
this._updateNotificationTimeout(0);
this._updateState();
@ -1204,7 +1204,7 @@ var MessageTray = new Lang.Class({
// 'this._pointerInNotification', 'this._traySummoned', etc, and
// _updateState() figures out what (if anything) needs to be done
// at the present time.
_updateState: function() {
_updateState() {
let hasMonitor = Main.layoutManager.primaryMonitor != null;
this.actor.visible = !this._bannerBlocked && hasMonitor && this._banner != null;
if (this._bannerBlocked || !hasMonitor)
@ -1262,7 +1262,7 @@ var MessageTray = new Lang.Class({
this._notificationExpired = false;
},
_tween: function(actor, statevar, value, params) {
_tween(actor, statevar, value, params) {
let onComplete = params.onComplete;
let onCompleteScope = params.onCompleteScope;
let onCompleteParams = params.onCompleteParams;
@ -1279,24 +1279,24 @@ var MessageTray = new Lang.Class({
this[statevar] = valuing;
},
_tweenComplete: function(statevar, value, onComplete, onCompleteScope, onCompleteParams) {
_tweenComplete(statevar, value, onComplete, onCompleteScope, onCompleteParams) {
this[statevar] = value;
if (onComplete)
onComplete.apply(onCompleteScope, onCompleteParams);
this._updateState();
},
_clampOpacity: function() {
_clampOpacity() {
this._bannerBin.opacity = Math.max(0, Math.min(this._bannerBin._opacity, 255));
},
_onIdleMonitorBecameActive: function() {
_onIdleMonitorBecameActive() {
this._userActiveWhileNotificationShown = true;
this._updateNotificationTimeout(2000);
this._updateState();
},
_showNotification: function() {
_showNotification() {
this._notification = this._notificationQueue.shift();
this.emit('queue-changed');
@ -1340,7 +1340,7 @@ var MessageTray = new Lang.Class({
this._resetNotificationLeftTimeout();
},
_updateShowingNotification: function() {
_updateShowingNotification() {
this._notification.acknowledged = true;
this._notification.playSound();
@ -1374,12 +1374,12 @@ var MessageTray = new Lang.Class({
this._tween(this._bannerBin, '_notificationState', State.SHOWN, tweenParams);
},
_showNotificationCompleted: function() {
_showNotificationCompleted() {
if (this._notification.urgency != Urgency.CRITICAL)
this._updateNotificationTimeout(NOTIFICATION_TIMEOUT * 1000);
},
_updateNotificationTimeout: function(timeout) {
_updateNotificationTimeout(timeout) {
if (this._notificationTimeoutId) {
Mainloop.source_remove(this._notificationTimeoutId);
this._notificationTimeoutId = 0;
@ -1392,7 +1392,7 @@ var MessageTray = new Lang.Class({
}
},
_notificationTimeout: function() {
_notificationTimeout() {
let [x, y, mods] = global.get_pointer();
if (y < this._lastSeenMouseY - 10 && !this._notificationHovered) {
// The mouse is moving towards the notification, so don't
@ -1416,7 +1416,7 @@ var MessageTray = new Lang.Class({
return GLib.SOURCE_REMOVE;
},
_hideNotification: function(animate) {
_hideNotification(animate) {
this._notificationFocusGrabber.ungrabFocus();
if (this._bannerClickedId) {
@ -1450,7 +1450,7 @@ var MessageTray = new Lang.Class({
}
},
_hideNotificationCompleted: function() {
_hideNotificationCompleted() {
let notification = this._notification;
this._notification = null;
if (notification.isTransient)
@ -1464,14 +1464,14 @@ var MessageTray = new Lang.Class({
this.actor.hide();
},
_expandActiveNotification: function() {
_expandActiveNotification() {
if (!this._banner)
return;
this._expandBanner(false);
},
_expandBanner: function(autoExpanding) {
_expandBanner(autoExpanding) {
// Don't animate changes in notifications that are auto-expanding.
this._banner.expand(!autoExpanding);
@ -1480,7 +1480,7 @@ var MessageTray = new Lang.Class({
this._ensureBannerFocused();
},
_ensureBannerFocused: function() {
_ensureBannerFocused() {
this._notificationFocusGrabber.grabFocus();
}
});
@ -1490,11 +1490,11 @@ var SystemNotificationSource = new Lang.Class({
Name: 'SystemNotificationSource',
Extends: Source,
_init: function() {
_init() {
this.parent(_("System Information"), 'dialog-information-symbolic');
},
open: function() {
open() {
this.destroy();
}
});