Commit e2f6f6b4 authored by Florian Müllner's avatar Florian Müllner
Browse files

cleanup: Get rid of Lang.bind()

After replacing Lang.Class with ES6 classes and adopting arrow notation
for anonymous callbacks, we only use the Lang module to bind `this` to
named callbacks. However since ES5, this functionality is already provided
by Function.prototype.bind() - in fact, Lang.bind() itself uses it when
no extra arguments are specified. Just use the built-in function directly
where possible, and use arrow notation in the few places where we pass
additional arguments.
parent e611aa32
Pipeline #777 passed with stage
in 3 minutes and 18 seconds
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Signals = imports.signals;
const Tp = imports.gi.TelepathyGLib;
......@@ -16,7 +15,7 @@ var AccountsMonitor = class {
this._app = Gio.Application.get_default();
this._app.connect('prepare-shutdown',
Lang.bind(this, this._onPrepareShutdown));
this._onPrepareShutdown.bind(this));
this._accountManager = Tp.AccountManager.dup();
......@@ -26,8 +25,7 @@ var AccountsMonitor = class {
factory.add_contact_features([Tp.ContactFeature.ALIAS]);
this._preparedCallbacks = [];
this._accountManager.prepare_async(null,
Lang.bind(this, this._onPrepared));
this._accountManager.prepare_async(null, this._onPrepared.bind(this));
}
get accounts() {
......@@ -75,7 +73,7 @@ var AccountsMonitor = class {
return; // no point in carrying on
}
am.dup_valid_accounts().forEach(Lang.bind(this, this._addAccount));
am.dup_valid_accounts().forEach(this._addAccount.bind(this));
am.connect('account-validity-changed', (am, account, valid) => {
if (valid)
......@@ -86,10 +84,8 @@ var AccountsMonitor = class {
am.connect('account-removed', (am, account) => {
this._removeAccount(account);
});
am.connect('account-enabled',
Lang.bind(this, this._accountEnabledChanged));
am.connect('account-disabled',
Lang.bind(this, this._accountEnabledChanged));
am.connect('account-enabled', this._accountEnabledChanged.bind(this));
am.connect('account-disabled', this._accountEnabledChanged.bind(this));
this._preparedCallbacks.forEach(callback => { callback(); });
}
......
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Pango = imports.gi.Pango;
......@@ -16,7 +15,7 @@ class AppNotification extends Gtk.Revealer {
super._init({ reveal_child: true,
transition_type: Gtk.RevealerTransitionType.SLIDE_DOWN });
this.connect('notify::child-revealed',
Lang.bind(this, this._onChildRevealed));
this._onChildRevealed.bind(this));
}
close() {
......@@ -34,7 +33,7 @@ class MessageNotification extends AppNotification {
_init(label, iconName) {
super._init();
Mainloop.timeout_add_seconds(TIMEOUT, Lang.bind(this, this.close));
Mainloop.timeout_add_seconds(TIMEOUT, this.close.bind(this));
this._box = new Gtk.Box({ spacing: 12 });
......@@ -46,7 +45,7 @@ class MessageNotification extends AppNotification {
let closeButton = new Gtk.Button({ relief: Gtk.ReliefStyle.NONE });
closeButton.image = new Gtk.Image({ icon_name: 'window-close-symbolic' });
closeButton.connect('clicked', Lang.bind(this, this.close));
closeButton.connect('clicked', this.close.bind(this));
this._box.pack_end(closeButton, false, false, 0);
this.add(this._box);
......@@ -100,7 +99,7 @@ class CommandOutputNotification extends AppNotification {
this.transition_type = Gtk.RevealerTransitionType.SLIDE_UP;
Mainloop.timeout_add_seconds(COMMAND_OUTPUT_REVEAL_TIME,
Lang.bind(this, this.close));
this.close.bind(this));
}
});
......@@ -165,7 +164,7 @@ class NotificationQueue extends Gtk.Frame {
addNotification(notification) {
this._grid.add(notification);
notification.connect('destroy', Lang.bind(this, this._onChildDestroy));
notification.connect('destroy', this._onChildDestroy.bind(this));
this.show();
}
......
......@@ -3,7 +3,6 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Polari = imports.gi.Polari;
const Tp = imports.gi.TelepathyGLib;
......@@ -151,38 +150,38 @@ var Application = GObject.registerClass({
let actionEntries = [
{ name: 'show-join-dialog',
activate: Lang.bind(this, this._onShowJoinDialog),
activate: this._onShowJoinDialog.bind(this),
accels: ['<Primary>n'] },
{ name: 'join-room',
activate: Lang.bind(this, this._onJoinRoom),
activate: this._onJoinRoom.bind(this),
parameter_type: GLib.VariantType.new('(ssu)') },
{ name: 'message-user',
activate: Lang.bind(this, this._onMessageUser),
activate: this._onMessageUser.bind(this),
parameter_type: GLib.VariantType.new('(sssu)') },
{ name: 'leave-room',
parameter_type: GLib.VariantType.new('(ss)') },
{ name: 'leave-current-room',
activate: Lang.bind(this, this._onLeaveCurrentRoom),
activate: this._onLeaveCurrentRoom.bind(this),
create_hook: (a) => { a.enabled = false; },
accels: ['<Primary>w'] },
{ name: 'authenticate-account',
parameter_type: GLib.VariantType.new('(os)') },
{ name: 'connect-account',
activate: Lang.bind(this, this._onConnectAccount),
activate: this._onConnectAccount.bind(this),
parameter_type: GLib.VariantType.new('o') },
{ name: 'reconnect-account',
activate: Lang.bind(this, this._onConnectAccount),
activate: this._onConnectAccount.bind(this),
parameter_type: GLib.VariantType.new('o') },
{ name: 'user-list',
activate: Lang.bind(this, this._onToggleAction),
create_hook: Lang.bind(this, this._userListCreateHook),
activate: this._onToggleAction.bind(this),
create_hook: this._userListCreateHook.bind(this),
state: GLib.Variant.new('b', false),
accels: ['F9', '<Primary>u'] },
{ name: 'remove-connection',
activate: Lang.bind(this, this._onRemoveConnection),
activate: this._onRemoveConnection.bind(this),
parameter_type: GLib.VariantType.new('o') },
{ name: 'edit-connection',
activate: Lang.bind(this, this._onEditConnection),
activate: this._onEditConnection.bind(this),
parameter_type: GLib.VariantType.new('o') },
{ name: 'save-identify-password',
parameter_type: GLib.VariantType.new('o') },
......@@ -191,14 +190,14 @@ var Application = GObject.registerClass({
{ name: 'show-emoji-picker',
accels: ['<Primary>e'] },
{ name: 'start-client',
activate: Lang.bind(this, this._onStartClient) },
activate: this._onStartClient.bind(this) },
{ name: 'help',
activate: Lang.bind(this, this._onShowHelp),
activate: this._onShowHelp.bind(this),
accels: ['F1'] },
{ name: 'about',
activate: Lang.bind(this, this._onShowAbout) },
activate: this._onShowAbout.bind(this) },
{ name: 'quit',
activate: Lang.bind(this, this._onQuit),
activate: this._onQuit.bind(this),
accels: ['<Primary>q'] },
{ name: 'next-room',
accels: ['<Primary>Page_Down', '<Alt>Down'] },
......@@ -239,7 +238,7 @@ var Application = GObject.registerClass({
this.add_action(action);
this._settings.connect('changed::run-in-background',
Lang.bind(this, this._onRunInBackgroundChanged));
this._onRunInBackgroundChanged.bind(this));
this._onRunInBackgroundChanged();
for (let i = 1; i < 10; i++)
......@@ -254,7 +253,7 @@ var Application = GObject.registerClass({
this._serverRoomManager = ServerRoomManager.getDefault();
this._accountsMonitor.connect('account-status-changed',
Lang.bind(this, this._onAccountStatusChanged));
this._onAccountStatusChanged.bind(this));
this._accountsMonitor.connect('account-added', (am, account) => {
// Reset nickname at startup
let accountName = this._getTrimmedAccountName(account);
......@@ -321,7 +320,7 @@ var Application = GObject.registerClass({
action.enabled = window.active_room != null;
window.connect('active-room-state-changed',
Lang.bind(this, this._updateUserListAction));
this._updateUserListAction.bind(this));
this._updateUserListAction();
}
......
......@@ -3,7 +3,6 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Pango = imports.gi.Pango;
const PangoCairo = imports.gi.PangoCairo;
......@@ -51,8 +50,8 @@ class TextView extends Gtk.TextView {
_init(params) {
super._init(params);
this.buffer.connect('mark-set', Lang.bind(this, this._onMarkSet));
this.connect('screen-changed', Lang.bind(this, this._updateLayout));
this.buffer.connect('mark-set', this._onMarkSet.bind(this));
this.connect('screen-changed', this._updateLayout.bind(this));
}
vfunc_get_preferred_width() {
......@@ -310,36 +309,33 @@ var ChatView = GObject.registerClass({
this._createTags();
this.connect('style-updated',
Lang.bind(this, this._onStyleUpdated));
this.connect('style-updated', this._onStyleUpdated.bind(this));
this._onStyleUpdated();
this.connect('destroy', Lang.bind(this, this._onDestroy));
this.connect('screen-changed',
Lang.bind(this, this._updateIndent));
this.connect('scroll-event', Lang.bind(this, this._onScroll));
this.connect('destroy', this._onDestroy.bind(this));
this.connect('screen-changed', this._updateIndent.bind(this));
this.connect('scroll-event', this._onScroll.bind(this));
this.connect('edge-reached', (w, pos) => {
if (pos == Gtk.PositionType.BOTTOM)
this._autoscroll = true;
});
this.vadjustment.connect('value-changed',
Lang.bind(this, this._onValueChanged));
this.vadjustment.connect('changed',
Lang.bind(this, this._updateScroll));
this._onValueChanged.bind(this));
this.vadjustment.connect('changed', this._updateScroll.bind(this));
this._view.connect('key-press-event', Lang.bind(this, this._onKeyPress));
this._view.connect('key-press-event', this._onKeyPress.bind(this));
this._view.connect('motion-notify-event',
Lang.bind(this, this._handleButtonTagsHover));
this._handleButtonTagsHover.bind(this));
this._view.connect('enter-notify-event',
Lang.bind(this, this._handleButtonTagsHover));
this._handleButtonTagsHover.bind(this));
this._view.connect('leave-notify-event',
Lang.bind(this, this._handleButtonTagsHover));
this._handleButtonTagsHover.bind(this));
/* pick up DPI changes (e.g. via the 'text-scaling-factor' setting):
the default handler calls pango_cairo_context_set_resolution(), so
update the indent after that */
this._view.connect_after('style-updated',
Lang.bind(this, this._updateIndent));
this._updateIndent.bind(this));
this._room = room;
this._state = { lastNick: null, lastTimestamp: 0, lastStatusGroup: 0 };
......@@ -372,7 +368,7 @@ var ChatView = GObject.registerClass({
this._fetchingBacklog = true;
this._logWalker.get_events_async(NUM_INITIAL_LOG_EVENTS,
Lang.bind(this, this._onLogEventsReady));
this._onLogEventsReady.bind(this));
this._autoscroll = true;
......@@ -380,7 +376,7 @@ var ChatView = GObject.registerClass({
DropTargetIface.addTargets(this, this._view);
this._app.connect('room-focus-changed',
Lang.bind(this, this._checkMessages));
this._checkMessages.bind(this));
this._hoverCursor = Gdk.Cursor.new_from_name(this.get_display(),
'pointer');
......@@ -390,19 +386,19 @@ var ChatView = GObject.registerClass({
let roomSignals = [
{ name: 'notify::channel',
handler: Lang.bind(this, this._onChannelChanged) },
handler: this._onChannelChanged.bind(this) },
{ name: 'member-renamed',
handler: Lang.bind(this, this._onMemberRenamed) },
handler: this._onMemberRenamed.bind(this) },
{ name: 'member-disconnected',
handler: Lang.bind(this, this._onMemberDisconnected) },
handler: this._onMemberDisconnected.bind(this) },
{ name: 'member-kicked',
handler: Lang.bind(this, this._onMemberKicked) },
handler: this._onMemberKicked.bind(this) },
{ name: 'member-banned',
handler: Lang.bind(this, this._onMemberBanned) },
handler: this._onMemberBanned.bind(this) },
{ name: 'member-joined',
handler: Lang.bind(this, this._onMemberJoined) },
handler: this._onMemberJoined.bind(this) },
{ name: 'member-left',
handler: Lang.bind(this, this._onMemberLeft) }
handler: this._onMemberLeft.bind(this) }
];
this._roomSignals = [];
roomSignals.forEach(signal => {
......@@ -412,7 +408,7 @@ var ChatView = GObject.registerClass({
this._nickStatusChangedId = this._userTracker.watchRoomStatus(this._room,
null,
Lang.bind(this, this._onNickStatusChanged));
this._onNickStatusChanged.bind(this));
this.connect('destroy', () => {
this._userTracker.unwatchRoomStatus(this._room, this._nickStatusChangedId);
......@@ -731,7 +727,7 @@ var ChatView = GObject.registerClass({
this._showLoadingIndicator();
this._backlogTimeoutId = Mainloop.timeout_add(500, () => {
this._logWalker.get_events_async(NUM_LOG_EVENTS,
Lang.bind(this, this._onLogEventsReady));
this._onLogEventsReady.bind(this));
this._backlogTimeoutId = 0;
return GLib.SOURCE_REMOVE;
});
......@@ -927,11 +923,11 @@ var ChatView = GObject.registerClass({
let channelSignals = [
{ name: 'message-received',
handler: Lang.bind(this, this._onMessageReceived) },
handler: this._onMessageReceived.bind(this) },
{ name: 'message-sent',
handler: Lang.bind(this, this._onMessageSent) },
handler: this._onMessageSent.bind(this) },
{ name: 'pending-message-removed',
handler: Lang.bind(this, this._pendingMessageRemoved) }
handler: this._pendingMessageRemoved.bind(this) }
];
channelSignals.forEach(signal => {
this._channelSignals.push(this._channel.connect(signal.name, signal.handler));
......@@ -1244,7 +1240,7 @@ var ChatView = GObject.registerClass({
if (!nickTag) {
nickTag = new ButtonTag({ name: nickTagName });
nickTag.connect('clicked', Lang.bind(this, this._onNickTagClicked));
nickTag.connect('clicked', this._onNickTagClicked.bind(this));
let status = this._userTracker.getNickRoomStatus(message.nick, this._room);
this._updateNickTag(nickTag, status);
......
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Tp = imports.gi.TelepathyGLib;
const {AccountsMonitor} = imports.accountsMonitor;
......@@ -88,16 +87,15 @@ var ConnectionsList = GObject.registerClass({
this.hscrollbar_policy = Gtk.PolicyType.NEVER;
this._list = new Gtk.ListBox({ visible: true });
this._list.connect('row-activated',
Lang.bind(this, this._onRowActivated));
this._list.connect('row-activated', this._onRowActivated.bind(this));
this.add(this._list);
this._rows = new Map();
this._filterTerms = [];
this._list.set_filter_func(Lang.bind(this, this._filterRows));
this._list.set_header_func(Lang.bind(this, this._updateHeader));
this._list.set_sort_func(Lang.bind(this, this._sort));
this._list.set_filter_func(this._filterRows.bind(this));
this._list.set_header_func(this._updateHeader.bind(this));
this._list.set_sort_func(this._sort.bind(this));
let placeholder = new Gtk.Box({ halign: Gtk.Align.CENTER,
valign: Gtk.Align.CENTER,
......@@ -123,7 +121,7 @@ var ConnectionsList = GObject.registerClass({
this._networksManager = NetworksManager.getDefault();
this._networksManager.connect('changed',
Lang.bind(this, this._networksChanged));
this._networksChanged.bind(this));
this._networksChanged();
}
......@@ -273,15 +271,15 @@ var ConnectionDetails = GObject.registerClass({
super._init(params);
this._nameEntry.connect('changed',
Lang.bind(this, this._onCanConfirmChanged));
this._onCanConfirmChanged.bind(this));
this._serverEntry.connect('changed',
Lang.bind(this, this._onCanConfirmChanged));
this._onCanConfirmChanged.bind(this));
this._nickEntry.connect('changed',
Lang.bind(this, this._onCanConfirmChanged));
this._onCanConfirmChanged.bind(this));
this._realnameEntry.connect('changed',
Lang.bind(this, this._onCanConfirmChanged));
this._onCanConfirmChanged.bind(this));
this._sslCheckbox.connect('toggled',
Lang.bind(this, this._onCanConfirmChanged));
this._onCanConfirmChanged.bind(this));
let realnameStore = new Gtk.ListStore();
realnameStore.set_column_types([GObject.TYPE_STRING]);
......@@ -501,7 +499,7 @@ var ConnectionProperties = GObject.registerClass({
this.set_default_response(Gtk.ResponseType.OK);
account.connect('notify::connection-status',
Lang.bind(this, this._syncErrorMessage));
this._syncErrorMessage.bind(this));
this._syncErrorMessage(account);
}
......
......@@ -2,7 +2,6 @@ const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const modifierBlacklist = [
'child',
......@@ -212,7 +211,7 @@ var EmojiPicker = GObject.registerClass({
});
this._adjustment.connect('value-changed',
Lang.bind(this, this._updateIndicators));
this._updateIndicators.bind(this));
this.connect('map', () => {
entry.text = '';
......
......@@ -5,7 +5,6 @@ const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gspell = imports.gi.Gspell;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Tp = imports.gi.TelepathyGLib;
......@@ -48,7 +47,7 @@ var ChatEntry = GObject.registerClass({
this._emojiPickedId = 0;
this.connect('icon-press', Lang.bind(this, this._showEmojiPicker));
this.connect('icon-press', this._showEmojiPicker.bind(this));
this.connect('unmap', () => {
if (this._emojiPickedId)
ChatEntry._emojiPicker.disconnect(this._emojiPickedId);
......@@ -57,7 +56,7 @@ var ChatEntry = GObject.registerClass({
let app = Gio.Application.get_default();
let action = app.lookup_action('show-emoji-picker');
action.connect('activate', Lang.bind(this, this._showEmojiPicker));
action.connect('activate', this._showEmojiPicker.bind(this));
let buffer = Gspell.EntryBuffer.get_from_gtk_entry_buffer(this.buffer);
buffer.set_spell_checker (ChatEntry._checker);
......@@ -112,7 +111,7 @@ var ChatEntry = GObject.registerClass({
if (uris && uris.length)
this.emit('file-pasted', Gio.File.new_for_uri(uris[0]));
else
clipboard.request_text(Lang.bind(this, this._onTextReceived));
clipboard.request_text(this._onTextReceived.bind(this));
});
clipboard.request_image((clipboard, pixbuf) => {
......@@ -219,12 +218,12 @@ var EntryArea = GObject.registerClass({
super._init(params);
this.connect('destroy', Lang.bind(this, this._onDestroy));
this.connect('notify::sensitive', Lang.bind(this, this._onSensitiveChanged));
this.connect('destroy', this._onDestroy.bind(this));
this.connect('notify::sensitive', this._onSensitiveChanged.bind(this));
this.connect('realize', () => {
this._toplevel = this.get_toplevel();
this._keyPressId = this._toplevel.connect('key-press-event',
Lang.bind(this, this._onKeyPressEvent));
this._onKeyPressEvent.bind(this));
});
this.connect('map', () => {
this._nickButton.popover = EntryArea._nickPopover;
......@@ -280,7 +279,7 @@ var EntryArea = GObject.registerClass({
this.pasteFile(file);
});
this._chatEntry.connect('changed', Lang.bind(this, this._onEntryChanged));
this._chatEntry.connect('changed', this._onEntryChanged.bind(this));
this._chatEntry.connect('activate', () => {
if (this._ircParser.process(this._chatEntry.text)) {
......@@ -291,8 +290,8 @@ var EntryArea = GObject.registerClass({
}
});
this._cancelButton.connect('clicked', Lang.bind(this, this._onCancelClicked));
this._pasteButton.connect('clicked', Lang.bind(this, this._onPasteClicked));
this._cancelButton.connect('clicked', this._onCancelClicked.bind(this));
this._pasteButton.connect('clicked', this._onPasteClicked.bind(this));
this._pasteBox.connect_after('key-press-event', (w, event) => {
let [, keyval] = event.get_keyval();
......@@ -312,7 +311,7 @@ var EntryArea = GObject.registerClass({
this._completion = new TabCompletion(this._chatEntry);
this._membersChangedId =
this._room.connect('members-changed',
Lang.bind(this, this._updateCompletions));
this._updateCompletions.bind(this));
this._nicknameChangedId =
this._room.account.connect('notify::nickname', () => {
if (!this._room.channel)
......@@ -320,11 +319,11 @@ var EntryArea = GObject.registerClass({
});
this._channelChangedId =
this._room.connect('notify::channel',
Lang.bind(this, this._onChannelChanged));
this._onChannelChanged.bind(this));
this._onChannelChanged(this._room);
this._chatEntry.connect('map', Lang.bind(this, this._updateCompletions));
this._chatEntry.connect('unmap', Lang.bind(this, this._updateCompletions));
this._chatEntry.connect('map', this._updateCompletions.bind(this));
this._chatEntry.connect('unmap', this._updateCompletions.bind(this));
}
set max_nick_chars(maxChars) {
......@@ -418,7 +417,7 @@ var EntryArea = GObject.registerClass({
file.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
Gio.FileQueryInfoFlags.NONE,
GLib.PRIORITY_DEFAULT, null,
Lang.bind(this, this._onFileInfoReady));
this._onFileInfoReady.bind(this));
}
_onFileInfoReady(file, res) {
......@@ -477,7 +476,7 @@ var EntryArea = GObject.registerClass({
if (room.channel)
this._selfAliasChangedId =
room.channel.connection.connect('notify::self-contact',
Lang.bind(this, this._updateNick));
this._updateNick.bind(this));
else
this._selfAliasChangedId = 0;
this._updateNick();
......
......@@ -2,7 +2,6 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Utils = imports.utils;
......@@ -35,7 +34,7 @@ var InitialSetupWindow = GObject.registerClass({
this.connect('destroy', () => { this._unsetAccount(); });
this._serverRoomList.connect('notify::can-join',
Lang.bind(this, this._updateNextSensitivity));
this._updateNextSensitivity.bind(this));
this._nextButton.connect('clicked', () => {
if (this._page == SetupPage.CONNECTION) {
......@@ -58,7 +57,7 @@ var InitialSetupWindow = GObject.registerClass({
this._networkMonitor = Gio.NetworkMonitor.get_default();
this._networkMonitor.connect('notify::network-available',
Lang.bind(this, this._onNetworkAvailableChanged));
this._onNetworkAvailableChanged.bind(this));
this._onNetworkAvailableChanged();
}
......
......@@ -3,7 +3,6 @@ const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const {AccountsMonitor} = imports.accountsMonitor;
const Utils = imports.utils;
......@@ -97,11 +96,11 @@ var JoinDialog = GObject.registerClass({
});
this._connectionCombo.connect('changed',