Commit 213e38c2 authored by Florian Müllner's avatar Florian Müllner Committed by Florian Müllner

cleanup: Use arrow notation for anonymous functions

Arrow notation is great, use it consistently through-out the code base
to bind `this` to anonymous functions, replacing the more overbose
Lang.bind(this, function() {}).

!23
parent 76f09b1e
......@@ -127,9 +127,7 @@ var Application = new Lang.Class({
errortext += 'Stack trace:\n';
// Indent stack trace.
errortext += exc.stack.split('\n').map(function(line) {
return ' ' + line;
}).join('\n');
errortext += exc.stack.split('\n').map(line => ' ' + line).join('\n');
let scroll = new Gtk.ScrolledWindow({ vexpand: true });
let buffer = new Gtk.TextBuffer({ text: errortext });
......@@ -171,10 +169,10 @@ var Application = new Lang.Class({
this._shellProxy = new GnomeShellProxy(Gio.DBus.session, 'org.gnome.Shell', '/org/gnome/Shell');
this._shellProxy.connectSignal('ExtensionStatusChanged', Lang.bind(this, function(proxy, senderName, [uuid, state, error]) {
this._shellProxy.connectSignal('ExtensionStatusChanged', (proxy, senderName, [uuid, state, error]) => {
if (ExtensionUtils.extensions[uuid] !== undefined)
this._scanExtensions();
}));
});
this._window.show_all();
},
......@@ -204,10 +202,9 @@ var Application = new Lang.Class({
let row = new ExtensionRow(extension.uuid);
row.prefsButton.visible = this._extensionAvailable(row.uuid);
row.prefsButton.connect('clicked', Lang.bind(this,
function() {
this._selectExtension(row.uuid);
}));
row.prefsButton.connect('clicked', () => {
this._selectExtension(row.uuid);
});
row.show_all();
this._extensionSelector.add(row);
......@@ -275,18 +272,17 @@ var ExtensionRow = new Lang.Class({
this.uuid = uuid;
this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
this._settings.connect('changed::enabled-extensions', Lang.bind(this,
function() {
this._switch.state = this._isEnabled();
}));
this._settings.connect('changed::enabled-extensions', () => {
this._switch.state = this._isEnabled();
});
this._settings.connect('changed::disable-extension-version-validation',
Lang.bind(this, function() {
() => {
this._switch.sensitive = this._canEnable();
}));
});
this._settings.connect('changed::disable-user-extensions',
Lang.bind(this, function() {
() => {
this._switch.sensitive = this._canEnable();
}));
});
this._buildUI();
},
......@@ -328,14 +324,13 @@ var ExtensionRow = new Lang.Class({
this._switch = new Gtk.Switch({ valign: Gtk.Align.CENTER,
sensitive: this._canEnable(),
state: this._isEnabled() });
this._switch.connect('notify::active', Lang.bind(this,
function() {
if (this._switch.active)
this._enable();
else
this._disable();
}));
this._switch.connect('state-set', function() { return true; });
this._switch.connect('notify::active', () => {
if (this._switch.active)
this._enable();
else
this._disable();
});
this._switch.connect('state-set', () => true);
hbox.add(this._switch);
},
......
......@@ -64,26 +64,24 @@ var AuthPrompt = new Lang.Class({
this._userVerifier.connect('ovirt-user-authenticated', Lang.bind(this, this._onOVirtUserAuthenticated));
this.smartcardDetected = this._userVerifier.smartcardDetected;
this.connect('next', Lang.bind(this, function() {
this.updateSensitivity(false);
this.startSpinning();
if (this._queryingService) {
this._userVerifier.answerQuery(this._queryingService, this._entry.text);
} else {
this._preemptiveAnswer = this._entry.text;
}
}));
this.connect('next', () => {
this.updateSensitivity(false);
this.startSpinning();
if (this._queryingService) {
this._userVerifier.answerQuery(this._queryingService, this._entry.text);
} else {
this._preemptiveAnswer = this._entry.text;
}
});
this.actor = new St.BoxLayout({ style_class: 'login-dialog-prompt-layout',
vertical: true });
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
this.actor.connect('key-press-event',
Lang.bind(this, function(actor, event) {
if (event.get_key_symbol() == Clutter.KEY_Escape) {
this.cancel();
}
return Clutter.EVENT_PROPAGATE;
}));
this.actor.connect('key-press-event', (actor, event) => {
if (event.get_key_symbol() == Clutter.KEY_Escape)
this.cancel();
return Clutter.EVENT_PROPAGATE;
});
this._userWell = new St.Bin({ x_fill: true,
x_align: St.Align.START });
......@@ -147,10 +145,7 @@ var AuthPrompt = new Lang.Class({
reactive: true,
can_focus: true,
label: _("Cancel") });
this.cancelButton.connect('clicked',
Lang.bind(this, function() {
this.cancel();
}));
this.cancelButton.connect('clicked', () => { this.cancel(); });
this._buttonBox.add(this.cancelButton,
{ expand: false,
x_fill: false,
......@@ -169,10 +164,7 @@ var AuthPrompt = new Lang.Class({
reactive: true,
can_focus: true,
label: _("Next") });
this.nextButton.connect('clicked',
Lang.bind(this, function() {
this.emit('next');
}));
this.nextButton.connect('clicked', () => { this.emit('next'); });
this.nextButton.add_style_pseudo_class('default');
this._buttonBox.add(this.nextButton,
{ expand: false,
......@@ -183,17 +175,16 @@ var AuthPrompt = new Lang.Class({
this._updateNextButtonSensitivity(this._entry.text.length > 0);
this._entry.clutter_text.connect('text-changed',
Lang.bind(this, function() {
if (!this._userVerifier.hasPendingMessages)
this._fadeOutMessage();
this._entry.clutter_text.connect('text-changed', () => {
if (!this._userVerifier.hasPendingMessages)
this._fadeOutMessage();
this._updateNextButtonSensitivity(this._entry.text.length > 0 || this.verificationStatus == AuthPromptStatus.VERIFYING);
}));
this._entry.clutter_text.connect('activate', Lang.bind(this, function() {
this._updateNextButtonSensitivity(this._entry.text.length > 0 || this.verificationStatus == AuthPromptStatus.VERIFYING);
});
this._entry.clutter_text.connect('activate', () => {
if (this.nextButton.reactive)
this.emit('next');
}));
});
},
_onAskQuestion(verifier, serviceName, question, passwordChar) {
......@@ -509,12 +500,11 @@ var AuthPrompt = new Lang.Class({
return;
}
let signalId = this._userVerifier.connect('no-more-messages',
Lang.bind(this, function() {
this._userVerifier.disconnect(signalId);
this._userVerifier.clear();
onComplete();
}));
let signalId = this._userVerifier.connect('no-more-messages', () => {
this._userVerifier.disconnect(signalId);
this._userVerifier.clear();
onComplete();
});
},
cancel() {
......
......@@ -73,9 +73,7 @@ var Hold = new Lang.Class({
Extends: Task,
_init() {
this.parent(this, function () {
return this;
});
this.parent(this, () => this);
this._acquisitions = 1;
},
......@@ -91,10 +89,10 @@ var Hold = new Lang.Class({
return;
this.acquire();
let signalId = hold.connect('release', Lang.bind(this, function() {
hold.disconnect(signalId);
this.release();
}));
let signalId = hold.connect('release', () => {
hold.disconnect(signalId);
this.release();
});
},
release() {
......@@ -214,11 +212,10 @@ var ConsecutiveBatch = new Lang.Class({
if (hold && hold.isAcquired()) {
// This task is inhibiting the batch. Wait on it
// before processing the next one.
let signalId = hold.connect('release',
Lang.bind(this, function() {
hold.disconnect(signalId);
this.nextTask();
}));
let signalId = hold.connect('release', () => {
hold.disconnect(signalId);
this.nextTask();
});
return;
} else {
// This task finished, process the next one
......
......@@ -129,20 +129,19 @@ var UserListItem = new Lang.Class({
let startTime = GLib.get_monotonic_time();
this._timedLoginTimeoutId = GLib.timeout_add (GLib.PRIORITY_DEFAULT,
33,
Lang.bind(this, function() {
let currentTime = GLib.get_monotonic_time();
let elapsedTime = (currentTime - startTime) / GLib.USEC_PER_SEC;
this._timedLoginIndicator.scale_x = elapsedTime / time;
if (elapsedTime >= time) {
this._timedLoginTimeoutId = 0;
hold.release();
return GLib.SOURCE_REMOVE;
}
return GLib.SOURCE_CONTINUE;
}));
this._timedLoginTimeoutId = GLib.timeout_add (GLib.PRIORITY_DEFAULT, 33,
() => {
let currentTime = GLib.get_monotonic_time();
let elapsedTime = (currentTime - startTime) / GLib.USEC_PER_SEC;
this._timedLoginIndicator.scale_x = elapsedTime / time;
if (elapsedTime >= time) {
this._timedLoginTimeoutId = 0;
hold.release();
return GLib.SOURCE_REMOVE;
}
return GLib.SOURCE_CONTINUE;
});
GLib.Source.set_name_by_id(this._timedLoginTimeoutId, '[gnome-shell] this._timedLoginTimeoutId');
......@@ -188,10 +187,10 @@ var UserList = new Lang.Class({
let focusSet = this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
if (!focusSet) {
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
this._moveFocusToItems();
return false;
}));
});
}
},
......@@ -275,11 +274,7 @@ var UserList = new Lang.Class({
Lang.bind(this, this._onItemActivated));
// Try to keep the focused item front-and-center
item.actor.connect('key-focus-in',
Lang.bind(this,
function() {
this.scrollToItem(item);
}));
item.actor.connect('key-focus-in', () => { this.scrollToItem(item); });
this._moveFocusToItems();
......@@ -338,20 +333,17 @@ var SessionMenuButton = new Lang.Class({
Main.uiGroup.add_actor(this._menu.actor);
this._menu.actor.hide();
this._menu.connect('open-state-changed',
Lang.bind(this, function(menu, isOpen) {
if (isOpen)
this._button.add_style_pseudo_class('active');
else
this._button.remove_style_pseudo_class('active');
}));
this._menu.connect('open-state-changed', (menu, isOpen) => {
if (isOpen)
this._button.add_style_pseudo_class('active');
else
this._button.remove_style_pseudo_class('active');
});
this._manager = new PopupMenu.PopupMenuManager({ actor: this._button });
this._manager.addMenu(this._menu);
this._button.connect('clicked', Lang.bind(this, function() {
this._menu.toggle();
}));
this._button.connect('clicked', () => { this._menu.toggle(); });
this._items = {};
this._activeSessionId = null;
......@@ -403,10 +395,10 @@ var SessionMenuButton = new Lang.Class({
this._menu.addMenuItem(item);
this._items[id] = item;
item.connect('activate', Lang.bind(this, function() {
item.connect('activate', () => {
this.setActiveSession(id);
this.emit('session-activated', this._activeSessionId);
}));
});
}
}
});
......@@ -506,17 +498,16 @@ var LoginDialog = new Lang.Class({
this.actor.add_child(this._logoBin);
this._updateLogo();
this._userList.connect('activate',
Lang.bind(this, function(userList, item) {
this._onUserListActivated(item);
}));
this._userList.connect('activate', (userList, item) => {
this._onUserListActivated(item);
});
this._sessionMenuButton = new SessionMenuButton();
this._sessionMenuButton.connect('session-activated',
Lang.bind(this, function(list, sessionId) {
this._greeter.call_select_session_sync (sessionId, null);
}));
(list, sessionId) => {
this._greeter.call_select_session_sync (sessionId, null);
});
this._sessionMenuButton.actor.opacity = 0;
this._sessionMenuButton.actor.show();
this._authPrompt.addActorToDefaultButtonWell(this._sessionMenuButton.actor);
......@@ -724,13 +715,13 @@ var LoginDialog = new Lang.Class({
_ensureUserListLoaded() {
if (!this._userManager.is_loaded) {
this._userManagerLoadedId = this._userManager.connect('notify::is-loaded',
Lang.bind(this, function() {
if (this._userManager.is_loaded) {
this._loadUserList();
this._userManager.disconnect(this._userManagerLoadedId);
this._userManagerLoadedId = 0;
}
}));
() => {
if (this._userManager.is_loaded) {
this._loadUserList();
this._userManager.disconnect(this._userManagerLoadedId);
this._userManagerLoadedId = 0;
}
});
} else {
let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, Lang.bind(this, this._loadUserList));
GLib.Source.set_name_by_id(id, '[gnome-shell] _loadUserList');
......@@ -907,17 +898,17 @@ var LoginDialog = new Lang.Class({
if (this._nextSignalId)
this._authPrompt.disconnect(this._nextSignalId);
this._nextSignalId = this._authPrompt.connect('next',
Lang.bind(this, function() {
this._authPrompt.disconnect(this._nextSignalId);
this._nextSignalId = 0;
this._authPrompt.updateSensitivity(false);
let answer = this._authPrompt.getAnswer();
this._user = this._userManager.get_user(answer);
this._authPrompt.clear();
this._authPrompt.startSpinning();
this._authPrompt.begin({ userName: answer });
this._updateCancelButton();
}));
() => {
this._authPrompt.disconnect(this._nextSignalId);
this._nextSignalId = 0;
this._authPrompt.updateSensitivity(false);
let answer = this._authPrompt.getAnswer();
this._user = this._userManager.get_user(answer);
this._authPrompt.clear();
this._authPrompt.startSpinning();
this._authPrompt.begin({ userName: answer });
this._updateCancelButton();
});
this._updateCancelButton();
this._sessionMenuButton.updateSensitivity(false);
......@@ -952,10 +943,10 @@ var LoginDialog = new Lang.Class({
_gotGreeterSessionProxy(proxy) {
this._greeterSessionProxy = proxy;
this._greeterSessionProxyChangedId =
proxy.connect('g-properties-changed', Lang.bind(this, function() {
proxy.connect('g-properties-changed', () => {
if (proxy.Active)
this._loginScreenSessionActivated();
}));
});
},
_startSession(serviceName) {
......@@ -979,9 +970,7 @@ var LoginDialog = new Lang.Class({
},
_onSessionOpened(client, serviceName) {
this._authPrompt.finish(Lang.bind(this, function() {
this._startSession(serviceName);
}));
this._authPrompt.finish(() => { this._startSession(serviceName); });
},
_waitForItemForUser(userName) {
......@@ -992,16 +981,14 @@ var LoginDialog = new Lang.Class({
let hold = new Batch.Hold();
let signalId = this._userList.connect('item-added',
Lang.bind(this, function() {
let item = this._userList.getItemFromUserName(userName);
() => {
let item = this._userList.getItemFromUserName(userName);
if (item)
hold.release();
}));
if (item)
hold.release();
});
hold.connect('release', Lang.bind(this, function() {
this._userList.disconnect(signalId);
}));
hold.connect('release', () => { this._userList.disconnect(signalId); });
return hold;
},
......@@ -1024,11 +1011,11 @@ var LoginDialog = new Lang.Class({
let hold = new Batch.Hold();
this._timedLoginIdleTimeOutId = Mainloop.timeout_add_seconds(_TIMED_LOGIN_IDLE_THRESHOLD,
function() {
this._timedLoginAnimationTime -= _TIMED_LOGIN_IDLE_THRESHOLD;
hold.release();
return GLib.SOURCE_REMOVE;
});
() => {
this._timedLoginAnimationTime -= _TIMED_LOGIN_IDLE_THRESHOLD;
hold.release();
return GLib.SOURCE_REMOVE;
});
GLib.Source.set_name_by_id(this._timedLoginIdleTimeOutId, '[gnome-shell] this._timedLoginAnimationTime');
return hold;
},
......@@ -1038,15 +1025,13 @@ var LoginDialog = new Lang.Class({
this._timedLoginDelay = delay;
this._timedLoginAnimationTime = delay;
let tasks = [function() {
return this._waitForItemForUser(userName);
},
let tasks = [() => this._waitForItemForUser(userName),
function() {
() => {
this._timedLoginItem = this._userList.getItemFromUserName(userName);
},
function() {
() => {
// If we're just starting out, start on the right
// item.
if (!this._userManager.is_loaded) {
......@@ -1056,13 +1041,13 @@ var LoginDialog = new Lang.Class({
this._blockTimedLoginUntilIdle,
function() {
() => {
this._userList.scrollToItem(this._timedLoginItem);
},
this._showTimedLoginAnimation,
function() {
() => {
this._timedLoginBatch = null;
this._greeter.call_begin_auto_login_sync(userName, null);
}];
......@@ -1090,24 +1075,23 @@ var LoginDialog = new Lang.Class({
_onTimedLoginRequested(client, userName, seconds) {
this._startTimedLogin(userName, seconds);
global.stage.connect('captured-event',
Lang.bind(this, function(actor, event) {
if (this._timedLoginDelay == undefined)
return Clutter.EVENT_PROPAGATE;
if (event.type() == Clutter.EventType.KEY_PRESS ||
event.type() == Clutter.EventType.BUTTON_PRESS) {
if (this._timedLoginBatch) {
this._timedLoginBatch.cancel();
this._timedLoginBatch = null;
}
} else if (event.type() == Clutter.EventType.KEY_RELEASE ||
event.type() == Clutter.EventType.BUTTON_RELEASE) {
this._resetTimedLogin();
}
return Clutter.EVENT_PROPAGATE;
}));
global.stage.connect('captured-event', (actor, event) => {
if (this._timedLoginDelay == undefined)
return Clutter.EVENT_PROPAGATE;
if (event.type() == Clutter.EventType.KEY_PRESS ||
event.type() == Clutter.EventType.BUTTON_PRESS) {
if (this._timedLoginBatch) {
this._timedLoginBatch.cancel();
this._timedLoginBatch = null;
}
} else if (event.type() == Clutter.EventType.KEY_RELEASE ||
event.type() == Clutter.EventType.BUTTON_RELEASE) {
this._resetTimedLogin();
}
return Clutter.EVENT_PROPAGATE;
});
},
_setUserListExpanded(expanded) {
......@@ -1218,25 +1202,25 @@ var LoginDialog = new Lang.Class({
this._updateDisableUserList();
this._userAddedId = this._userManager.connect('user-added',
Lang.bind(this, function(userManager, user) {
this._userList.addUser(user);
this._updateDisableUserList();
}));
(userManager, user) => {
this._userList.addUser(user);
this._updateDisableUserList();
});
this._userRemovedId = this._userManager.connect('user-removed',
Lang.bind(this, function(userManager, user) {
this._userList.removeUser(user);
this._updateDisableUserList();
}));
(userManager, user) => {
this._userList.removeUser(user);
this._updateDisableUserList();
});
this._userChangedId = this._userManager.connect('user-changed',
Lang.bind(this, function(userManager, user) {
if (this._userList.containsUser(user) && user.locked)
this._userList.removeUser(user);
else if (!this._userList.containsUser(user) && !user.locked)
this._userList.addUser(user);
this._updateDisableUserList();
}));
(userManager, user) => {
if (this._userList.containsUser(user) && user.locked)
this._userList.removeUser(user);
else if (!this._userList.containsUser(user) && !user.locked)
this._userList.addUser(user);
this._updateDisableUserList();
});
return GLib.SOURCE_REMOVE;
},
......
......@@ -70,10 +70,10 @@ var Manager = new Lang.Class({
this._realms = {};
this._signalId = this._aggregateProvider.connect('g-properties-changed',
Lang.bind(this, function(proxy, properties) {
if ('Realms' in properties.deep_unpack())
this._reloadRealms();
}));
(proxy, properties) => {
if ('Realms' in properties.deep_unpack())
this._reloadRealms();
});
},
_reloadRealms() {
......@@ -109,11 +109,10 @@ var Manager = new Lang.Class({
this._reloadRealm(realm);
realm.connect('g-properties-changed',
Lang.bind(this, function(proxy, properties) {
if ('Configured' in properties.deep_unpack())
this._reloadRealm(realm);
}));
realm.connect('g-properties-changed', (proxy, properties) => {
if ('Configured' in properties.deep_unpack())
this._reloadRealm(realm);
});
},
_updateLoginFormat() {
......@@ -146,9 +145,7 @@ var Manager = new Lang.Class({
Service(Gio.DBus.system,
'org.freedesktop.realmd',
'/org/freedesktop/realmd',
function(service) {
service.ReleaseRemote();
});
service => { service.ReleaseRemote(); });
this._aggregateProvider.disconnect(this._signalId);
this._realms = { };
this._updateLoginFormat();
......
......@@ -230,11 +230,10 @@ var ShellUserVerifier = new Lang.Class({
if (!this.hasPendingMessages) {
this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
} else {
let signalId = this.connect('no-more-messages',
Lang.bind(this, function() {
this.disconnect(signalId);
this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
}));
let signalId = this.connect('no-more-messages', () => {
this.disconnect(signalId);
this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
});
}
},
......@@ -268,11 +267,11 @@ var ShellUserVerifier = new Lang.Class({
this._messageQueueTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
message.interval,
Lang.bind(this, function() {
() => {
this._messageQueueTimeoutId = 0;
this._queueMessageTimeout();
return GLib.SOURCE_REMOVE;
}));
});
GLib.Source.set_name_by_id(this._messageQueueTimeoutId, '[gnome-shell] this._queueMessageTimeout');
},
......@@ -303,13 +302,13 @@ var ShellUserVerifier = new Lang.Class({
return;
}
this._fprintManager.GetDefaultDeviceRemote(Gio.DBusCallFlags.NONE, this._cancellable, Lang.bind(this,
function(device, error) {
this._fprintManager.GetDefaultDeviceRemote(Gio.DBusCallFlags.NONE, this._cancellable,