[sushi/wip/cosimoc/no-clutter: 56/66] Stop using Lang.bind()
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi/wip/cosimoc/no-clutter: 56/66] Stop using Lang.bind()
- Date: Sat, 8 Jun 2019 18:44:51 +0000 (UTC)
commit 65585b755d873b6ce4a593a7b6e86b32db61f69b
Author: Cosimo Cecchi <cosimo endlessm com>
Date: Fri Jun 7 10:44:19 2019 -0700
Stop using Lang.bind()
Either use arrow functions or the bind() method instead.
src/js/ui/fallbackRenderer.js | 4 +---
src/js/ui/mainWindow.js | 56 +++++++++++++++++++------------------------
src/js/viewers/audio.js | 45 +++++++++++++---------------------
src/js/viewers/evince.js | 19 +++++++--------
src/js/viewers/image.js | 53 ++++++++++++++++++----------------------
src/js/viewers/text.js | 7 +++---
6 files changed, 75 insertions(+), 109 deletions(-)
---
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index 5c9bb30..bcc0d55 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -49,9 +49,7 @@ var FallbackRenderer = new Lang.Class({
this._fileLoader = new Sushi.FileLoader();
this._fileLoader.file = file;
- this._fileLoaderId =
- this._fileLoader.connect('notify',
- Lang.bind(this, this._onFileInfoChanged));
+ this._fileLoaderId = this._fileLoader.connect('notify', this._onFileInfoChanged.bind(this));
this._image = new Gtk.Image();
this.pack_start(this._image, false, false, 0);
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 9d84822..700b60c 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -88,16 +88,11 @@ var MainWindow = new Lang.Class({
decoration_layout: "menu:close" });
this.set_titlebar(this._titlebar);
- this.connect('button-press-event',
- Lang.bind(this, this._onButtonPressEvent));
- this.connect('delete-event',
- Lang.bind(this, this._onDeleteEvent));
- this.connect('key-press-event',
- Lang.bind(this, this._onKeyPressEvent));
- this.connect('motion-notify-event',
- Lang.bind(this, this._onMotionNotifyEvent));
- this.connect('realize',
- Lang.bind(this, this._onRealize));
+ this.connect('button-press-event', this._onButtonPressEvent.bind(this));
+ this.connect('delete-event', this._onDeleteEvent.bind(this));
+ this.connect('key-press-event', this._onKeyPressEvent.bind(this));
+ this.connect('motion-notify-event', this._onMotionNotifyEvent.bind(this));
+ this.connect('realize', this._onRealize.bind(this));
this._embed = new Embed();
this._embed.connect('size-request', this._onEmbedSizeRequest.bind(this));
@@ -190,25 +185,24 @@ var MainWindow = new Lang.Class({
},
_createRenderer : function(file) {
- file.query_info_async
- (Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ',' +
- Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- Gio.FileQueryInfoFlags.NONE,
- GLib.PRIORITY_DEFAULT, null,
- Lang.bind (this, function(obj, res) {
- try {
- this._fileInfo = obj.query_info_finish(res);
- this.setTitle(this._fileInfo.get_display_name());
-
- /* now prepare the real renderer */
- let klass = this._mimeHandler.getKlass(this._fileInfo.get_content_type());
- this._createView(file, klass);
- this._createToolbar();
- } catch(e) {
- /* FIXME: report the error */
- logError(e, 'Error creating viewer');
- }})
- );
+ file.query_info_async(
+ [Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE].join(','),
+ Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null,
+ (obj, res) => {
+ try {
+ this._fileInfo = obj.query_info_finish(res);
+ this.setTitle(this._fileInfo.get_display_name());
+
+ /* now prepare the real renderer */
+ let klass = this._mimeHandler.getKlass(this._fileInfo.get_content_type());
+ this._createView(file, klass);
+ this._createToolbar();
+ } catch(e) {
+ /* FIXME: report the error */
+ logError(e, 'Error creating viewer');
+ }
+ });
},
_createView : function (file, klass) {
@@ -269,9 +263,7 @@ var MainWindow = new Lang.Class({
this._toolbar.reveal_child = true;
this._removeToolbarTimeout();
- this._toolbarId = Mainloop.timeout_add(1500,
- Lang.bind(this,
- this._onToolbarTimeout));
+ this._toolbarId = Mainloop.timeout_add(1500, this._onToolbarTimeout.bind(this));
},
_onToolbarTimeout : function() {
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index 9ba3e3b..8599095 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -105,30 +105,21 @@ const AudioRenderer = new Lang.Class({
this._player.playing = true;
this._playerNotifies.push(
- this._player.connect('notify::progress',
- Lang.bind(this, this._onPlayerProgressChanged)));
+ this._player.connect('notify::progress', this._onPlayerProgressChanged.bind(this)));
this._playerNotifies.push(
- this._player.connect('notify::duration',
- Lang.bind(this, this._onPlayerDurationChanged)));
+ this._player.connect('notify::duration', this._onPlayerDurationChanged.bind(this)));
this._playerNotifies.push(
- this._player.connect('notify::state',
- Lang.bind(this, this._onPlayerStateChanged)));
+ this._player.connect('notify::state', this._onPlayerStateChanged.bind(this)));
this._playerNotifies.push(
- this._player.connect('notify::taglist',
- Lang.bind(this, this._onTagListChanged)));
+ this._player.connect('notify::taglist', this._onTagListChanged.bind(this)));
this._playerNotifies.push(
- this._player.connect('notify::cover',
- Lang.bind(this, this._onCoverArtChanged)));
+ this._player.connect('notify::cover', this._onCoverArtChanged.bind(this)));
},
_onDestroy : function() {
- this._playerNotifies.forEach(Lang.bind(this,
- function(id) {
- this._player.disconnect(id);
- }));
-
- this._player.playing = false;
+ this._playerNotifies.forEach((id) => this._player.disconnect(id));
this._playerNotifies = [];
+ this._player.playing = false;
this._player = null;
},
@@ -194,9 +185,7 @@ const AudioRenderer = new Lang.Class({
this._mainWindow.setTitle(windowTitle);
this._artFetcher = new Sushi.CoverArtFetcher();
- this._artFetcher.connect('notify::cover',
- Lang.bind(this, this._onCoverArtChanged));
-
+ this._artFetcher.connect('notify::cover', this._onCoverArtChanged.bind(this));
this._artFetcher.taglist = tags;
},
@@ -253,11 +242,10 @@ const AudioRenderer = new Lang.Class({
},
populateToolbar : function (toolbar) {
- this._toolbarPlay =
- Utils.createToolButton('media-playback-pause-symbolic', Lang.bind(this, function () {
- let playing = !this._player.playing;
- this._player.playing = playing;
- }));
+ this._toolbarPlay = Utils.createToolButton('media-playback-pause-symbolic', () => {
+ let playing = !this._player.playing;
+ this._player.playing = playing;
+ });
toolbar.add(this._toolbarPlay);
this._currentLabel = new Gtk.Label({ margin_start: 6,
@@ -269,11 +257,10 @@ const AudioRenderer = new Lang.Class({
0, 1000, 10);
this._progressBar.set_value(0);
this._progressBar.set_draw_value(false);
- this._progressBar.connect('value-changed',
- Lang.bind(this, function() {
- if(!this._isSettingValue)
- this._player.progress = this._progressBar.get_value() / 1000;
- }));
+ this._progressBar.connect('value-changed', () => {
+ if(!this._isSettingValue)
+ this._player.progress = this._progressBar.get_value() / 1000;
+ });
this._progressBar.set_size_request(200, -1);
toolbar.add(this._progressBar);
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 7daefd6..ec12052 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -54,8 +54,7 @@ const EvinceRenderer = new Lang.Class({
this._file = file;
this._pdfLoader = new Sushi.PdfLoader();
- this._pdfLoader.connect('notify::document',
- Lang.bind(this, this._onDocumentLoaded));
+ this._pdfLoader.connect('notify::document', this._onDocumentLoaded.bind(this));
this._pdfLoader.uri = file.get_uri();
this._view = EvView.View.new();
@@ -80,7 +79,7 @@ const EvinceRenderer = new Lang.Class({
this._model.set_sizing_mode(EvView.SizingMode.FIT_WIDTH);
this._model.set_continuous(true);
- this._model.connect('page-changed', Lang.bind(this, this._updatePageLabel));
+ this._model.connect('page-changed', this._updatePageLabel.bind(this));
this._updatePageLabel();
this._view.set_model(this._model);
@@ -91,10 +90,9 @@ const EvinceRenderer = new Lang.Class({
},
populateToolbar : function(toolbar) {
- this._toolbarBack =
- Utils.createToolButton('go-previous-symbolic', Lang.bind(this, function () {
- this._view.previous_page();
- }));
+ this._toolbarBack = Utils.createToolButton('go-previous-symbolic', () => {
+ this._view.previous_page();
+ });
toolbar.add(this._toolbarBack);
this._pageLabel = new Gtk.Label({ hexpand: true,
@@ -102,10 +100,9 @@ const EvinceRenderer = new Lang.Class({
margin_end: 10 });
toolbar.add(this._pageLabel);
- this._toolbarForward =
- Utils.createToolButton('go-next-symbolic', Lang.bind(this, function () {
- this._view.next_page();
- }));
+ this._toolbarForward = Utils.createToolButton('go-next-symbolic', () => {
+ this._view.next_page();
+ });
toolbar.add(this._toolbarForward);
let separator = new Gtk.Separator({ orientation: Gtk.Orientation.VERTICAL });
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index a03f947..1be8bdf 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -147,39 +147,33 @@ const ImageRenderer = new Lang.Class({
},
_createImageTexture : function(file) {
- file.read_async
- (GLib.PRIORITY_DEFAULT, null,
- Lang.bind(this,
- function(obj, res) {
- try {
- let stream = obj.read_finish(res);
- this._textureFromStream(stream);
- } catch (e) {
- }
- }));
+ file.read_async(GLib.PRIORITY_DEFAULT, null, (obj, res) => {
+ try {
+ let stream = obj.read_finish(res);
+ this._textureFromStream(stream);
+ } catch (e) {
+ }
+ });
},
_textureFromStream : function(stream) {
- GdkPixbuf.PixbufAnimation.new_from_stream_async
- (stream, null,
- Lang.bind(this, function(obj, res) {
- let anim = GdkPixbuf.PixbufAnimation.new_from_stream_finish(res);
+ GdkPixbuf.PixbufAnimation.new_from_stream_async(stream, null, (obj, res) => {
+ let anim = GdkPixbuf.PixbufAnimation.new_from_stream_finish(res);
- this._iter = anim.get_iter(null);
- this.pix = this._iter.get_pixbuf().apply_embedded_orientation();
+ this._iter = anim.get_iter(null);
+ this.pix = this._iter.get_pixbuf().apply_embedded_orientation();
- if (!anim.is_static_image())
- this._startTimeout();
+ if (!anim.is_static_image())
+ this._startTimeout();
- stream.close_async(GLib.PRIORITY_DEFAULT,
- null, function(object, res) {
- try {
- object.close_finish(res);
- } catch (e) {
- log('Unable to close the stream ' + e.toString());
- }
- });
- }));
+ stream.close_async(GLib.PRIORITY_DEFAULT, null, (obj, res) => {
+ try {
+ obj.close_finish(res);
+ } catch (e) {
+ log('Unable to close the stream ' + e.toString());
+ }
+ });
+ });
},
get resizePolicy() {
@@ -187,9 +181,8 @@ const ImageRenderer = new Lang.Class({
},
_startTimeout : function() {
- this._timeoutId = Mainloop.timeout_add(this._iter.get_delay_time(),
- Lang.bind(this,
- this._advanceImage));
+ this._timeoutId = Mainloop.timeout_add(
+ this._iter.get_delay_time(), this._advanceImage.bind(this));
},
populateToolbar : function(toolbar) {
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index edc263c..8c14946 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -50,8 +50,7 @@ const TextRenderer = new Lang.Class({
this._file = file;
let textLoader = new Sushi.TextLoader();
- textLoader.connect('loaded',
- Lang.bind(this, this._onBufferLoaded));
+ textLoader.connect('loaded', this._onBufferLoaded.bind(this));
textLoader.uri = file.get_uri();
this._geditScheme = 'tango';
@@ -69,13 +68,13 @@ const TextRenderer = new Lang.Class({
cursor_visible: false,
monospace: true });
this._view.set_can_focus(false);
- this._view.connect('button-press-event', Lang.bind(this, function(view, event) {
+ this._view.connect('button-press-event', (view, event) => {
let [, button] = event.get_button();
if (button == Gdk.BUTTON_SECONDARY)
return true;
return false;
- }));
+ });
this.add(this._view);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]