[sushi/wip/cosimoc/no-clutter: 58/66] Port to ES6 classes
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi/wip/cosimoc/no-clutter: 58/66] Port to ES6 classes
- Date: Sat, 8 Jun 2019 18:45:01 +0000 (UTC)
commit bad486b0173b013bc59963dea114511cc74d771d
Author: Cosimo Cecchi <cosimo endlessm com>
Date: Fri Jun 7 11:34:44 2019 -0700
Port to ES6 classes
This makes the code much simpler and more maintainable.
src/js/ui/application.js | 43 ++++++++-----------
src/js/ui/fallbackRenderer.js | 30 ++++++--------
src/js/ui/main.js | 4 +-
src/js/ui/mainWindow.js | 96 ++++++++++++++++++++-----------------------
src/js/ui/renderer.js | 14 +++----
src/js/viewers/audio.js | 64 ++++++++++++++---------------
src/js/viewers/evince.js | 30 ++++++--------
src/js/viewers/font.js | 15 +++----
src/js/viewers/gst.js | 19 ++++-----
src/js/viewers/html.js | 18 ++++----
src/js/viewers/image.js | 82 +++++++++++++++++-------------------
src/js/viewers/text.js | 23 ++++-------
12 files changed, 192 insertions(+), 246 deletions(-)
---
diff --git a/src/js/ui/application.js b/src/js/ui/application.js
index 03c2b1a..381f4ed 100644
--- a/src/js/ui/application.js
+++ b/src/js/ui/application.js
@@ -23,13 +23,11 @@
*
*/
-const {Gdk, Gio, GLib, Gtk} = imports.gi;
-const Lang = imports.lang;
+const {Gdk, Gio, GLib, GObject, Gtk} = imports.gi;
const MainWindow = imports.ui.mainWindow;
const SUSHI_DBUS_PATH = '/org/gnome/NautilusPreviewer';
-const SUSHI_DBUS_NAME = 'org.gnome.NautilusPreviewer';
const SushiIface = '<node> \
<interface name="org.gnome.NautilusPreviewer"> \
@@ -43,37 +41,30 @@ const SushiIface = '<node> \
</interface> \
</node>';
-var Application = new Lang.Class({
- Name: 'Application',
- Extends: Gtk.Application,
-
- _init : function(args) {
- this.parent({ application_id: SUSHI_DBUS_NAME });
- },
-
- vfunc_startup : function() {
- this.parent();
+var Application = GObject.registerClass(class Application extends Gtk.Application {
+ vfunc_startup() {
+ super.vfunc_startup();
this._defineStyleAndThemes();
this._createMainWindow();
- },
+ }
- vfunc_dbus_register : function(connection, path) {
+ vfunc_dbus_register(connection, path) {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(SushiIface, this);
this._dbusImpl.export(connection, SUSHI_DBUS_PATH);
- return this.parent(connection, path);
- },
+ return super.vfunc_dbus_register(connection, path);
+ }
- vfunc_activate : function() {
- },
+ vfunc_activate() {
+ }
- _createMainWindow : function() {
+ _createMainWindow() {
this._mainWindow =
new MainWindow.MainWindow(this);
- },
+ }
- _defineStyleAndThemes : function() {
+ _defineStyleAndThemes() {
let provider = new Gtk.CssProvider();
provider.load_from_resource('/org/gnome/Sushi/gtk-style.css');
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
@@ -82,13 +73,13 @@ var Application = new Lang.Class({
let settings = Gtk.Settings.get_default();
settings.gtk_application_prefer_dark_theme = true;
- },
+ }
- Close: function() {
+ Close() {
this._mainWindow.destroy();
- },
+ }
- ShowFile : function(uri, xid, closeIfAlreadyShown) {
+ ShowFile(uri, xid, closeIfAlreadyShown) {
let file = Gio.file_new_for_uri(uri);
if (closeIfAlreadyShown &&
this._mainWindow.file &&
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index 45d7e6b..ba8a348 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -23,19 +23,15 @@
*
*/
-const {Gio, Gtk, Pango, Sushi} = imports.gi;
+const {Gio, GObject, Gtk, Pango, Sushi} = imports.gi;
const Gettext = imports.gettext.domain('sushi');
const _ = Gettext.gettext;
-const Lang = imports.lang;
const Renderer = imports.ui.renderer;
-var FallbackRenderer = new Lang.Class({
- Name: 'FallbackRenderer',
- Extends: Gtk.Box,
-
- _init : function(file, mainWindow) {
- this.parent({ orientation: Gtk.Orientation.HORIZONTAL,
+var FallbackRenderer = GObject.registerClass(class FallbackRenderer extends Gtk.Box {
+ _init(file, mainWindow) {
+ super._init({ orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6 });
this.moveOnClick = true;
@@ -87,9 +83,9 @@ var FallbackRenderer = new Lang.Class({
this._applyLabels();
this.connect('destroy', this._onDestroy.bind(this));
- },
+ }
- _applyLabels : function() {
+ _applyLabels() {
let titleStr =
'<b><big>' +
((this._fileLoader.name) ? (this._fileLoader.name) : (this._fileLoader.file.get_basename()))
@@ -117,9 +113,9 @@ var FallbackRenderer = new Lang.Class({
((this._fileLoader.time) ? (this._fileLoader.time) : (_("Loading…")))
+ '</small>';
this._dateLabel.set_markup(dateStr);
- },
+ }
- _updateIcon: function(icon) {
+ _updateIcon(icon) {
let iconTheme = Gtk.IconTheme.get_default();
let iconInfo = iconTheme.lookup_by_gicon_for_scale(icon, 256,
this._image.scale_factor, 0);
@@ -132,9 +128,9 @@ var FallbackRenderer = new Lang.Class({
} catch (e) {
logError(e, `Error loading surface for icon ${icon.to_string()}`);
}
- },
+ }
- _onFileInfoChanged : function() {
+ _onFileInfoChanged() {
if (!this._fileLoader.get_loading()) {
this._spinner.stop();
this._spinner.hide();
@@ -144,9 +140,9 @@ var FallbackRenderer = new Lang.Class({
this._updateIcon(this._fileLoader.icon);
this._applyLabels();
- },
+ }
- _onDestroy : function() {
+ _onDestroy() {
if (this._fileLoader) {
this._fileLoader.disconnect(this._fileLoaderId);
this._fileLoaderId = 0;
@@ -154,7 +150,7 @@ var FallbackRenderer = new Lang.Class({
this._fileLoader.stop();
this._fileLoader = null;
}
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.NAT_SIZE;
diff --git a/src/js/ui/main.js b/src/js/ui/main.js
index c77189f..c84b764 100644
--- a/src/js/ui/main.js
+++ b/src/js/ui/main.js
@@ -33,12 +33,14 @@ const Gettext = imports.gettext;
const Application = imports.ui.application;
const Path = imports.util.path;
+const SUSHI_DBUS_NAME = 'org.gnome.NautilusPreviewer';
+
function run(argv) {
Gettext.bindtextdomain('sushi', Path.LOCALE_DIR);
String.prototype.format = Format.format;
GLib.set_application_name('Sushi');
- let application = new Application.Application();
+ let application = new Application.Application({ application_id: SUSHI_DBUS_NAME });
return application.run(null);
}
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 31a6cb7..05a3525 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -23,9 +23,8 @@
*
*/
-const {Gdk, Gio, GLib, Gtk, Sushi} = imports.gi;
+const {Gdk, Gio, GLib, GObject, Gtk, Sushi} = imports.gi;
-const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Constants = imports.util.constants;
@@ -33,17 +32,15 @@ const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
const Utils = imports.ui.utils;
-const Embed = new Lang.Class({
- Name: 'Embed',
- Extends: Gtk.Overlay,
- Signals: { 'size-request': {} },
-
- vfunc_get_request_mode: function() {
+const Embed = GObject.registerClass({
+ Signals: { 'size-request': {} }
+}, class Embed extends Gtk.Overlay {
+ vfunc_get_request_mode() {
return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
- },
+ }
- vfunc_get_preferred_width: function() {
- let [min, nat] = this.parent();
+ vfunc_get_preferred_width() {
+ let [min, nat] = super.vfunc_get_preferred_width();
min = Math.max(min, Constants.VIEW_MIN);
nat = Math.max(nat, Constants.VIEW_MIN);
@@ -56,11 +53,8 @@ const Embed = new Lang.Class({
}
});
-var MainWindow = new Lang.Class({
- Name: 'MainWindow',
- Extends: Gtk.Window,
-
- _init : function(application) {
+var MainWindow = GObject.registerClass(class MainWindow extends Gtk.Window {
+ _init(application) {
this._isFullScreen = false;
this._renderer = null;
this._lastWindowSize = [0, 0];
@@ -71,7 +65,7 @@ var MainWindow = new Lang.Class({
this._mimeHandler = new MimeHandler.MimeHandler();
- this.parent({ type: Gtk.WindowType.TOPLEVEL,
+ super._init({ type: Gtk.WindowType.TOPLEVEL,
skipPagerHint: true,
skipTaskbarHint: true,
windowPosition: Gtk.WindowPosition.CENTER,
@@ -92,23 +86,23 @@ var MainWindow = new Lang.Class({
this._embed = new Embed();
this._embed.connect('size-request', this._onEmbedSizeRequest.bind(this));
this.add(this._embed);
- },
+ }
/**************************************************************************
****************** main object event callbacks ***************************
**************************************************************************/
- _onDeleteEvent : function() {
+ _onDeleteEvent() {
this.destroy();
- },
+ }
- _onRealize: function() {
+ _onRealize() {
// don't support maximize and minimize
this.get_window().set_functions(Gdk.WMFunction.MOVE |
Gdk.WMFunction.RESIZE |
Gdk.WMFunction.CLOSE);
- },
+ }
- _onKeyPressEvent : function(widget, event) {
+ _onKeyPressEvent(widget, event) {
let key = event.get_keyval()[1];
if (key == Gdk.KEY_Escape ||
@@ -121,9 +115,9 @@ var MainWindow = new Lang.Class({
this.toggleFullScreen();
return false;
- },
+ }
- _onButtonPressEvent : function(window, event) {
+ _onButtonPressEvent(window, event) {
if (!this._renderer.moveOnClick)
return false;
@@ -134,23 +128,23 @@ var MainWindow = new Lang.Class({
event.get_time());
return false;
- },
+ }
- _onMotionNotifyEvent : function() {
+ _onMotionNotifyEvent() {
if (this._toolbar)
this._resetToolbar();
return false;
- },
+ }
/**************************************************************************
*********************** texture allocation *******************************
**************************************************************************/
- _onEmbedSizeRequest : function() {
+ _onEmbedSizeRequest() {
this._resizeWindow();
- },
+ }
- _resizeWindow : function() {
+ _resizeWindow() {
if (this._isFullScreen)
return;
@@ -177,9 +171,9 @@ var MainWindow = new Lang.Class({
this._lastWindowSize = windowSize;
this.resize(windowSize[0], windowSize[1]);
}
- },
+ }
- _createRenderer : function(file) {
+ _createRenderer(file) {
file.query_info_async(
[Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE].join(','),
@@ -198,9 +192,9 @@ var MainWindow = new Lang.Class({
logError(e, 'Error creating viewer');
}
});
- },
+ }
- _createView : function (file, klass) {
+ _createView(file, klass) {
if (this._renderer) {
this._renderer.destroy()
this._renderer = null;
@@ -210,12 +204,12 @@ var MainWindow = new Lang.Class({
this._renderer.show_all();
this._renderer.expand = true;
this._embed.add(this._renderer);
- },
+ }
/**************************************************************************
************************* toolbar helpers ********************************
**************************************************************************/
- _createToolbar : function() {
+ _createToolbar() {
this._removeToolbarTimeout();
if (this._toolbar) {
@@ -244,33 +238,33 @@ var MainWindow = new Lang.Class({
return;
this._embed.add_overlay(this._toolbar);
- },
+ }
- _removeToolbarTimeout: function() {
+ _removeToolbarTimeout() {
if (this._toolbarId != 0) {
Mainloop.source_remove(this._toolbarId);
this._toolbarId = 0;
}
- },
+ }
- _resetToolbar : function() {
+ _resetToolbar() {
if (this._toolbarId == 0)
this._toolbar.reveal_child = true;
this._removeToolbarTimeout();
this._toolbarId = Mainloop.timeout_add(1500, this._onToolbarTimeout.bind(this));
- },
+ }
- _onToolbarTimeout : function() {
+ _onToolbarTimeout() {
this._toolbarId = 0;
this._toolbar.reveal_child = false;
return false;
- },
+ }
/**************************************************************************
************************ public methods **********************************
**************************************************************************/
- setParent : function(xid) {
+ setParent(xid) {
this._parent = Sushi.create_foreign_window(xid);
this.realize();
if (this._parent)
@@ -279,18 +273,18 @@ var MainWindow = new Lang.Class({
if (this.get_window().move_to_current_desktop)
this.get_window().move_to_current_desktop();
- },
+ }
- setFile : function(file) {
+ setFile(file) {
this.file = file;
this._createRenderer(file);
- },
+ }
- setTitle : function(label) {
+ setTitle(label) {
this.set_title(label);
- },
+ }
- toggleFullScreen : function() {
+ toggleFullScreen() {
if (!this._renderer.canFullScreen)
return false;
diff --git a/src/js/ui/renderer.js b/src/js/ui/renderer.js
index 7407d74..d64435e 100644
--- a/src/js/ui/renderer.js
+++ b/src/js/ui/renderer.js
@@ -1,6 +1,4 @@
-const {Gtk} = imports.gi;
-
-const Lang = imports.lang;
+const {GObject, Gtk} = imports.gi;
var ResizePolicy = {
MAX_SIZE: 0,
@@ -9,13 +7,11 @@ var ResizePolicy = {
STRETCHED: 3
};
-var RendererToolbar = new Lang.Class({
- Name: 'RendererToolbar',
- Extends: Gtk.Box,
+var RendererToolbar = GObject.registerClass({
CssName: 'toolbar',
-
- _init : function() {
- this.parent({ halign: Gtk.Align.CENTER,
+}, class RendererToolbar extends Gtk.Box {
+ _init() {
+ super._init({ halign: Gtk.Align.CENTER,
hexpand: true });
this.get_style_context().add_class('osd');
}
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index d4fedb9..adb18cc 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -23,11 +23,10 @@
*
*/
-const {GdkPixbuf, Gio, Gst, Gtk, Sushi} = imports.gi;
+const {GdkPixbuf, Gio, GObject, Gst, Gtk, Sushi} = imports.gi;
const Gettext = imports.gettext.domain('sushi');
const _ = Gettext.gettext;
-const Lang = imports.lang;
const Constants = imports.util.constants;
const MimeHandler = imports.ui.mimeHandler;
@@ -52,12 +51,9 @@ function _formatTimeString(timeVal) {
return str;
}
-const AudioRenderer = new Lang.Class({
- Name: 'AudioRenderer',
- Extends: Gtk.Box,
-
- _init : function(file, mainWindow) {
- this.parent({ orientation: Gtk.Orientation.HORIZONTAL,
+const AudioRenderer = GObject.registerClass(class AudioRenderer extends Gtk.Box {
+ _init(file, mainWindow) {
+ super._init({ orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6 });
this.moveOnClick = true;
@@ -92,9 +88,9 @@ const AudioRenderer = new Lang.Class({
vbox.pack_start(this._albumLabel, false, false, 0);
this.connect('destroy', this._onDestroy.bind(this));
- },
+ }
- _createPlayer : function(file) {
+ _createPlayer(file) {
this._playerNotifies = [];
this._player = new Sushi.SoundPlayer({ uri: file.get_uri() });
@@ -110,16 +106,16 @@ const AudioRenderer = new Lang.Class({
this._player.connect('notify::taglist', this._onTagListChanged.bind(this)));
this._playerNotifies.push(
this._player.connect('notify::cover', this._onCoverArtChanged.bind(this)));
- },
+ }
- _onDestroy : function() {
+ _onDestroy() {
this._playerNotifies.forEach((id) => this._player.disconnect(id));
this._playerNotifies = [];
this._player.playing = false;
this._player = null;
- },
+ }
- _ensurePixbufSize : function(cover) {
+ _ensurePixbufSize(cover) {
let width, height;
width = cover.get_width();
@@ -139,9 +135,9 @@ const AudioRenderer = new Lang.Class({
} else {
this._coverArt = cover;
}
- },
+ }
- _onCoverArtChanged : function() {
+ _onCoverArtChanged() {
if (!this._artFetcher.cover) {
this._image.set_from_icon_name('media-optical-symbolic');
return;
@@ -149,9 +145,9 @@ const AudioRenderer = new Lang.Class({
this._ensurePixbufSize(this._artFetcher.cover);
this._image.set_from_pixbuf(this._coverArt);
- },
+ }
- _onTagListChanged : function() {
+ _onTagListChanged() {
let tags = this._player.taglist;
let albumName = tags.get_string('album')[1];
let artistName = tags.get_string('artist')[1];
@@ -183,18 +179,18 @@ const AudioRenderer = new Lang.Class({
this._artFetcher = new Sushi.CoverArtFetcher();
this._artFetcher.connect('notify::cover', this._onCoverArtChanged.bind(this));
this._artFetcher.taglist = tags;
- },
+ }
- _updateProgressBar : function() {
+ _updateProgressBar() {
if (!this._progressBar)
return;
this._isSettingValue = true;
this._progressBar.set_value(this._player.progress * 1000);
this._isSettingValue = false;
- },
+ }
- _updateCurrentLabel : function() {
+ _updateCurrentLabel() {
if (!this._currentLabel)
return;
@@ -202,27 +198,27 @@ const AudioRenderer = new Lang.Class({
Math.floor(this._player.duration * this._player.progress);
this._currentLabel.set_text(_formatTimeString(currentTime));
- },
+ }
- _updateDurationLabel : function() {
+ _updateDurationLabel() {
if (!this._durationLabel)
return;
let totalTime = this._player.duration;
this._durationLabel.set_text(_formatTimeString(totalTime));
- },
+ }
- _onPlayerProgressChanged : function() {
+ _onPlayerProgressChanged() {
this._updateProgressBar();
this._updateCurrentLabel();
- },
+ }
- _onPlayerDurationChanged : function() {
+ _onPlayerDurationChanged() {
this._updateDurationLabel();
- },
+ }
- _onPlayerStateChanged : function() {
+ _onPlayerStateChanged() {
switch(this._player.state) {
case Sushi.SoundPlayerState.PLAYING:
this._toolbarPlay.image.set_from_icon_name('media-playback-pause-symbolic', Gtk.IconSize.MENU);
@@ -231,13 +227,13 @@ const AudioRenderer = new Lang.Class({
let iconName = 'media-playback-start-symbolic';
this._toolbarPlay.image.set_from_icon_name(iconName, Gtk.IconSize.MENU);
}
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.NAT_SIZE;
- },
+ }
- populateToolbar : function (toolbar) {
+ populateToolbar(toolbar) {
this._toolbarPlay = Utils.createToolButton('media-playback-pause-symbolic', () => {
let playing = !this._player.playing;
this._player.playing = playing;
@@ -262,7 +258,7 @@ const AudioRenderer = new Lang.Class({
this._durationLabel = new Gtk.Label({ margin_start: 3 });
toolbar.add(this._durationLabel);
- },
+ }
});
let handler = new MimeHandler.MimeHandler();
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index a79d26b..c73096b 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -23,23 +23,19 @@
*
*/
-const {EvinceDocument, EvinceView, Gtk, Sushi} = imports.gi;
+const {EvinceDocument, EvinceView, GObject, Gtk, Sushi} = imports.gi;
const Gettext = imports.gettext.domain('sushi');
const _ = Gettext.gettext;
-const Lang = imports.lang;
const Constants = imports.util.constants;
const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
const Utils = imports.ui.utils;
-const EvinceRenderer = new Lang.Class({
- Name: 'EvinceRenderer',
- Extends: Gtk.ScrolledWindow,
-
- _init : function(file, mainWindow) {
- this.parent({ visible: true });
+const EvinceRenderer = GObject.registerClass(class EvinceRenderer extends Gtk.ScrolledWindow {
+ _init(file, mainWindow) {
+ super._init({ visible: true });
this.set_min_content_width(Constants.VIEW_MIN);
this.set_min_content_height(Constants.VIEW_MIN);
@@ -59,9 +55,9 @@ const EvinceRenderer = new Lang.Class({
this.add(this._view);
this.connect('destroy', this._onDestroy.bind(this));
- },
+ }
- _updatePageLabel : function() {
+ _updatePageLabel() {
let curPage = this._model.get_page();
let totPages = this._model.document.get_n_pages();
@@ -69,9 +65,9 @@ const EvinceRenderer = new Lang.Class({
this._toolbarForward.set_sensitive(curPage < totPages - 1);
this._pageLabel.set_text(_("%d of %d").format(curPage + 1, totPages));
- },
+ }
- _onDocumentLoaded : function(pdfLoader) {
+ _onDocumentLoaded(pdfLoader) {
this._model = EvinceView.DocumentModel.new_with_document(pdfLoader.document);
this._model.set_sizing_mode(EvinceView.SizingMode.FIT_WIDTH);
this._model.set_continuous(true);
@@ -80,13 +76,13 @@ const EvinceRenderer = new Lang.Class({
this._updatePageLabel();
this._view.set_model(this._model);
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.MAX_SIZE;
- },
+ }
- populateToolbar : function(toolbar) {
+ populateToolbar(toolbar) {
this._toolbarBack = Utils.createToolButton('go-previous-symbolic', () => {
this._view.previous_page();
});
@@ -107,9 +103,9 @@ const EvinceRenderer = new Lang.Class({
let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
toolbar.add(toolbarZoom);
- },
+ }
- _onDestroy : function() {
+ _onDestroy() {
this._pdfLoader = null;
}
});
diff --git a/src/js/viewers/font.js b/src/js/viewers/font.js
index 01109d4..329e42e 100644
--- a/src/js/viewers/font.js
+++ b/src/js/viewers/font.js
@@ -23,25 +23,20 @@
*
*/
-const {Gtk, GLib, Sushi} = imports.gi;
-
-const Lang = imports.lang;
+const {GLib, GObject, Gtk, Sushi} = imports.gi;
const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
-const FontRenderer = new Lang.Class({
- Name: 'FontRenderer',
- Extends: Sushi.FontWidget,
-
- _init : function(file, mainWindow) {
- this.parent({ uri: file.get_uri(),
+const FontRenderer = GObject.registerClass(class FontRenderer extends Sushi.FontWidget {
+ _init(file, mainWindow) {
+ super._init({ uri: file.get_uri(),
visible: true })
this.moveOnClick = true;
this.canFullScreen = true;
this._file = file;
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.MAX_SIZE;
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index 9054bb2..c73de5c 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -23,21 +23,16 @@
*
*/
-const {GLib, Sushi} = imports.gi;
-
-const Lang = imports.lang;
+const {GLib, GObject, Sushi} = imports.gi;
const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
const TotemMimeTypes = imports.util.totemMimeTypes;
const Utils = imports.ui.utils;
-const GstRenderer = new Lang.Class({
- Name: 'GstRenderer',
- Extends: Sushi.MediaBin,
-
- _init : function(file, mainWindow) {
- this.parent({ uri: file.get_uri() });
+const GstRenderer = GObject.registerClass(class GstRenderer extends Sushi.MediaBin {
+ _init(file, mainWindow) {
+ super._init({ uri: file.get_uri() });
this.moveOnClick = true;
// fullscreen is handled internally by the widget
@@ -50,14 +45,14 @@ const GstRenderer = new Lang.Class({
});
this.connect('destroy', this._onDestroy.bind(this));
- },
+ }
- _onDestroy : function() {
+ _onDestroy() {
if (this._autoplayId > 0) {
GLib.source_remove(this._autoplayId);
this._autoplayId = 0;
}
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.STRETCHED;
diff --git a/src/js/viewers/html.js b/src/js/viewers/html.js
index 9cab7a9..eb9bad8 100644
--- a/src/js/viewers/html.js
+++ b/src/js/viewers/html.js
@@ -23,19 +23,15 @@
*
*/
-const {Gtk, GLib, Sushi, WebKit2} = imports.gi;
-const Lang = imports.lang;
+const {Gtk, GLib, GObject, Sushi, WebKit2} = imports.gi;
const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
const Utils = imports.ui.utils;
-const HTMLRenderer = new Lang.Class({
- Name: 'HTMLRenderer',
- Extends: WebKit2.WebView,
-
- _init : function(file, mainWindow) {
- this.parent();
+const HTMLRenderer = GObject.registerClass(class HTMLRenderer extends WebKit2.WebView {
+ _init(file, mainWindow) {
+ super._init();
this.moveOnClick = false;
this.canFullScreen = true;
@@ -48,13 +44,13 @@ const HTMLRenderer = new Lang.Class({
function() {return true;});
this.load_uri(file.get_uri());
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.MAX_SIZE;
- },
+ }
- populateToolbar : function(toolbar) {
+ populateToolbar(toolbar) {
let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
toolbar.add(toolbarZoom);
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index 9094429..b4bbfb6 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -29,30 +29,27 @@ const {Gdk, GdkPixbuf, GLib, GObject, Gtk} = imports.gi;
const Gettext = imports.gettext.domain('sushi');
const _ = Gettext.gettext;
-const Lang = imports.lang;
const Mainloop = imports.mainloop;
const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
const Utils = imports.ui.utils;
-const Image = new Lang.Class({
- Name: 'Image',
- Extends: Gtk.DrawingArea,
+const Image = GObject.registerClass({
Properties: {
- 'pix': GObject.ParamSpec.object('pix', '', '',
- GObject.ParamFlags.READWRITE,
- GdkPixbuf.Pixbuf)
- },
+ pix: GObject.ParamSpec.object('pix', '', '',
+ GObject.ParamFlags.READWRITE,
+ GdkPixbuf.Pixbuf)
+ }
+}, class Image extends Gtk.DrawingArea {
+ _init() {
+ super._init();
- _init: function() {
this._pix = null;
this._scaledSurface = null;
+ }
- this.parent();
- },
-
- _ensureScaledPix: function() {
+ _ensureScaledPix() {
if (!this._pix)
return;
@@ -81,22 +78,22 @@ const Image = new Lang.Class({
scaleFactor,
this.get_window());
}
- },
+ }
- vfunc_get_preferred_width: function() {
+ vfunc_get_preferred_width() {
return [1, this._pix ? this.pix.get_width() : 1];
- },
+ }
- vfunc_get_preferred_height: function() {
+ vfunc_get_preferred_height() {
return [1, this._pix ? this.pix.get_height() : 1];
- },
+ }
- vfunc_size_allocate: function(allocation) {
- this.parent(allocation);
+ vfunc_size_allocate(allocation) {
+ super.vfunc_size_allocate(allocation);
this._ensureScaledPix();
- },
+ }
- vfunc_draw: function(context) {
+ vfunc_draw(context) {
if (!this._scaledSurface)
return false;
@@ -110,25 +107,22 @@ const Image = new Lang.Class({
context.setSourceSurface(this._scaledSurface, offsetX, offsetY);
context.paint();
return false;
- },
+ }
set pix(p) {
this._pix = p;
this._scaledSurface = null;
this.queue_resize();
- },
+ }
get pix() {
return this._pix;
}
});
-const ImageRenderer = new Lang.Class({
- Name: 'ImageRenderer',
- Extends: Image,
-
- _init : function(file, mainWindow) {
- this.parent();
+const ImageRenderer = GObject.registerClass(class ImageRenderer extends Image {
+ _init(file, mainWindow) {
+ super._init();
this._timeoutId = 0;
this.moveOnClick = true;
@@ -140,9 +134,9 @@ const ImageRenderer = new Lang.Class({
this._createImageTexture(file);
this.connect('destroy', this._onDestroy.bind(this));
- },
+ }
- _createImageTexture : function(file) {
+ _createImageTexture(file) {
file.read_async(GLib.PRIORITY_DEFAULT, null, (obj, res) => {
try {
let stream = obj.read_finish(res);
@@ -150,9 +144,9 @@ const ImageRenderer = new Lang.Class({
} catch (e) {
}
});
- },
+ }
- _textureFromStream : function(stream) {
+ _textureFromStream(stream) {
GdkPixbuf.PixbufAnimation.new_from_stream_async(stream, null, (obj, res) => {
let anim = GdkPixbuf.PixbufAnimation.new_from_stream_finish(res);
@@ -170,23 +164,23 @@ const ImageRenderer = new Lang.Class({
}
});
});
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.SCALED;
- },
+ }
- _startTimeout : function() {
+ _startTimeout() {
this._timeoutId = Mainloop.timeout_add(
this._iter.get_delay_time(), this._advanceImage.bind(this));
- },
+ }
- populateToolbar : function(toolbar) {
+ populateToolbar(toolbar) {
let toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
toolbar.add(toolbarZoom);
- },
+ }
- _onDestroy : function () {
+ _onDestroy() {
/* We should do the check here because it is possible
* that we never created a source if our image is
* not animated. */
@@ -194,14 +188,14 @@ const ImageRenderer = new Lang.Class({
Mainloop.source_remove(this._timeoutId);
this._timeoutId = 0;
}
- },
+ }
- _advanceImage : function () {
+ _advanceImage() {
this._iter.advance(null);
let pix = this._iter.get_pixbuf().apply_embedded_orientation();
this.set_from_pixbuf(pix);
return true;
- },
+ }
});
let handler = new MimeHandler.MimeHandler();
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index de27795..06a1bf6 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -25,20 +25,15 @@
imports.gi.versions.GtkSource = '4';
-const {Gdk, Gio, GLib, Gtk, GtkSource, Sushi} = imports.gi;
-
-const Lang = imports.lang;
+const {Gdk, Gio, GLib, GObject, Gtk, GtkSource, Sushi} = imports.gi;
const MimeHandler = imports.ui.mimeHandler;
const Renderer = imports.ui.renderer;
const Utils = imports.ui.utils;
-const TextRenderer = new Lang.Class({
- Name: 'TextRenderer',
- Extends: Gtk.ScrolledWindow,
-
- _init : function(file, mainWindow) {
- this.parent();
+const TextRenderer = GObject.registerClass(class TextRenderer extends Gtk.ScrolledWindow {
+ _init(file, mainWindow) {
+ super._init();
this.moveOnClick = false;
this.canFullScreen = true;
@@ -73,9 +68,9 @@ const TextRenderer = new Lang.Class({
});
this.add(this._view);
- },
+ }
- _onBufferLoaded : function(loader, buffer) {
+ _onBufferLoaded(loader, buffer) {
this._buffer = buffer;
this._buffer.highlight_syntax = true;
@@ -86,13 +81,13 @@ const TextRenderer = new Lang.Class({
this._view.set_buffer(this._buffer);
if (this._buffer.get_language())
this._view.set_show_line_numbers(true);
- },
+ }
get resizePolicy() {
return Renderer.ResizePolicy.MAX_SIZE;
- },
+ }
- populateToolbar : function(toolbar) {
+ populateToolbar(toolbar) {
let toolbarRun = Utils.createOpenButton(this._file, this._mainWindow);
toolbar.add(toolbarRun);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]