[polari] cleanup: Use arrow notation for anonymous functions
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] cleanup: Use arrow notation for anonymous functions
- Date: Tue, 11 Apr 2017 00:50:17 +0000 (UTC)
commit 2f3d808916aca81f1ec29e44688c04045ad4bba4
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Mar 15 06:40:30 2017 +0100
cleanup: Use arrow notation for anonymous functions
Arrow notation is great, but as we only started using it recently,
we currently have a wild mix of Lang.bind(this, function() {}),
function() {} and () => {}. To make the style consistent again,
go through the entire codebase and change all anonymous functions
to arrow notation (using /[^:].function/ for identifying them).
https://bugzilla.gnome.org/show_bug.cgi?id=780273
src/accountsMonitor.js | 25 +++---
src/appNotifications.js | 8 +-
src/application.js | 106 +++++++++++------------
src/chatView.js | 122 +++++++++++---------------
src/connections.js | 119 +++++++++++---------------
src/entryArea.js | 216 ++++++++++++++++++++++-------------------------
src/ircParser.js | 53 +++++------
src/joinDialog.js | 131 +++++++++++++----------------
src/mainWindow.js | 31 +++----
src/networksManager.js | 11 +--
src/pasteManager.js | 55 ++++++-------
src/polari-accounts.in | 32 +++----
src/roomList.js | 40 ++++-----
src/roomStack.js | 30 +++----
src/tabCompletion.js | 22 ++---
src/telepathyClient.js | 81 ++++++++---------
src/userList.js | 26 +++---
src/utils.js | 114 ++++++++++++-------------
18 files changed, 553 insertions(+), 669 deletions(-)
---
diff --git a/src/accountsMonitor.js b/src/accountsMonitor.js
index 5ff623b..aa283bd 100644
--- a/src/accountsMonitor.js
+++ b/src/accountsMonitor.js
@@ -82,17 +82,15 @@ const AccountsMonitor = new Lang.Class({
am.dup_valid_accounts().forEach(Lang.bind(this, this._addAccount));
- am.connect('account-validity-changed', Lang.bind(this,
- function(am, account, valid) {
- if (valid)
- this._addAccount(account);
- else
- this._removeAccount(account);
- }));
- am.connect('account-removed', Lang.bind(this,
- function(am, account) {
+ am.connect('account-validity-changed', (am, account, valid) => {
+ if (valid)
+ this._addAccount(account);
+ else
this._removeAccount(account);
- }));
+ });
+ am.connect('account-removed', (am, account) => {
+ this._removeAccount(account);
+ });
am.connect('account-enabled',
Lang.bind(this, this._accountEnabledChanged));
am.connect('account-disabled',
@@ -126,10 +124,9 @@ const AccountsMonitor = new Lang.Class({
return;
account._statusNotifyId =
- account.connect('notify::connection-status', Lang.bind(this,
- function() {
- this.emit('account-status-changed', account);
- }));
+ account.connect('notify::connection-status', () => {
+ this.emit('account-status-changed', account);
+ });
this._accounts.set(account.object_path, account);
this.emit('account-added', account);
diff --git a/src/appNotifications.js b/src/appNotifications.js
index c7eb698..3b98ddd 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -60,11 +60,11 @@ const MessageNotification = new Lang.Class({
addButton: function(label, callback) {
let button = new Gtk.Button({ label: label, visible: true });
- button.connect('clicked', Lang.bind(this, function() {
+ button.connect('clicked', () => {
if (callback)
callback();
this.close();
- }));
+ });
this._box.add(button);
}
@@ -82,9 +82,7 @@ const UndoNotification = new Lang.Class({
this.connect('destroy', Lang.bind(this, this._onDestroy));
- this.addButton(_("Undo"), Lang.bind(this, function() {
- this._undo = true;
- }));
+ this.addButton(_("Undo"), () => { this._undo = true; });
this._app = Gio.Application.get_default();
this._shutdownId = this._app.connect('prepare-shutdown',
diff --git a/src/application.js b/src/application.js
index 734ca48..aad845a 100644
--- a/src/application.js
+++ b/src/application.js
@@ -193,26 +193,24 @@ const Application = new Lang.Class({
{ name: 'previous-pending-room',
accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']}
];
- actionEntries.forEach(Lang.bind(this,
- function(actionEntry) {
- let props = {};
- ['name', 'state', 'parameter_type'].forEach(
- function(prop) {
- if (actionEntry[prop])
- props[prop] = actionEntry[prop];
- });
- let action = new Gio.SimpleAction(props);
- if (actionEntry.create_hook)
- actionEntry.create_hook(action);
- if (actionEntry.activate)
- action.connect('activate', actionEntry.activate);
- if (actionEntry.change_state)
- action.connect('change-state', actionEntry.change_state);
- if (actionEntry.accels)
- this.set_accels_for_action('app.' + actionEntry.name,
- actionEntry.accels);
- this.add_action(action);
- }));
+ actionEntries.forEach(actionEntry => {
+ let props = {};
+ ['name', 'state', 'parameter_type'].forEach(prop => {
+ if (actionEntry[prop])
+ props[prop] = actionEntry[prop];
+ });
+ let action = new Gio.SimpleAction(props);
+ if (actionEntry.create_hook)
+ actionEntry.create_hook(action);
+ if (actionEntry.activate)
+ action.connect('activate', actionEntry.activate);
+ if (actionEntry.change_state)
+ action.connect('change-state', actionEntry.change_state);
+ if (actionEntry.accels)
+ this.set_accels_for_action('app.' + actionEntry.name,
+ actionEntry.accels);
+ this.add_action(action);
+ });
this._settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
let action = this._settings.create_action('run-in-background');
@@ -297,7 +295,7 @@ const Application = new Lang.Class({
this.activate();
let time = Utils.getTpEventTime();
- let uris = files.map(function(f) { return f.get_uri(); });
+ let uris = files.map(f => f.get_uri());
this._accountsMonitor.prepare(() => {
this._openURIs(uris, time);
@@ -316,13 +314,13 @@ const Application = new Lang.Class({
});
let joinAction = this.lookup_action('join-room');
- uris.forEach(Lang.bind(this, function(uri) {
+ uris.forEach(uri => {
let [success, server, port, room] = this._parseURI(uri);
if (!success)
return;
let matchedId = this._networksManager.findByServer(server);
- let matches = Object.keys(map).filter(function(a) {
+ let matches = Object.keys(map).filter(a => {
return GLib.ascii_strcasecmp(map[a].server, server) == 0 ||
map[a].service == matchedId;
});
@@ -331,14 +329,13 @@ const Application = new Lang.Class({
joinAction.activate(new GLib.Variant('(ssu)',
[matches[0], '#' + room, time]));
else
- this._createAccount(matchedId, server, port,
- function(a) {
- if (a)
- joinAction.activate(new GLib.Variant('(ssu)',
+ this._createAccount(matchedId, server, port, a => {
+ if (a)
+ joinAction.activate(new GLib.Variant('(ssu)',
[a.get_object_path(),
'#' + room, time]));
- });
- }));
+ });
+ });
},
_parseURI: function(uri) {
@@ -385,11 +382,10 @@ const Application = new Lang.Class({
for (let prop in params)
req.set_parameter(prop, params[prop]);
- req.create_account_async(Lang.bind(this,
- function(r, res) {
- let account = req.create_account_finish(res);
- callback(account);
- }));
+ req.create_account_async((r, res) => {
+ let account = req.create_account_finish(res);
+ callback(account);
+ });
},
_updateUserListAction: function() {
@@ -399,7 +395,7 @@ const Application = new Lang.Class({
},
_userListCreateHook: function(action) {
- action.connect('notify::enabled', function() {
+ action.connect('notify::enabled', () => {
if (!action.enabled)
action.change_state(GLib.Variant.new('b', false));
});
@@ -553,23 +549,22 @@ const Application = new Lang.Class({
_onRemoveConnection: function(action, parameter){
let accountPath = parameter.deep_unpack();
let account = this._accountsMonitor.lookupAccount(accountPath);
- account.set_enabled_async(false, Lang.bind(this,
- function() {
- let label = _("%s removed.").format(account.display_name);
- let n = new AppNotifications.UndoNotification(label);
- this.notificationQueue.addNotification(n);
-
- n.connect('closed', function() {
- account.remove_async(function(a, res) {
- a.remove_finish(res); // TODO: Check for errors
- });
+ account.set_enabled_async(false, () => {
+ let label = _("%s removed.").format(account.display_name);
+ let n = new AppNotifications.UndoNotification(label);
+ this.notificationQueue.addNotification(n);
+
+ n.connect('closed', () => {
+ account.remove_async((a, res) => {
+ a.remove_finish(res); // TODO: Check for errors
});
- n.connect('undo', function() {
- account.set_enabled_async(true, function(a, res) {
- a.set_enabled_finish(res); // TODO: Check for errors
- });
+ });
+ n.connect('undo', () => {
+ account.set_enabled_async(true, (a, res) => {
+ a.set_enabled_finish(res); // TODO: Check for errors
});
- }));
+ });
+ });
},
_onEditConnection: function(action, parameter) {
@@ -577,10 +572,9 @@ const Application = new Lang.Class({
let account = this._accountsMonitor.lookupAccount(accountPath);
let dialog = new Connections.ConnectionProperties(account);
dialog.transient_for = this.active_window;
- dialog.connect('response', Lang.bind(this,
- function(w, response) {
- w.destroy();
- }));
+ dialog.connect('response', (w, reponse) => {
+ w.destroy();
+ });
dialog.show();
},
@@ -669,10 +663,10 @@ const Application = new Lang.Class({
this._aboutDialog = new Gtk.AboutDialog(aboutParams);
this._aboutDialog.show();
- this._aboutDialog.connect('response', Lang.bind(this, function() {
+ this._aboutDialog.connect('response', () => {
this._aboutDialog.destroy();
this._aboutDialog = null;
- }));
+ });
},
_onQuit: function() {
diff --git a/src/chatView.js b/src/chatView.js
index 870d2e3..5a8131d 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -88,10 +88,10 @@ const TextView = new Lang.Class({
location.x, location.y);
let tags = iter.get_tags();
- let pixelsAbove = tags.reduce(function(prev, current) {
+ let pixelsAbove = tags.reduce((prev, current) => {
return Math.max(prev, current.pixels_above_lines);
}, this.get_pixels_above_lines());
- let pixelsBelow = tags.reduce(function(prev, current) {
+ let pixelsBelow = tags.reduce((prev, current) => {
return Math.max(prev, current.pixels_below_lines);
}, this.get_pixels_below_lines());
@@ -365,10 +365,9 @@ const ChatView = new Lang.Class({
let statusMonitor = UserTracker.getUserStatusMonitor();
this._userTracker = statusMonitor.getUserTrackerForAccount(room.account);
- this._room.account.connect('notify::nickname', Lang.bind(this,
- function() {
- this._updateMaxNickChars(this._room.account.nickname.length);
- }));
+ this._room.account.connect('notify::nickname', () => {
+ this._updateMaxNickChars(this._room.account.nickname.length);
+ });
this._updateMaxNickChars(this._room.account.nickname.length);
let isRoom = room.type == Tp.HandleType.ROOM;
@@ -415,9 +414,9 @@ const ChatView = new Lang.Class({
handler: Lang.bind(this, this._onMemberLeft) }
];
this._roomSignals = [];
- roomSignals.forEach(Lang.bind(this, function(signal) {
+ roomSignals.forEach(signal => {
this._roomSignals.push(room.connect(signal.name, signal.handler));
- }));
+ });
this._onChannelChanged();
this._nickStatusChangedId = this._userTracker.watchRoomStatus(this._room,
@@ -461,9 +460,7 @@ const ChatView = new Lang.Class({
{ name: 'loading',
justification: Gtk.Justification.CENTER }
];
- tags.forEach(function(tagProps) {
- tagTable.add(new Gtk.TextTag(tagProps));
- });
+ tags.forEach(tagProps => { tagTable.add(new Gtk.TextTag(tagProps)); });
},
_onStyleUpdated: function() {
@@ -509,7 +506,7 @@ const ChatView = new Lang.Class({
{ name: 'url',
foreground_rgba: linkColor }
];
- tags.forEach(function(tagProps) {
+ tags.forEach(tagProps => {
let tag = tagTable.lookup(tagProps.name);
for (let prop in tagProps) {
if (prop == 'name')
@@ -740,13 +737,12 @@ const ChatView = new Lang.Class({
this._fetchingBacklog = true;
this._showLoadingIndicator();
- this._backlogTimeoutId = Mainloop.timeout_add(500, Lang.bind(this,
- function() {
- this._logWalker.get_events_async(NUM_LOG_EVENTS,
- Lang.bind(this, this._onLogEventsReady));
- this._backlogTimeoutId = 0;
- return GLib.SOURCE_REMOVE;
- }));
+ this._backlogTimeoutId = Mainloop.timeout_add(500, () => {
+ this._logWalker.get_events_async(NUM_LOG_EVENTS,
+ Lang.bind(this, this._onLogEventsReady));
+ this._backlogTimeoutId = 0;
+ return GLib.SOURCE_REMOVE;
+ });
return Gdk.EVENT_STOP;
},
@@ -754,12 +750,11 @@ const ChatView = new Lang.Class({
if (this._valueChangedId)
return;
- this._valueChangedId = Mainloop.timeout_add(SCROLL_TIMEOUT, Lang.bind(this,
- function() {
- this._checkMessages();
- this._valueChangedId = 0;
- return GLib.SOURCE_REMOVE;
- }));
+ this._valueChangedId = Mainloop.timeout_add(SCROLL_TIMEOUT, () => {
+ this._checkMessages();
+ this._valueChangedId = 0;
+ return GLib.SOURCE_REMOVE;
+ });
},
_pendingMessageRemoved: function(channel, message) {
@@ -782,17 +777,16 @@ const ChatView = new Lang.Class({
let menu = new Gtk.Menu();
let item = new Gtk.MenuItem({ label: _("Open Link") });
- item.connect('activate', function() {
+ item.connect('activate', () => {
Utils.openURL(url, Gtk.get_current_event_time());
});
menu.append(item);
item = new Gtk.MenuItem({ label: _("Copy Link Address") });
- item.connect('activate',
- function() {
- let clipboard = Gtk.Clipboard.get_default(item.get_display());
- clipboard.set_text(url, -1);
- });
+ item.connect('activate', () => {
+ let clipboard = Gtk.Clipboard.get_default(item.get_display());
+ clipboard.set_text(url, -1);
+ });
menu.append(item);
menu.show_all();
@@ -807,21 +801,14 @@ const ChatView = new Lang.Class({
let hoveredButtonTags;
if (inside)
- hoveredButtonTags = iter.get_tags().filter(
- function(t) {
- return t instanceof ButtonTag;
- });
+ hoveredButtonTags = iter.get_tags().filter(t => t instanceof ButtonTag);
else
hoveredButtonTags = [];
- hoveredButtonTags.forEach(
- function(t) {
- t.hover = true;
- });
- this._hoveredButtonTags.forEach(
- function(t) {
- t.hover = hoveredButtonTags.indexOf(t) >= 0;
- });
+ hoveredButtonTags.forEach(t => { t.hover = true; });
+ this._hoveredButtonTags.forEach(t => {
+ t.hover = hoveredButtonTags.indexOf(t) >= 0;
+ });
let isHovering = hoveredButtonTags.length > 0;
let wasHovering = this._hoveredButtonTags.length > 0;
@@ -953,9 +940,9 @@ const ChatView = new Lang.Class({
{ name: 'pending-message-removed',
handler: Lang.bind(this, this._pendingMessageRemoved) }
];
- channelSignals.forEach(Lang.bind(this, function(signal) {
+ channelSignals.forEach(signal => {
this._channelSignals.push(this._channel.connect(signal.name, signal.handler));
- }));
+ });
let pending = this._channel.dup_pending_messages();
this._initialPending = pending.map(p => this._createMessage(p));
@@ -1059,15 +1046,13 @@ const ChatView = new Lang.Class({
groupTag.bind_property('invisible', headerArrowTag, 'invisible',
GObject.BindingFlags.INVERT_BOOLEAN);
- headerTag.connect('clicked',
- function() {
- groupTag.invisible = !groupTag.invisible;
- });
+ headerTag.connect('clicked', () => {
+ groupTag.invisible = !groupTag.invisible;
+ });
- headerTag.connect('notify::hover', Lang.bind(this,
- function() {
- headerTag.foreground_rgba = headerTag.hover ? this._statusHeaderHoverColor : null;
- }));
+ headerTag.connect('notify::hover', () => {
+ headerTag.foreground_rgba = headerTag.hover ? this._statusHeaderHoverColor : null;
+ });
this._ensureNewLine();
headerMark = buffer.create_mark('idle-status-start', buffer.get_end_iter(), true);
@@ -1396,23 +1381,20 @@ const ChatView = new Lang.Class({
url = 'http://' + url;
let tag = new ButtonTag();
- tag.connect('notify::hover', Lang.bind(this,
- function() {
- tag.foreground_rgba = tag.hover ? this._hoveredLinkColor : null;
- }));
- tag.connect('clicked',
- function() {
- Utils.openURL(url, Gtk.get_current_event_time());
- });
- tag.connect('button-press-event', Lang.bind(this,
- function(tag, event) {
- let [, button] = event.get_button();
- if (button != Gdk.BUTTON_SECONDARY)
- return Gdk.EVENT_PROPAGATE;
-
- this._showUrlContextMenu(url, button, event.get_time());
- return Gdk.EVENT_STOP;
- }));
+ tag.connect('notify::hover', () => {
+ tag.foreground_rgba = tag.hover ? this._hoveredLinkColor : null;
+ });
+ tag.connect('clicked', () => {
+ Utils.openURL(url, Gtk.get_current_event_time());
+ });
+ tag.connect('button-press-event', (tag, event) => {
+ let [, button] = event.get_button();
+ if (button != Gdk.BUTTON_SECONDARY)
+ return Gdk.EVENT_PROPAGATE;
+
+ this._showUrlContextMenu(url, button, event.get_time());
+ return Gdk.EVENT_STOP;
+ });
return tag;
},
diff --git a/src/connections.js b/src/connections.js
index 689e596..7233053 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -92,14 +92,12 @@ const ConnectionsList = new Lang.Class({
this._list.set_sort_func(Lang.bind(this, this._sort));
this._accountsMonitor = AccountsMonitor.getDefault();
- this._accountsMonitor.connect('account-added', Lang.bind(this,
- function(mon, account) {
- this._setAccountRowSensitive(account, false);
- }));
- this._accountsMonitor.connect('account-removed', Lang.bind(this,
- function(mon, account) {
- this._setAccountRowSensitive(account, true);
- }));
+ this._accountsMonitor.connect('account-added', (mon, account) => {
+ this._setAccountRowSensitive(account, false);
+ });
+ this._accountsMonitor.connect('account-removed', (mon, account) => {
+ this._setAccountRowSensitive(account, true);
+ });
this._networksManager = NetworksManager.getDefault();
this._networksManager.connect('changed',
@@ -120,8 +118,8 @@ const ConnectionsList = new Lang.Class({
_filterRows: function(row) {
let matchTerms = this._networksManager.getNetworkMatchTerms(row.id);
- return this._filterTerms.every(function(term) {
- return matchTerms.some(function(s) { return s.indexOf(term) != -1; });
+ return this._filterTerms.every(term => {
+ return matchTerms.some(s => s.indexOf(term) != -1);
});
},
@@ -133,23 +131,20 @@ const ConnectionsList = new Lang.Class({
},
_networksChanged: function() {
- this._list.foreach(function(w) { w.destroy(); });
+ this._list.foreach(w => { w.destroy(); });
let accounts = this._accountsMonitor.accounts;
- let usedNetworks = accounts.filter(Lang.bind(this, function(a) {
+ let usedNetworks = accounts.filter(a => {
return this._networksManager.getAccountIsPredefined(a);
- })).map(function(a) {
- return a.service;
+ }).map(a => a.service);
+
+ this._networksManager.networks.forEach(network => {
+ let sensitive = usedNetworks.indexOf(network.id) < 0;
+ this._rows.set(network.id,
+ new ConnectionRow({ id: network.id,
+ sensitive: sensitive }));
+ this._list.add(this._rows.get(network.id));
});
-
- this._networksManager.networks.forEach(Lang.bind(this,
- function(network) {
- let sensitive = usedNetworks.indexOf(network.id) < 0;
- this._rows.set(network.id,
- new ConnectionRow({ id: network.id,
- sensitive: sensitive }));
- this._list.add(this._rows.get(network.id));
- }));
},
_onRowActivated: function(list, row) {
@@ -166,12 +161,11 @@ const ConnectionsList = new Lang.Class({
for (let prop in details)
req.set_parameter(prop, details[prop]);
- req.create_account_async(Lang.bind(this,
- function(r, res) {
- let account = req.create_account_finish(res);
- if (account) // TODO: Handle errors
- this.emit('account-created', account);
- }));
+ req.create_account_async((r, res) => {
+ let account = req.create_account_finish(res);
+ if (account) // TODO: Handle errors
+ this.emit('account-created', account);
+ });
this.emit('account-selected');
},
@@ -219,10 +213,9 @@ const ConnectionDetails = new Lang.Class({
_init: function(params) {
this._networksManager = NetworksManager.getDefault();
- this._networksManager.connect('changed', Lang.bind(this,
- function() {
- this.notify('has-service');
- }));
+ this._networksManager.connect('changed', () => {
+ this.notify('has-service');
+ });
this._account = null;
@@ -384,12 +377,11 @@ const ConnectionDetails = new Lang.Class({
for (let prop in details)
req.set_parameter(prop, details[prop]);
- req.create_account_async(Lang.bind(this,
- function(r, res) {
- let account = req.create_account_finish(res);
- if (account) // TODO: Handle errors
- this.emit('account-created', account);
- }));
+ req.create_account_async((r, res) => {
+ let account = req.create_account_finish(res);
+ if (account) // TODO: Handle errors
+ this.emit('account-created', account);
+ });
},
_updateAccount: function() {
@@ -399,15 +391,13 @@ const ConnectionDetails = new Lang.Class({
let [details, removed] = this._detailsFromParams(params, oldDetails);
let vardict = GLib.Variant.new('a{sv}', details);
- account.update_parameters_vardict_async(vardict, removed,
- Lang.bind(this, function(a, res) {
- a.update_parameters_vardict_finish(res); // TODO: Check for errors
- }));
+ account.update_parameters_vardict_async(vardict, removed, (a, res) => {
+ a.update_parameters_vardict_finish(res); // TODO: Check for errors
+ });
- account.set_display_name_async(params.name, Lang.bind(this,
- function(a, res) {
- a.set_display_name_finish(res); // TODO: Check for errors
- }));
+ account.set_display_name_async(params.name, (a, res) => {
+ a.set_display_name_finish(res); // TODO: Check for errors
+ });
},
_detailsFromParams: function(params, oldDetails) {
@@ -422,10 +412,7 @@ const ConnectionDetails = new Lang.Class({
if (params.use_ssl)
details['use-ssl'] = GLib.Variant.new('b', params.use_ssl);
- let removed = Object.keys(oldDetails).filter(
- function(p) {
- return !details.hasOwnProperty(p);
- });
+ let removed = Object.keys(oldDetails).filter(p => !details.hasOwnProperty(p));
return [details, removed];
}
@@ -448,22 +435,20 @@ const ConnectionProperties = new Lang.Class({
this._details.account = account;
- this._details.connect('notify::has-service', Lang.bind(this,
- function() {
- /* HACK:
- * Shrink back to minimum height when the visibility of
- * some elements in Details could have changed; this
- * assumes that this only happens before the user could
- * resize the dialog herself
- */
- this.resize(this.default_width, 1);
- }));
-
- this.connect('response', Lang.bind(this,
- function(w, response) {
- if (response == Gtk.ResponseType.OK)
- this._details.save();
- }));
+ this._details.connect('notify::has-service', () => {
+ /* HACK:
+ * Shrink back to minimum height when the visibility of
+ * some elements in Details could have changed; this
+ * assumes that this only happens before the user could
+ * resize the dialog herself
+ */
+ this.resize(this.default_width, 1);
+ });
+
+ this.connect('response', (w, response) => {
+ if (response == Gtk.ResponseType.OK)
+ this._details.save();
+ });
this.set_default_response(Gtk.ResponseType.OK);
account.connect('notify::connection-status',
diff --git a/src/entryArea.js b/src/entryArea.js
index 8c55bf3..da0254f 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -69,20 +69,18 @@ const ChatEntry = new Lang.Class({
}
let clipboard = Gtk.Clipboard.get_default(this.get_display());
- clipboard.request_uris(Lang.bind(this,
- function(clipboard, uris) {
- 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_image(Lang.bind(this,
- function(clipboard, pixbuf) {
- if (pixbuf == null)
- return;
- this.emit('image-pasted', pixbuf);
- }));
+ clipboard.request_uris((clipboard, uris) => {
+ 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_image((clipboard, pixbuf) => {
+ if (pixbuf == null)
+ return;
+ this.emit('image-pasted', pixbuf);
+ });
},
_onTextReceived: function(clipboard, text) {
@@ -136,90 +134,79 @@ const EntryArea = new Lang.Class({
this.connect('destroy', Lang.bind(this, this._onDestroy));
this.connect('notify::sensitive', Lang.bind(this, this._onSensitiveChanged));
- this.connect('realize', Lang.bind(this,
- function() {
- this._toplevel = this.get_toplevel();
- this._keyPressId = this._toplevel.connect('key-press-event',
- Lang.bind(this, this._onKeyPressEvent));
- }));
+ this.connect('realize', () => {
+ this._toplevel = this.get_toplevel();
+ this._keyPressId = this._toplevel.connect('key-press-event',
+ Lang.bind(this, this._onKeyPressEvent));
+ });
this._nickLabel.set_state_flags(Gtk.StateFlags.LINK, false);
this._nickLabel.width_chars = this._maxNickChars;
/* HACK: We don't want the button to look different when the toplevel
is unfocused, so filter out the BACKDROP state */
- this._nickButton.connect('state-flags-changed', Lang.bind(this,
- function(w) {
- let state = w.get_state_flags();
- if (!(state & Gtk.StateFlags.BACKDROP))
- return; // avoid indefinite recursion
-
- state &= ~Gtk.StateFlags.BACKDROP;
- w.set_state_flags (state, true);
- }));
-
- this._changeButton.connect('clicked', Lang.bind(this,
- function() {
- if (this._nickEntry.text)
- this._setNick(this._nickEntry.text);
- this._nickButton.active = false;
- }));
+ this._nickButton.connect('state-flags-changed', w => {
+ let state = w.get_state_flags();
+ if (!(state & Gtk.StateFlags.BACKDROP))
+ return; // avoid indefinite recursion
+
+ state &= ~Gtk.StateFlags.BACKDROP;
+ w.set_state_flags (state, true);
+ });
+
+ this._changeButton.connect('clicked', () => {
+ if (this._nickEntry.text)
+ this._setNick(this._nickEntry.text);
+ this._nickButton.active = false;
+ });
this._nickPopover.set_default_widget(this._changeButton);
- this._chatEntry.connect('text-pasted', Lang.bind(this,
- function(entry, text, nLines) {
- this.pasteText(text, nLines);
- }));
- this._chatEntry.connect('text-dropped', Lang.bind(this,
- function(entry, text) {
- this.pasteText(text, text.split('\n').length);
- }));
-
- this._chatEntry.connect('image-pasted', Lang.bind(this,
- function(entry, image) {
- this.pasteImage(image);
- }));
- this._chatEntry.connect('image-dropped', Lang.bind(this,
- function(entry, image) {
- this.pasteImage(image);
- }));
-
- this._chatEntry.connect('file-pasted', Lang.bind(this,
- function(entry, file) {
- this.pasteFile(file);
- }));
- this._chatEntry.connect('file-dropped', Lang.bind(this,
- function(entry, file) {
- this.pasteFile(file);
- }));
+ this._chatEntry.connect('text-pasted', (entry, text, nLines) => {
+ this.pasteText(text, nLines);
+ });
+ this._chatEntry.connect('text-dropped', (entry, text) => {
+ this.pasteText(text, text.split('\n').length);
+ });
+
+ this._chatEntry.connect('image-pasted', (entry, image) => {
+ this.pasteImage(image);
+ });
+ this._chatEntry.connect('image-dropped', (entry, image) => {
+ this.pasteImage(image);
+ });
+
+ this._chatEntry.connect('file-pasted', (entry, file) => {
+ this.pasteFile(file);
+ });
+ this._chatEntry.connect('file-dropped', (entry, file) => {
+ this.pasteFile(file);
+ });
this._chatEntry.connect('changed', Lang.bind(this, this._onEntryChanged));
- this._chatEntry.connect('activate', Lang.bind(this,
- function() {
- if (this._ircParser.process(this._chatEntry.text)) {
- this._chatEntry.text = '';
- } else {
- this._chatEntry.get_style_context().add_class('error');
- this._chatEntry.grab_focus(); // select text
- }
- }));
+ this._chatEntry.connect('activate', () => {
+ if (this._ircParser.process(this._chatEntry.text)) {
+ this._chatEntry.text = '';
+ } else {
+ this._chatEntry.get_style_context().add_class('error');
+ this._chatEntry.grab_focus(); // select text
+ }
+ });
this._cancelButton.connect('clicked', Lang.bind(this, this._onCancelClicked));
this._pasteButton.connect('clicked', Lang.bind(this, this._onPasteClicked));
- this._pasteBox.connect_after('key-press-event', Lang.bind(this,
- function(w, event) {
- let [, keyval] = event.get_keyval();
- let [, mods] = event.get_state();
- if (keyval == Gdk.KEY_Escape || keyval == Gdk.KEY_BackSpace ||
- keyval == Gdk.KEY_Delete ||
- keyval == Gdk.KEY_z && mods & Gdk.ModifierType.CONTROL_MASK) {
- this._cancelButton.clicked();
- return Gdk.EVENT_STOP;
- }
- return Gdk.EVENT_PROPAGATE;
- }));
+ this._pasteBox.connect_after('key-press-event', (w, event) => {
+ let [, keyval] = event.get_keyval();
+ let [, mods] = event.get_state();
+ if (keyval == Gdk.KEY_Escape || keyval == Gdk.KEY_BackSpace ||
+ keyval == Gdk.KEY_Delete ||
+ keyval == Gdk.KEY_z && mods & Gdk.ModifierType.CONTROL_MASK) {
+ this._cancelButton.clicked();
+ return Gdk.EVENT_STOP;
+ }
+ return Gdk.EVENT_PROPAGATE;
+ });
if (!this._room)
return;
@@ -253,7 +240,7 @@ const EntryArea = new Lang.Class({
this._room.channel &&
this._room.channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP)) {
let members = this._room.channel.group_dup_members_contacts();
- nicks = members.map(function(member) { return member.alias; });
+ nicks = members.map(member => member.alias);
}
this._completion.setCompletions(nicks);
},
@@ -361,13 +348,12 @@ const EntryArea = new Lang.Class({
let app = Gio.Application.get_default();
try {
- app.pasteManager.pasteContent(this._pasteContent, title,
- Lang.bind(this, function(url) {
- // TODO: handle errors
- this._setPasteContent(null);
- if (url)
- this._chatEntry.emit('insert-at-cursor', url);
- }));
+ app.pasteManager.pasteContent(this._pasteContent, title, url => {
+ // TODO: handle errors
+ this._setPasteContent(null);
+ if (url)
+ this._chatEntry.emit('insert-at-cursor', url);
+ });
} catch(e) {
let type = typeof this._pasteContent;
debug('Failed to paste content of type ' +
@@ -403,31 +389,29 @@ const EntryArea = new Lang.Class({
this._nickLabel.label = nick;
let account = this._room.account;
- account.set_nickname_async(nick, Lang.bind(this,
- function(a, res) {
- try {
- a.set_nickname_finish(res);
- } catch(e) {
- logError(e, "Failed to change nick");
-
- this._updateNick();
- return;
- }
-
- // TpAccount:nickname is a local property which doesn't
- // necessarily match the externally visible nick; telepathy
- // doesn't consider failing to sync the two an error, so
- // we give the server MAX_NICK_UPDATE_TIME seconds until
- // we assume failure and revert back to the server nick
- //
- // (set_aliases() would do what we want, but it's not
- // introspected)
- Mainloop.timeout_add_seconds(MAX_NICK_UPDATE_TIME,
- Lang.bind(this, function() {
- this._updateNick();
- return GLib.SOURCE_REMOVE;
- }));
- }));
+ account.set_nickname_async(nick, (a, res) => {
+ try {
+ a.set_nickname_finish(res);
+ } catch(e) {
+ logError(e, "Failed to change nick");
+
+ this._updateNick();
+ return;
+ }
+
+ // TpAccount:nickname is a local property which doesn't
+ // necessarily match the externally visible nick; telepathy
+ // doesn't consider failing to sync the two an error, so
+ // we give the server MAX_NICK_UPDATE_TIME seconds until
+ // we assume failure and revert back to the server nick
+ //
+ // (set_aliases() would do what we want, but it's not
+ // introspected)
+ Mainloop.timeout_add_seconds(MAX_NICK_UPDATE_TIME, () => {
+ this._updateNick();
+ return GLib.SOURCE_REMOVE;
+ });
+ });
},
_updateNick: function() {
diff --git a/src/ircParser.js b/src/ircParser.js
index 0f39e86..da25e78 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -8,7 +8,7 @@ const RoomManager = imports.roomManager;
const Signals = imports.signals;
const Utils = imports.utils;
-const N_ = function(s) { return s; };
+const N_ = s => s;
const knownCommands = {
/* commands that would be nice to support: */
@@ -69,9 +69,7 @@ const IrcParser = new Lang.Class({
return true;
}
- let stripCommand = function(text) {
- return text.substr(text.indexOf(' ')).trimLeft();
- }
+ let stripCommand = text => text.substr(text.indexOf(' ')).trimLeft();
let retval = true;
@@ -103,7 +101,7 @@ const IrcParser = new Lang.Class({
break;
}
this._room.channel.connection.dup_contact_by_id_async(nick, [],
- Lang.bind(this, function(c, res) {
+ (c, res) => {
let contact;
try {
contact = c.dup_contact_by_id_finish(res);
@@ -112,7 +110,7 @@ const IrcParser = new Lang.Class({
return;
}
this._room.add_member(contact);
- }));
+ });
break;
}
case 'J':
@@ -143,7 +141,7 @@ const IrcParser = new Lang.Class({
break;
}
this._room.channel.connection.dup_contact_by_id_async(nick, [],
- Lang.bind(this, function(c, res) {
+ (c, res) => {
let contact;
try {
contact = c.dup_contact_by_id_finish(res);
@@ -152,7 +150,7 @@ const IrcParser = new Lang.Class({
return;
}
this._room.remove_member(contact);
- }));
+ });
break;
}
case 'ME': {
@@ -189,8 +187,7 @@ const IrcParser = new Lang.Class({
}
case 'NAMES': {
let channel = this._room.channel;
- let members = channel.group_dup_members_contacts().map(
- function(m) { return m.alias; });
+ let members = channel.group_dup_members_contacts().map(m => m.alias);
output = this._createFeedbackGrid(_("Users on %s:").format(channel.identifier),
members);
break;
@@ -205,14 +202,13 @@ const IrcParser = new Lang.Class({
if (argv.length)
log('Excess arguments to NICK command: ' + argv);
- this._room.account.set_nickname_async(nick, Lang.bind(this,
- function(a, res) {
- try {
- a.set_nickname_finish(res);
- } catch(e) {
- logError(e, 'Failed to update nick');
- }
- }));
+ this._room.account.set_nickname_async(nick, (a, res) => {
+ try {
+ a.set_nickname_finish(res);
+ } catch(e) {
+ logError(e, 'Failed to update nick');
+ }
+ });
break;
}
case 'PART':
@@ -255,13 +251,13 @@ const IrcParser = new Lang.Class({
let presence = Tp.ConnectionPresenceType.OFFLINE;
let message = stripCommand(text);
this._room.account.request_presence_async(presence, 'offline', message,
- Lang.bind(this, function(a, res) {
+ (a, res) => {
try {
a.request_presence_finish(res);
} catch(e) {
logError(e, 'Failed to disconnect');
}
- }));
+ });
break;
}
case 'SAY': {
@@ -298,15 +294,14 @@ const IrcParser = new Lang.Class({
},
_sendMessage: function(message) {
- this._room.channel.send_message_async(message, 0, Lang.bind(this,
- function(c, res) {
- try {
- c.send_message_finish(res);
- } catch(e) {
- // TODO: propagate to user
- logError(e, 'Failed to send message')
- }
- }));
+ this._room.channel.send_message_async(message, 0, (c, res) => {
+ try {
+ c.send_message_finish(res);
+ } catch(e) {
+ // TODO: propagate to user
+ logError(e, 'Failed to send message')
+ }
+ });
}
});
Signals.addSignalMethods(IrcParser.prototype);
diff --git a/src/joinDialog.js b/src/joinDialog.js
index ba110de..837d220 100644
--- a/src/joinDialog.js
+++ b/src/joinDialog.js
@@ -62,29 +62,25 @@ const JoinDialog = new Lang.Class({
this._accounts[a.display_name] = a;
});
this._accountAddedId =
- this._accountsMonitor.connect('account-added', Lang.bind(this,
- function(am, account) {
- this._accounts[account.display_name] = account;
- this._updateConnectionCombo();
- }));
+ this._accountsMonitor.connect('account-added', (am, account) => {
+ this._accounts[account.display_name] = account;
+ this._updateConnectionCombo();
+ });
this._accountRemovedId =
- this._accountsMonitor.connect('account-removed', Lang.bind(this,
- function(am, account) {
- delete this._accounts[account.display_name];
- this._updateConnectionCombo();
- }));
-
- this.connect('response', Lang.bind(this,
- function(w, response) {
- if (response == Gtk.ResponseType.OK)
- this._joinRoom();
- this.destroy();
- }));
- this.connect('destroy', Lang.bind(this,
- function() {
- this._accountsMonitor.disconnect(this._accountAddedId);
- this._accountsMonitor.disconnect(this._accountRemovedId);
- }));
+ this._accountsMonitor.connect('account-removed', (am, account) => {
+ delete this._accounts[account.display_name];
+ this._updateConnectionCombo();
+ });
+
+ this.connect('response', (w, response) => {
+ if (response == Gtk.ResponseType.OK)
+ this._joinRoom();
+ this.destroy();
+ });
+ this.connect('destroy', () => {
+ this._accountsMonitor.disconnect(this._accountAddedId);
+ this._accountsMonitor.disconnect(this._accountRemovedId);
+ });
if (this._hasAccounts)
this._setPage(DialogPage.MAIN);
@@ -100,10 +96,9 @@ const JoinDialog = new Lang.Class({
},
_setupMainPage: function() {
- this._connectionButton.connect('clicked', Lang.bind(this,
- function() {
- this._setPage(DialogPage.CONNECTION);
- }));
+ this._connectionButton.connect('clicked', () => {
+ this._setPage(DialogPage.CONNECTION);
+ });
this._connectionCombo.connect('changed',
Lang.bind(this, this._onAccountChanged));
@@ -114,52 +109,45 @@ const JoinDialog = new Lang.Class({
},
_setupConnectionPage: function() {
- this._backButton.connect('clicked', Lang.bind(this,
- function() {
- this._setPage(DialogPage.MAIN);
- }));
- this._connectionsList.connect('account-selected', Lang.bind(this,
- function() {
- this._setPage(DialogPage.MAIN);
- }));
- this._addButton.connect('clicked', Lang.bind(this,
- function() {
- this._details.save();
- this._setPage(DialogPage.MAIN);
- }));
+ this._backButton.connect('clicked', () => {
+ this._setPage(DialogPage.MAIN);
+ });
+ this._connectionsList.connect('account-selected', () => {
+ this._setPage(DialogPage.MAIN);
+ });
+ this._addButton.connect('clicked', () => {
+ this._details.save();
+ this._setPage(DialogPage.MAIN);
+ });
this._connectionsList.connect('account-created',
Lang.bind(this, this._onAccountCreated));
this._details.connect('account-created',
Lang.bind(this, this._onAccountCreated));
- this._customToggle.connect('notify::active', Lang.bind(this,
- function() {
- let isCustom = this._customToggle.active;
- this._connectionStack.visible_child_name = isCustom ? 'custom'
- : 'predefined';
- if (isCustom) {
- this._addButton.grab_default();
- this._details.reset();
- }
- }));
-
- this._filterEntry.connect('search-changed', Lang.bind(this,
- function() {
- this._connectionsList.setFilter(this._filterEntry.text);
- }));
- this._filterEntry.connect('stop-search', Lang.bind(this,
- function() {
- if (this._filterEntry.text.length > 0)
- this._filterEntry.text = '';
- else
- this.response(Gtk.ResponseType.CANCEL);
- }));
- this._filterEntry.connect('activate', Lang.bind(this,
- function() {
- if (this._filterEntry.text.length > 0)
- this._connectionsList.activateFirst();
- }));
+ this._customToggle.connect('notify::active', () => {
+ let isCustom = this._customToggle.active;
+ this._connectionStack.visible_child_name = isCustom ? 'custom'
+ : 'predefined';
+ if (isCustom) {
+ this._addButton.grab_default();
+ this._details.reset();
+ }
+ });
+
+ this._filterEntry.connect('search-changed', () => {
+ this._connectionsList.setFilter(this._filterEntry.text);
+ });
+ this._filterEntry.connect('stop-search', () => {
+ if (this._filterEntry.text.length > 0)
+ this._filterEntry.text = '';
+ else
+ this.response(Gtk.ResponseType.CANCEL);
+ });
+ this._filterEntry.connect('activate', () => {
+ if (this._filterEntry.text.length > 0)
+ this._connectionsList.activateFirst();
+ });
},
_onAccountChanged: function() {
@@ -182,7 +170,7 @@ const JoinDialog = new Lang.Class({
let account = this._accounts[selected];
let toJoinRooms = this._serverRoomList.selectedRooms;
- toJoinRooms.forEach(function(room) {
+ toJoinRooms.forEach(room => {
if (room[0] != '#')
room = '#' + room;
@@ -198,11 +186,10 @@ const JoinDialog = new Lang.Class({
_updateConnectionCombo: function() {
this._connectionCombo.remove_all();
- let names = Object.keys(this._accounts).sort(
- function(a, b) {
- // TODO: figure out combo box sorting
- return (a < b) ? -1 : ((a > b) ? 1 : 0);
- });
+ let names = Object.keys(this._accounts).sort((a, b) => {
+ // TODO: figure out combo box sorting
+ return (a < b) ? -1 : ((a > b) ? 1 : 0);
+ });
for (let i = 0; i < names.length; i++)
this._connectionCombo.append(names[i], names[i]);
this._connectionCombo.sensitive = names.length > 1;
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a6c6b4b..6bc7249 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -153,14 +153,13 @@ const MainWindow = new Lang.Class({
GObject.BindingFlags.SYNC_CREATE);
// Make sure user-list button is at least as wide as icon buttons
- this._joinButton.connect('size-allocate', Lang.bind(this,
- function(w, rect) {
- let width = rect.width;
- Mainloop.idle_add(Lang.bind(this, function() {
- this._showUserListButton.width_request = width;
- return GLib.SOURCE_REMOVE;
- }));
- }));
+ this._joinButton.connect('size-allocate', (w, rect) => {
+ let width = rect.width;
+ Mainloop.idle_add(() => {
+ this._showUserListButton.width_request = width;
+ return GLib.SOURCE_REMOVE;
+ });
+ });
this._accountsMonitor = AccountsMonitor.getDefault();
this._accountsMonitor.connect('accounts-changed',
@@ -178,15 +177,13 @@ const MainWindow = new Lang.Class({
this._userListAction = app.lookup_action('user-list');
- app.connect('action-state-changed::user-list', Lang.bind(this,
- function(group, actionName, value) {
- this._userListPopover.visible = value.get_boolean();
- }));
- this._userListPopover.connect('notify::visible', Lang.bind(this,
- function() {
- if (!this._userListPopover.visible)
- this._userListAction.change_state(GLib.Variant.new('b', false));
- }));
+ app.connect('action-state-changed::user-list', (group, name, value) => {
+ this._userListPopover.visible = value.get_boolean();
+ });
+ this._userListPopover.connect('notify::visible', () => {
+ if (!this._userListPopover.visible)
+ this._userListAction.change_state(GLib.Variant.new('b', false));
+ });
this._gtkSettings.connect('notify::gtk-decoration-layout',
Lang.bind(this, this._updateDecorations));
diff --git a/src/networksManager.js b/src/networksManager.js
index ae154bc..4bded4f 100644
--- a/src/networksManager.js
+++ b/src/networksManager.js
@@ -53,10 +53,9 @@ const NetworksManager = new Lang.Class({
this._networksById.clear();
this._networks = networks;
- this._networks.forEach(Lang.bind(this,
- function(network) {
- this._networksById.set(network.id, network);
- }));
+ this._networks.forEach(network => {
+ this._networksById.set(network.id, network);
+ });
return true;
},
@@ -111,9 +110,7 @@ const NetworksManager = new Lang.Class({
getNetworkMatchTerms: function(id) {
let network = this._lookupNetwork(id);
- let servers = network.servers.map(function(s) {
- return s.address.toLowerCase();
- });
+ let servers = network.servers.map(s => s.address.toLowerCase());
return [network.name.toLowerCase(),
network.id.toLowerCase()].concat(servers);
},
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 530528d..8aa03f1 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -65,21 +65,18 @@ const PasteManager = new Lang.Class({
let targetType = _getTargetForContentType(contentType);
if (targetType == DndTargetType.TEXT)
- file.load_contents_async(null, Lang.bind(this,
- function(f, res) {
- let [, contents, ,] = f.load_contents_finish(res);
- Utils.gpaste(contents.toString(), title, callback);
- }));
+ file.load_contents_async(null, (f, res) => {
+ let [, contents, ,] = f.load_contents_finish(res);
+ Utils.gpaste(contents.toString(), title, callback);
+ });
else if (targetType == DndTargetType.IMAGE)
- file.read_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
- function(f, res) {
- let stream = f.read_finish(res);
- GdkPixbuf.Pixbuf.new_from_stream_async(stream, null,
- Lang.bind(this, function(stream, res) {
- let pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
- Utils.imgurPaste(pixbuf, title, callback);
- }));
- }));
+ file.read_async(GLib.PRIORITY_DEFAULT, null, (f, res) => {
+ let stream = f.read_finish(res);
+ GdkPixbuf.Pixbuf.new_from_stream_async(stream, null, (s, res) => {
+ let pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
+ Utils.imgurPaste(pixbuf, title, callback);
+ });
+ });
else
callback(null);
}
@@ -175,13 +172,12 @@ const DropTargetIface = new Lang.Interface({
// TODO: handle multiple files ...
let file = Gio.File.new_for_uri(uris[0]);
try {
- this._lookupFileInfo(file, Lang.bind(this,
- function(targetType) {
- let canHandle = targetType != 0;
- if (canHandle)
- this.emit('file-dropped', file);
- Gtk.drag_finish(context, canHandle, false, time);
- }));
+ this._lookupFileInfo(file, targetType => {
+ let canHandle = targetType != 0;
+ if (canHandle)
+ this.emit('file-dropped', file);
+ Gtk.drag_finish(context, canHandle, false, time);
+ });
} catch(e) {
Gtk.drag_finish(context, false, false, time);
}
@@ -202,14 +198,13 @@ const DropTargetIface = new Lang.Interface({
},
_lookupFileInfo: function(file, callback) {
- file.query_info_async(Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- Gio.FileQueryInfoFlags.NONE,
- GLib.PRIORITY_DEFAULT,
- null, Lang.bind(this,
- function(f, res) {
- let fileInfo = file.query_info_finish(res);
- let contentType = fileInfo.get_content_type();
- callback(_getTargetForContentType(contentType));
- }))
+ let attr = Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE;
+ let flags = Gio.FileQueryInfoFlags.NONE;
+ let priority = GLib.PRIORITY_DEFAULT;
+ file.query_info_async(attr, flags, priority, null, (f, res) => {
+ let fileInfo = file.query_info_finish(res);
+ let contentType = fileInfo.get_content_type();
+ callback(_getTargetForContentType(contentType));
+ });
}
});
diff --git a/src/polari-accounts.in b/src/polari-accounts.in
index ea5571e..b548ab0 100755
--- a/src/polari-accounts.in
+++ b/src/polari-accounts.in
@@ -19,10 +19,10 @@ const AccountsWindow = new Lang.Class({
this.add(scrolled);
this._list = new Gtk.ListBox();
- this._list.set_sort_func(function(row1, row2) {
+ this._list.set_sort_func((row1, row2) => {
return row1.account.display_name.localeCompare(row2.account.display_name);
});
- this._list.set_header_func(function(row, before) {
+ this._list.set_header_func((row, before) => {
let header = row.get_header();
if (!before)
@@ -30,7 +30,7 @@ const AccountsWindow = new Lang.Class({
else if (!header)
row.set_header(new Gtk.Separator({ orientation: Gtk.Orientation.HORIZONTAL }));
});
- this._list.connect('row-activated', function(l, row) {
+ this._list.connect('row-activated', (l, row) => {
row.account.set_enabled_async(!row.account.enabled, null);
});
scrolled.add(this._list);
@@ -41,17 +41,15 @@ const AccountsWindow = new Lang.Class({
},
_onPrepared: function(am) {
- am.connect('account-validity-changed', Lang.bind(this,
- function(am, account, valid) {
- if (valid)
- this._addAccount(account);
- else
- this._removeAccount(account);
- }));
- am.connect('account-removed', Lang.bind(this,
- function(am, account) {
+ am.connect('account-validity-changed', (am, account, valid) => {
+ if (valid)
+ this._addAccount(account);
+ else
this._removeAccount(account);
- }));
+ });
+ am.connect('account-removed', (am, account) => {
+ this._removeAccount(account);
+ });
am.dup_valid_accounts().forEach(Lang.bind(this, this._addAccount));
},
@@ -80,11 +78,9 @@ const AccountsWindow = new Lang.Class({
GObject.BindingFlags.SYNC_CREATE);
account.bind_property('enabled', sw, 'state',
GObject.BindingFlags.SYNC_CREATE);
- account.connect('notify::display-name', function() {
- row.changed();
- });
+ account.connect('notify::display-name', () => { row.changed(); });
- sw.connect('state-set', function(w, state) {
+ sw.connect('state-set', (w, state) => {
account.set_enabled_async(state, null);
return true;
});
@@ -103,7 +99,7 @@ const AccountsWindow = new Lang.Class({
GLib.set_application_name("Polari Accounts");
let app = new Gtk.Application({ application_id: 'org.gnome.Polari.Accounts' });
-app.connect('activate', function() {
+app.connect('activate', () => {
let window = app.active_window;
if (!window)
window = new AccountsWindow({ application: app,
diff --git a/src/roomList.js b/src/roomList.js
index f839c21..571c5e6 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -168,10 +168,9 @@ const RoomListHeader = new Lang.Class({
this.popover.set_default_widget(this._popoverPassword);
this.popover.connect('notify::visible', _onPopoverVisibleChanged);
- this.popover.connect('closed', Lang.bind(this,
- function() {
- this._popoverPassword.text = '';
- }));
+ this.popover.connect('closed', () => {
+ this._popoverPassword.text = '';
+ });
let target = new GLib.Variant('o', this._account.get_object_path());
this._popoverConnect.action_target = target;
@@ -179,15 +178,14 @@ const RoomListHeader = new Lang.Class({
this._popoverRemove.action_target = target;
this._popoverProperties.action_target = target;
- this._popoverPassword.connect('activate', Lang.bind(this,
- function() {
- let action = this._app.lookup_action('authenticate-account');
- let password = this._popoverPassword.text;
- let accountPath = this._account.get_object_path();
- let param = new GLib.Variant('(os)', [accountPath, password]);
- action.activate(param);
- this.popover.hide();
- }));
+ this._popoverPassword.connect('activate', () => {
+ let action = this._app.lookup_action('authenticate-account');
+ let password = this._popoverPassword.text;
+ let accountPath = this._account.get_object_path();
+ let param = new GLib.Variant('(os)', [accountPath, password]);
+ action.activate(param);
+ this.popover.hide();
+ });
let displayNameChangedId =
this._account.connect('notify::display-name',
@@ -203,11 +201,11 @@ const RoomListHeader = new Lang.Class({
Lang.bind(this, this._onRequestedPresenceChanged));
this._onRequestedPresenceChanged();
- this.connect('destroy', Lang.bind(this, function() {
+ this.connect('destroy', () => {
this._account.disconnect(displayNameChangedId);
this._account.disconnect(connectionStatusChangedId);
this._account.disconnect(presenceChangedId);
- }));
+ });
},
_onDisplayNameChanged: function() {
@@ -508,10 +506,9 @@ const RoomList = new Lang.Class({
this._placeholders.set(account, placeholder);
this.add(placeholder);
- placeholder.connect('notify::visible', Lang.bind(this,
- function() {
- this.invalidate_sort();
- }));
+ placeholder.connect('notify::visible', () => {
+ this.invalidate_sort();
+ });
this._updatePlaceholderVisibility(account);
},
@@ -580,9 +577,8 @@ const RoomList = new Lang.Class({
},
_updateHeader: function(row, before) {
- let getAccount = function(row) {
- return row ? row.account : null;
- };
+ let getAccount = row => row ? row.account : null;
+
let beforeAccount = getAccount(before);
let account = getAccount(row);
diff --git a/src/roomStack.js b/src/roomStack.js
index 2870796..09dba69 100644
--- a/src/roomStack.js
+++ b/src/roomStack.js
@@ -39,11 +39,10 @@ const RoomStack = new Lang.Class({
this.add_named(new ChatPlaceholder(this._sizeGroup), 'placeholder');
this._entryAreaHeight = 0;
- this._sizeGroup.get_widgets()[0].connect('size-allocate', Lang.bind(this,
- function(w, rect) {
- this._entryAreaHeight = rect.height - 1;
- this.notify('entry-area-height');
- }));
+ this._sizeGroup.get_widgets()[0].connect('size-allocate', (w, rect) => {
+ this._entryAreaHeight = rect.height - 1;
+ this.notify('entry-area-height');
+ });
},
vfunc_realize: function() {
@@ -217,18 +216,15 @@ const RoomView = new Lang.Class({
GObject.BindingFlags.SYNC_CREATE);
sizeGroup.add_widget(this._entryArea);
- this._view.connect('text-dropped', Lang.bind(this,
- function(view, text) {
- this._entryArea.pasteText(text, text.split('\n').length);
- }));
- this._view.connect('image-dropped', Lang.bind(this,
- function(view, image) {
- this._entryArea.pasteImage(image);
- }));
- this._view.connect('file-dropped', Lang.bind(this,
- function(view, file) {
- this._entryArea.pasteFile(file);
- }));
+ this._view.connect('text-dropped', (view, text) => {
+ this._entryArea.pasteText(text, text.split('\n').length);
+ });
+ this._view.connect('image-dropped', (view, image) => {
+ this._entryArea.pasteImage(image);
+ });
+ this._view.connect('file-dropped', (view, file) => {
+ this._entryArea.pasteFile(file);
+ });
this.show_all();
},
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index a4f1cfe..d9a710b 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -16,10 +16,9 @@ const TabCompletion = new Lang.Class({
this._entry.connect('key-press-event', Lang.bind(this, this._onKeyPress));
this._entry.connect('focus-out-event', Lang.bind(this, this._cancel));
this._entry.connect('unmap', Lang.bind(this, this._cancel));
- this._entry.connect('realize', Lang.bind(this,
- function() {
- this._popup.set_transient_for(this._entry.get_toplevel());
- }));
+ this._entry.connect('realize', () => {
+ this._popup.set_transient_for(this._entry.get_toplevel());
+ });
this._popup = new Gtk.Window({ type: Gtk.WindowType.POPUP });
@@ -78,11 +77,10 @@ const TabCompletion = new Lang.Class({
setCompletions: function(completions) {
if (this._popup.visible) {
- let id = this._popup.connect('unmap', Lang.bind(this,
- function() {
- this._popup.disconnect(id);
- this.setCompletions(completions);
- }));
+ let id = this._popup.connect('unmap', () => {
+ this._popup.disconnect(id);
+ this.setCompletions(completions);
+ });
return;
}
@@ -110,7 +108,7 @@ const TabCompletion = new Lang.Class({
this._widgetMap = widgetMap;
// All remaining rows except those with IRC commands are going unused
- this._list.foreach(function(r) {
+ this._list.foreach(r => {
if (!r._text.startsWith('/'))
r.destroy();
});
@@ -216,9 +214,7 @@ const TabCompletion = new Lang.Class({
this._list.invalidate_filter();
- let visibleRows = this._list.get_children().filter(function(c) {
- return c.get_child_visible();
- });
+ let visibleRows = this._list.get_children().filter(c => c.get_child_visible());
let nVisibleRows = visibleRows.length;
if (nVisibleRows == 0)
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index d6b5011..7fe5686 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -101,12 +101,11 @@ const SASLAuthHandler = new Lang.Class({
let account = this._channel.connection.get_account();
let prompt = new GLib.Variant('b', false);
let params = new GLib.Variant('a{sv}', { 'password-prompt': prompt });
- account.update_parameters_vardict_async(params, [], Lang.bind(this,
- function(a, res) {
- a.update_parameters_vardict_finish(res);
- account.request_presence_async(Tp.ConnectionPresenceType.AVAILABLE,
- 'available', '', null);
- }));
+ account.update_parameters_vardict_async(params, [], (a, res) => {
+ a.update_parameters_vardict_finish(res);
+ account.request_presence_async(Tp.ConnectionPresenceType.AVAILABLE,
+ 'available', '', null);
+ });
}
});
@@ -354,14 +353,12 @@ const TelepathyClient = new Lang.Class({
let prompt = new GLib.Variant('b', password.length > 0);
let params = GLib.Variant.new('a{sv}', { 'password-prompt': prompt });
- account.update_parameters_vardict_async(params, [],
- Lang.bind(this, function(a, res) {
- a.update_parameters_vardict_finish(res);
- Utils.storeAccountPassword(a, password, Lang.bind(this,
- function() {
- a.reconnect_async(null);
- }));
- }));
+ account.update_parameters_vardict_async(params, [], (a, res) => {
+ a.update_parameters_vardict_finish(res);
+ Utils.storeAccountPassword(a, password, () => {
+ a.reconnect_async(null);
+ });
+ });
},
_onQueryActivated: function(action, parameter) {
@@ -481,45 +478,43 @@ const TelepathyClient = new Lang.Class({
vfunc_observe_channels: function(account, connection, channels,
op, requests, context) {
- this._processRequest(context, connection, channels, Lang.bind(this,
- function(channel) {
- if (this._isAuthChannel(channel))
- return;
-
- if (channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP)) {
- let [invited, , , ,] =
channel.group_get_local_pending_contact_info(channel.group_self_contact);
- if (invited)
- // this is an invitation - only add it in handleChannel
- // if accepted
- return;
- }
+ this._processRequest(context, connection, channels, channel => {
+ if (this._isAuthChannel(channel))
+ return;
+
+ if (channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP)) {
+ let [invited, , , ,] =
channel.group_get_local_pending_contact_info(channel.group_self_contact);
+ if (invited)
+ // this is an invitation - only add it in handleChannel
+ // if accepted
+ return;
+ }
- channel.connect('message-received',
- Lang.bind(this, this._onMessageReceived));
- channel.connect('pending-message-removed',
- Lang.bind(this, this._onPendingMessageRemoved));
+ channel.connect('message-received',
+ Lang.bind(this, this._onMessageReceived));
+ channel.connect('pending-message-removed',
+ Lang.bind(this, this._onPendingMessageRemoved));
- this._roomManager.ensureRoomForChannel(channel, 0);
- }));
+ this._roomManager.ensureRoomForChannel(channel, 0);
+ });
},
vfunc_handle_channels: function(account, connection, channels,
satisfied, userTime, context) {
let [present, ] = Tp.user_action_time_should_present(userTime);
- this._processRequest(context, connection, channels, Lang.bind(this,
- function(channel) {
- if (this._isAuthChannel(channel)) {
- let authHandler = new SASLAuthHandler(channel);
- return;
- }
+ this._processRequest(context, connection, channels, channel => {
+ if (this._isAuthChannel(channel)) {
+ let authHandler = new SASLAuthHandler(channel);
+ return;
+ }
- if (present)
- this._app.activate();
+ if (present)
+ this._app.activate();
- this._roomManager.ensureRoomForChannel(channel, userTime);
- //channel.join_async('', null);
- }));
+ this._roomManager.ensureRoomForChannel(channel, userTime);
+ //channel.join_async('', null);
+ });
},
_getPendingNotificationID: function(room, id) {
diff --git a/src/userList.js b/src/userList.js
index ec00cb9..333cc3e 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -24,16 +24,14 @@ const UserListPopover = new Lang.Class({
this._createWidget();
- this.connect('closed', Lang.bind(this, function() {
- this._entry.text = '';
- }));
- this.connect('map', Lang.bind(this, function() {
+ this.connect('closed', () => { this._entry.text = ''; });
+ this.connect('map', () => {
this._revealer.transition_duration = 0;
this._ensureUserList();
- }));
- this._revealer.connect('notify::child-revealed', Lang.bind(this, function() {
+ });
+ this._revealer.connect('notify::child-revealed', () => {
this._revealer.transition_duration = 250;
- }));
+ });
},
vfunc_realize: function() {
@@ -447,9 +445,9 @@ const UserListRow = new Lang.Class({
this._createWidget();
- this.connect('unmap', Lang.bind(this, function() {
+ this.connect('unmap', () => {
this._revealer.reveal_child = false;
- }));
+ });
this.connect('state-flags-changed',
Lang.bind(this, this._updateArrowVisibility));
@@ -617,9 +615,9 @@ const UserList = new Lang.Class({
handler: Lang.bind(this, this._onChannelChanged) }
];
this._roomSignals = [];
- roomSignals.forEach(Lang.bind(this, function(signal) {
+ roomSignals.forEach(signal => {
this._roomSignals.push(room.connect(signal.name, signal.handler));
- }));
+ });
this._onChannelChanged(room);
this.show_all();
@@ -644,7 +642,7 @@ const UserList = new Lang.Class({
if (this._updateHeightId != 0)
return;
- this._updateHeightId = Mainloop.idle_add(Lang.bind(this, function() {
+ this._updateHeightId = Mainloop.idle_add(() => {
let topRow = this._list.get_row_at_y(this.vadjustment.value);
let membersShown = Math.min(this.numRows, MAX_USERS_SHOWN);
// topRow is unset when all rows are hidden due to filtering,
@@ -661,7 +659,7 @@ const UserList = new Lang.Class({
this.propagate_natural_height = true;
this._updateHeightId = 0;
return GLib.SOURCE_REMOVE;
- }));
+ });
},
_onMemberRenamed: function(room, oldMember, newMember) {
@@ -682,7 +680,7 @@ const UserList = new Lang.Class({
},
_onChannelChanged: function(room) {
- this._list.foreach(function(w) { w.destroy(); });
+ this._list.foreach(w => { w.destroy(); });
this._rows = {};
if (!room.channel)
diff --git a/src/utils.js b/src/utils.js
index 1fd4606..21b97c8 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -115,18 +115,17 @@ function storeIdentifyPassword(account, password, callback) {
function _storePassword(schema, label, account, password, callback) {
let attr = { 'account-id': account.get_path_suffix() };
- Secret.password_store(schema, attr, Secret.COLLECTION_DEFAULT,
- label, password, null,
- function(o, res) {
- try {
- let success = Secret.password_store_finish(res);
- callback(success);
- } catch(e) {
- log('Failed to store password for account "%s": %s'.format(
- account.display_name, e.message));
- callback(false);
- }
- });
+ let coll = Secret.COLLECTION_DEFAULT;
+ Secret.password_store(schema, attr, coll, label, password, null, (o, res) => {
+ try {
+ let success = Secret.password_store_finish(res);
+ callback(success);
+ } catch(e) {
+ log('Failed to store password for account "%s": %s'.format(
+ account.display_name, e.message));
+ callback(false);
+ }
+ });
}
function lookupAccountPassword(account, callback) {
@@ -139,17 +138,16 @@ function lookupIdentifyPassword(account, callback) {
function _lookupPassword(schema, account, callback) {
let attr = { 'account-id': account.get_path_suffix() };
- Secret.password_lookup(schema, attr, null,
- function(o, res) {
- try {
- let password = Secret.password_lookup_finish(res);
- callback(password);
- } catch(e) {
- log('Failed to lookup password for account "%s": %s'.format(
- account.display_name, e.message));
- callback(null);
- }
- });
+ Secret.password_lookup(schema, attr, null, (o, res) => {
+ try {
+ let password = Secret.password_lookup_finish(res);
+ callback(password);
+ } catch(e) {
+ log('Failed to lookup password for account "%s": %s'.format(
+ account.display_name, e.message));
+ callback(null);
+ }
+ });
}
// findUrls:
@@ -257,24 +255,23 @@ function gpaste(text, title, callback) {
let session = new Soup.Session();
let createUrl = GPASTE_BASEURL + 'api/json/create';
let message = Soup.form_request_new_from_hash('POST', createUrl, params);
- session.queue_message(message,
- function(session, message) {
- if (message.status_code != Soup.KnownStatusCode.OK) {
- callback(null);
- return;
- }
-
- let info = {};
- try {
- info = JSON.parse(message.response_body.data);
- } catch(e) {
- log(e.message);
- }
- if (info.result && info.result.id)
- callback(GPASTE_BASEURL + info.result.id);
- else
- callback(null);
- });
+ session.queue_message(message, (s, message) => {
+ if (message.status_code != Soup.KnownStatusCode.OK) {
+ callback(null);
+ return;
+ }
+
+ let info = {};
+ try {
+ info = JSON.parse(message.response_body.data);
+ } catch(e) {
+ log(e.message);
+ }
+ if (info.result && info.result.id)
+ callback(GPASTE_BASEURL + info.result.id);
+ else
+ callback(null);
+ });
}
function imgurPaste(pixbuf, title, callback) {
@@ -295,22 +292,21 @@ function imgurPaste(pixbuf, title, callback) {
let requestHeaders = message.request_headers;
requestHeaders.append('Authorization', 'Client-ID ' + IMGUR_CLIENT_ID);
- session.queue_message(message,
- function(session, message) {
- if (message.status_code != Soup.KnownStatusCode.OK) {
- callback(null);
- return;
- }
-
- let info = {};
- try {
- info = JSON.parse(message.response_body.data);
- } catch(e) {
- log(e.message);
- }
- if (info.success)
- callback(info.data.link);
- else
- callback(null);
- });
+ session.queue_message(message, (s, message) => {
+ if (message.status_code != Soup.KnownStatusCode.OK) {
+ callback(null);
+ return;
+ }
+
+ let info = {};
+ try {
+ info = JSON.parse(message.response_body.data);
+ } catch(e) {
+ log(e.message);
+ }
+ if (info.success)
+ callback(info.data.link);
+ else
+ callback(null);
+ });
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]