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() {}). https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
This commit is contained in:

committed by
Florian Müllner

parent
76f09b1e49
commit
213e38c2ef
@ -189,19 +189,19 @@ var LanguageSelectionPopup = new Lang.Class({
|
||||
for (let i in inputSources) {
|
||||
let is = inputSources[i];
|
||||
|
||||
this.addAction(is.displayName, Lang.bind(this, () => {
|
||||
this.addAction(is.displayName, () => {
|
||||
inputSourceManager.activateInputSource(is, true);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
this.addAction(_("Region & Language Settings"), Lang.bind(this, this._launchSettings));
|
||||
this._capturedEventId = 0;
|
||||
|
||||
this._unmapId = actor.connect('notify::mapped', Lang.bind(this, function() {
|
||||
this._unmapId = actor.connect('notify::mapped', () => {
|
||||
if (!actor.is_mapped())
|
||||
this.close(true);
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_launchSettings() {
|
||||
@ -304,7 +304,7 @@ var Key = new Lang.Class({
|
||||
if (key == this.key) {
|
||||
this._pressTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
||||
KEY_LONG_PRESS_TIME,
|
||||
Lang.bind(this, function() {
|
||||
() => {
|
||||
this._longPress = true;
|
||||
this._pressTimeoutId = 0;
|
||||
|
||||
@ -319,7 +319,7 @@ var Key = new Lang.Class({
|
||||
}
|
||||
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@ -358,10 +358,10 @@ var Key = new Lang.Class({
|
||||
this._boxPointer.show(BoxPointer.PopupAnimation.FULL);
|
||||
this._capturedEventId = global.stage.connect('captured-event',
|
||||
Lang.bind(this, this._onCapturedEvent));
|
||||
this._unmapId = this.keyButton.connect('notify::mapped', Lang.bind(this, function() {
|
||||
this._unmapId = this.keyButton.connect('notify::mapped', () => {
|
||||
if (!this.keyButton.is_mapped())
|
||||
this._hideSubkeys();
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_hideSubkeys() {
|
||||
@ -384,45 +384,42 @@ var Key = new Lang.Class({
|
||||
style_class: 'keyboard-key' });
|
||||
|
||||
button.keyWidth = 1;
|
||||
button.connect('button-press-event', Lang.bind(this,
|
||||
function () {
|
||||
button.connect('button-press-event', () => {
|
||||
this._press(key);
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
});
|
||||
button.connect('button-release-event', () => {
|
||||
this._release(key);
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
});
|
||||
button.connect('touch-event', (actor, event) => {
|
||||
let device = event.get_device();
|
||||
let sequence = event.get_event_sequence();
|
||||
|
||||
// We only handle touch events here on wayland. On X11
|
||||
// we do get emulated pointer events, which already works
|
||||
// for single-touch cases. Besides, the X11 passive touch grab
|
||||
// set up by Mutter will make us see first the touch events
|
||||
// and later the pointer events, so it will look like two
|
||||
// unrelated series of events, we want to avoid double handling
|
||||
// in these cases.
|
||||
if (!Meta.is_wayland_compositor())
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
|
||||
if (!this._touchPressed &&
|
||||
event.type() == Clutter.EventType.TOUCH_BEGIN) {
|
||||
device.sequence_grab(sequence, actor);
|
||||
this._touchPressed = true;
|
||||
this._press(key);
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
}));
|
||||
button.connect('button-release-event', Lang.bind(this,
|
||||
function () {
|
||||
} else if (this._touchPressed &&
|
||||
event.type() == Clutter.EventType.TOUCH_END &&
|
||||
device.sequence_get_grabbed_actor(sequence) == actor) {
|
||||
device.sequence_ungrab(sequence);
|
||||
this._touchPressed = false;
|
||||
this._release(key);
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
}));
|
||||
button.connect('touch-event', Lang.bind(this,
|
||||
function (actor, event) {
|
||||
let device = event.get_device();
|
||||
let sequence = event.get_event_sequence();
|
||||
|
||||
// We only handle touch events here on wayland. On X11
|
||||
// we do get emulated pointer events, which already works
|
||||
// for single-touch cases. Besides, the X11 passive touch grab
|
||||
// set up by Mutter will make us see first the touch events
|
||||
// and later the pointer events, so it will look like two
|
||||
// unrelated series of events, we want to avoid double handling
|
||||
// in these cases.
|
||||
if (!Meta.is_wayland_compositor())
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
|
||||
if (!this._touchPressed &&
|
||||
event.type() == Clutter.EventType.TOUCH_BEGIN) {
|
||||
device.sequence_grab(sequence, actor);
|
||||
this._touchPressed = true;
|
||||
this._press(key);
|
||||
} else if (this._touchPressed &&
|
||||
event.type() == Clutter.EventType.TOUCH_END &&
|
||||
device.sequence_get_grabbed_actor(sequence) == actor) {
|
||||
device.sequence_ungrab(sequence);
|
||||
this._touchPressed = false;
|
||||
this._release(key);
|
||||
}
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
}));
|
||||
}
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
});
|
||||
|
||||
return button;
|
||||
},
|
||||
@ -513,8 +510,8 @@ var Keyboard = new Lang.Class({
|
||||
this._lastDeviceId = null;
|
||||
this._suggestions = null;
|
||||
|
||||
Meta.get_backend().connect('last-device-changed', Lang.bind(this,
|
||||
function (backend, deviceId) {
|
||||
Meta.get_backend().connect('last-device-changed',
|
||||
(backend, deviceId) => {
|
||||
let manager = Clutter.DeviceManager.get_default();
|
||||
let device = manager.get_device(deviceId);
|
||||
|
||||
@ -522,26 +519,26 @@ var Keyboard = new Lang.Class({
|
||||
this._lastDeviceId = deviceId;
|
||||
this._syncEnabled();
|
||||
}
|
||||
}));
|
||||
});
|
||||
this._syncEnabled();
|
||||
|
||||
this._showIdleId = 0;
|
||||
|
||||
this._keyboardVisible = false;
|
||||
Main.layoutManager.connect('keyboard-visible-changed', Lang.bind(this, function(o, visible) {
|
||||
Main.layoutManager.connect('keyboard-visible-changed', (o, visible) => {
|
||||
this._keyboardVisible = visible;
|
||||
}));
|
||||
});
|
||||
this._keyboardRequested = false;
|
||||
this._keyboardRestingId = 0;
|
||||
|
||||
Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._relayout));
|
||||
//Main.inputMethod.connect('cursor-location-changed', Lang.bind(this, function(o, rect) {
|
||||
//Main.inputMethod.connect('cursor-location-changed', (o, rect) => {
|
||||
// if (this._keyboardVisible) {
|
||||
// let currentWindow = global.screen.get_display().focus_window;
|
||||
// this.setCursorLocation(currentWindow, rect.get_x(), rect.get_y(),
|
||||
// rect.get_width(), rect.get_height());
|
||||
// }
|
||||
//}));
|
||||
//});
|
||||
},
|
||||
|
||||
get visible() {
|
||||
@ -568,7 +565,7 @@ var Keyboard = new Lang.Class({
|
||||
GLib.source_remove(this._updateCaretPositionId);
|
||||
if (!this._keyboardRequested)
|
||||
return;
|
||||
this._updateCaretPositionId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, Lang.bind(this, function() {
|
||||
this._updateCaretPositionId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
|
||||
this._updateCaretPositionId = 0;
|
||||
|
||||
let currentWindow = global.screen.get_display().focus_window;
|
||||
@ -595,7 +592,7 @@ var Keyboard = new Lang.Class({
|
||||
}
|
||||
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}));
|
||||
});
|
||||
|
||||
GLib.Source.set_name_by_id(this._updateCaretPositionId, '[gnome-shell] this._updateCaretPosition');
|
||||
},
|
||||
@ -694,9 +691,9 @@ var Keyboard = new Lang.Class({
|
||||
this._current_page = null;
|
||||
|
||||
this._suggestions = new Suggestions();
|
||||
this._suggestions.connect('suggestion-clicked', Lang.bind(this, function(suggestions, str) {
|
||||
this._suggestions.connect('suggestion-clicked', (suggestions, str) => {
|
||||
this._keyboardController.commitString(str);
|
||||
}));
|
||||
});
|
||||
this.actor.add(this._suggestions.actor,
|
||||
{ x_align: St.Align.MIDDLE,
|
||||
x_fill: false });
|
||||
@ -734,11 +731,10 @@ var Keyboard = new Lang.Class({
|
||||
}
|
||||
|
||||
if (!this._showIdleId) {
|
||||
this._showIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE,
|
||||
Lang.bind(this, function() {
|
||||
this.show(Main.layoutManager.focusIndex);
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}));
|
||||
this._showIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
|
||||
this.show(Main.layoutManager.focusIndex);
|
||||
return GLib.SOURCE_REMOVE;
|
||||
});
|
||||
GLib.Source.set_name_by_id(this._showIdleId, '[gnome-shell] this.show');
|
||||
}
|
||||
},
|
||||
@ -782,7 +778,7 @@ var Keyboard = new Lang.Class({
|
||||
if (button.key == ' ')
|
||||
button.setWidth(keys.length <= 3 ? 5 : 3);
|
||||
|
||||
button.connect('pressed', Lang.bind(this, function(actor, keyval, str) {
|
||||
button.connect('pressed', (actor, keyval, str) => {
|
||||
if (!Main.inputMethod.currentFocus ||
|
||||
!this._keyboardController.commitString(str, true)) {
|
||||
if (keyval != 0) {
|
||||
@ -790,8 +786,8 @@ var Keyboard = new Lang.Class({
|
||||
button._keyvalPress = true;
|
||||
}
|
||||
}
|
||||
}));
|
||||
button.connect('released', Lang.bind(this, function(actor, keyval, str) {
|
||||
});
|
||||
button.connect('released', (actor, keyval, str) => {
|
||||
if (keyval != 0) {
|
||||
if (button._keyvalPress)
|
||||
this._keyboardController.keyvalRelease(keyval);
|
||||
@ -800,7 +796,7 @@ var Keyboard = new Lang.Class({
|
||||
|
||||
if (!this._latched)
|
||||
this._setActiveLayer(0);
|
||||
}));
|
||||
});
|
||||
|
||||
layout.appendKey(button.actor, button.keyButton.keyWidth);
|
||||
}
|
||||
@ -833,7 +829,7 @@ var Keyboard = new Lang.Class({
|
||||
|
||||
let actor = extraButton.keyButton;
|
||||
|
||||
extraButton.connect('pressed', Lang.bind(this, function() {
|
||||
extraButton.connect('pressed', () => {
|
||||
if (switchToLevel != null) {
|
||||
this._setActiveLayer(switchToLevel);
|
||||
// Shift only gets latched on long press
|
||||
@ -841,23 +837,23 @@ var Keyboard = new Lang.Class({
|
||||
} else if (keyval != null) {
|
||||
this._keyboardController.keyvalPress(keyval);
|
||||
}
|
||||
}));
|
||||
extraButton.connect('released', Lang.bind(this, function() {
|
||||
});
|
||||
extraButton.connect('released', () => {
|
||||
if (keyval != null)
|
||||
this._keyboardController.keyvalRelease(keyval);
|
||||
else if (action == 'hide')
|
||||
this.hide();
|
||||
else if (action == 'languageMenu')
|
||||
this._popupLanguageMenu(actor);
|
||||
}));
|
||||
});
|
||||
|
||||
if (switchToLevel == 0) {
|
||||
layout.shiftKeys.push(extraButton);
|
||||
} else if (switchToLevel == 1) {
|
||||
extraButton.connect('long-press', Lang.bind(this, function() {
|
||||
extraButton.connect('long-press', () => {
|
||||
this._latched = true;
|
||||
this._setCurrentLevelLatched(this._current_page, this._latched);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/* Fixup default keys based on the number of levels/keys */
|
||||
@ -1019,11 +1015,11 @@ var Keyboard = new Lang.Class({
|
||||
this._clearKeyboardRestTimer();
|
||||
this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
||||
KEYBOARD_REST_TIME,
|
||||
Lang.bind(this, function() {
|
||||
() => {
|
||||
this._clearKeyboardRestTimer();
|
||||
this._show(monitor);
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}));
|
||||
});
|
||||
GLib.Source.set_name_by_id(this._keyboardRestingId, '[gnome-shell] this._clearKeyboardRestTimer');
|
||||
},
|
||||
|
||||
@ -1051,11 +1047,11 @@ var Keyboard = new Lang.Class({
|
||||
this._clearKeyboardRestTimer();
|
||||
this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
||||
KEYBOARD_REST_TIME,
|
||||
Lang.bind(this, function() {
|
||||
() => {
|
||||
this._clearKeyboardRestTimer();
|
||||
this._hide();
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}));
|
||||
});
|
||||
GLib.Source.set_name_by_id(this._keyboardRestingId, '[gnome-shell] this._clearKeyboardRestTimer');
|
||||
},
|
||||
|
||||
@ -1177,7 +1173,9 @@ var KeyboardController = new Lang.Class({
|
||||
|
||||
Main.inputMethod.connect('notify::content-purpose', Lang.bind(this, this._onContentPurposeHintsChanged));
|
||||
Main.inputMethod.connect('notify::content-hints', Lang.bind(this, this._onContentPurposeHintsChanged));
|
||||
Main.inputMethod.connect('input-panel-state', Lang.bind(this, function(o, state) { this.emit('panel-state', state); }));
|
||||
Main.inputMethod.connect('input-panel-state', (o, state) => {
|
||||
this.emit('panel-state', state);
|
||||
});
|
||||
},
|
||||
|
||||
_onSourcesModified() {
|
||||
|
Reference in New Issue
Block a user