[gnome-documents] Initial port to ES6
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] Initial port to ES6
- Date: Mon, 5 Aug 2019 14:03:21 +0000 (UTC)
commit 4e2351eca029b90941e26a507e2f53ee8646ad45
Author: Christopher Davis <brainblasted disroot org>
Date: Sun Apr 21 13:49:52 2019 -0400
Initial port to ES6
src/application.js | 114 +++++-----
src/changeMonitor.js | 44 ++--
src/documents.js | 517 ++++++++++++++++++++++-----------------------
src/edit.js | 63 +++---
src/embed.js | 55 +++--
src/errorBox.js | 16 +-
src/evinceview.js | 218 +++++++++----------
src/fullscreenAction.js | 78 ++++---
src/lokview.js | 74 ++++---
src/mainToolbar.js | 34 ++-
src/mainWindow.js | 38 ++--
src/manager.js | 90 ++++----
src/notifications.js | 86 ++++----
src/overview.js | 330 ++++++++++++++---------------
src/password.js | 10 +-
src/places.js | 30 ++-
src/presentation.js | 86 ++++----
src/preview.js | 306 +++++++++++++--------------
src/properties.js | 10 +-
src/query.js | 68 +++---
src/search.js | 248 +++++++++-------------
src/searchbar.js | 42 ++--
src/selections.js | 284 ++++++++++++-------------
src/sharing.js | 77 ++++---
src/shellSearchProvider.js | 108 +++++-----
src/trackerController.js | 163 +++++++-------
src/trackerUtils.js | 20 +-
src/windowMode.js | 21 +-
28 files changed, 1509 insertions(+), 1721 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 23a959b1..ea4311e4 100644
--- a/src/application.js
+++ b/src/application.js
@@ -92,14 +92,12 @@ function TrackerExtractPriority() {
const MINER_REFRESH_TIMEOUT = 60; /* seconds */
-var Application = new Lang.Class({
- Name: 'Application',
- Extends: Gtk.Application,
+var Application = GObject.registerClass({
Signals: {
'miners-changed': {}
- },
-
- _init: function() {
+ }
+}, class Application extends Gtk.Application {
+ _init() {
this.minersRunning = [];
this._activationTimestamp = Gdk.CURRENT_TIME;
this._extractPriority = null;
@@ -112,14 +110,14 @@ var Application = new Lang.Class({
// needed by data/ui/view-menu.ui
GObject.type_ensure(Gio.ThemedIcon);
- this.parent({ application_id: appid,
+ super._init({ application_id: appid,
inactivity_timeout: 12000 });
this.add_main_option('version', 'v'.charCodeAt(0), GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
_("Show the version of the program"), null);
- },
+ }
- _initGettingStarted: function() {
+ _initGettingStarted() {
let manager = TrackerControl.MinerManager.new_full(false);
let languages = GLib.get_language_names();
@@ -153,9 +151,9 @@ var Application = new Lang.Class({
if (!this.gettingStartedLocation)
log('Can\'t find a valid getting started PDF document');
- },
+ }
- _nightModeCreateHook: function(action) {
+ _nightModeCreateHook(action) {
settings.connect('changed::night-mode', Lang.bind(this,
function() {
let state = settings.get_value('night-mode');
@@ -169,17 +167,17 @@ var Application = new Lang.Class({
let state = settings.get_value('night-mode');
let gtkSettings = Gtk.Settings.get_default();
gtkSettings.gtk_application_prefer_dark_theme = state.get_boolean();
- },
+ }
- _onActionQuit: function() {
+ _onActionQuit() {
this._mainWindow.destroy();
- },
+ }
- _onActionAbout: function() {
+ _onActionAbout() {
this._mainWindow.showAbout();
- },
+ }
- _onActionHelp: function() {
+ _onActionHelp() {
try {
Gtk.show_uri_on_window(this._mainWindow,
'help:gnome-documents',
@@ -187,14 +185,14 @@ var Application = new Lang.Class({
} catch (e) {
logError(e, 'Unable to display help');
}
- },
+ }
- _onActionNightMode: function(action) {
+ _onActionNightMode(action) {
let state = action.get_state();
settings.set_value('night-mode', GLib.Variant.new('b', !state.get_boolean()));
- },
+ }
- _createMiners: function(callback) {
+ _createMiners(callback) {
let count = 3;
this.gdataMiner = new Miners.GDataMiner(Lang.bind(this,
@@ -217,9 +215,9 @@ var Application = new Lang.Class({
if (count == 0)
callback();
}));
- },
+ }
- _refreshMinerNow: function(miner) {
+ _refreshMinerNow(miner) {
let env = GLib.getenv('DOCUMENTS_DISABLE_MINERS');
if (env)
return false;
@@ -253,9 +251,9 @@ var Application = new Lang.Class({
}));
return false;
- },
+ }
- _refreshMiners: function() {
+ _refreshMiners() {
if (sourceManager.hasProviderType('google')) {
try {
// startup a refresh of the gdocs cache
@@ -282,9 +280,9 @@ var Application = new Lang.Class({
logError(e, 'Unable to start Zpj miner');
}
}
- },
+ }
- _startMiners: function() {
+ _startMiners() {
this._createMiners(Lang.bind(this,
function() {
this._refreshMiners();
@@ -294,9 +292,9 @@ var Application = new Lang.Class({
this._sourceRemovedId = sourceManager.connect('item-removed',
Lang.bind(this, this._refreshMiners));
}));
- },
+ }
- _stopMiners: function() {
+ _stopMiners() {
if (this._sourceAddedId != 0) {
sourceManager.disconnect(this._sourceAddedId);
this._sourceAddedId = 0;
@@ -316,9 +314,9 @@ var Application = new Lang.Class({
this.gdataMiner = null;
this.owncloudMiner = null;
this.zpjMiner = null;
- },
+ }
- _themeChanged: function(gtkSettings) {
+ _themeChanged(gtkSettings) {
let screen = Gdk.Screen.get_default();
if (gtkSettings.gtk_theme_name == 'Adwaita') {
@@ -334,11 +332,11 @@ var Application = new Lang.Class({
} else if (cssProvider != null) {
Gtk.StyleContext.remove_provider_for_screen(screen, cssProvider);
}
- },
+ }
- vfunc_startup: function() {
+ vfunc_startup() {
application = this;
- this.parent();
+ super.vfunc_startup();
String.prototype.format = Format.format;
EvDoc.init();
@@ -396,9 +394,9 @@ var Application = new Lang.Class({
];
Utils.populateActionGroup(this, actionEntries, 'app');
- },
+ }
- _createWindow: function() {
+ _createWindow() {
if (this._mainWindow)
return;
@@ -417,10 +415,10 @@ var Application = new Lang.Class({
// start miners
this._startMiners();
- },
+ }
- vfunc_dbus_register: function(connection, path) {
- this.parent(connection, path);
+ vfunc_dbus_register(connection, path) {
+ super.vfunc_dbus_register(connection, path);
if (this._searchProvider != null)
throw(new Error('ShellSearchProvider already instantiated - dbus_register called twice?'));
@@ -437,27 +435,27 @@ var Application = new Lang.Class({
}
return true;
- },
+ }
- vfunc_dbus_unregister: function(connection, path) {
+ vfunc_dbus_unregister(connection, path) {
if (this._searchProvider != null) {
this._searchProvider.unexport(connection);
this._searchProvider = null;
}
- this.parent(connection, path);
- },
+ super.vfunc_dbus_unregister(connection, path);
+ }
- vfunc_handle_local_options: function(options) {
+ vfunc_handle_local_options(options) {
if (options.contains('version')) {
print(pkg.version);
return 0;
}
return -1;
- },
+ }
- vfunc_activate: function() {
+ vfunc_activate() {
if (!this._mainWindow) {
this._createWindow();
modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
@@ -465,9 +463,9 @@ var Application = new Lang.Class({
this._mainWindow.present_with_time(this._activationTimestamp);
this._activationTimestamp = Gdk.CURRENT_TIME;
- },
+ }
- _clearState: function() {
+ _clearState() {
// clean up signals
changeMonitor.disconnectAll();
documentManager.disconnectAll();
@@ -492,17 +490,17 @@ var Application = new Lang.Class({
if (this._extractPriority)
this._extractPriority.ClearRdfTypesRemote();
- },
+ }
- _onWindowDestroy: function(window) {
+ _onWindowDestroy(window) {
this._mainWindow = null;
// clear our state in an idle, so other handlers connected
// to 'destroy' have the chance to perform their cleanups first
Mainloop.idle_add(Lang.bind(this, this._clearState));
- },
+ }
- _onActivateResult: function(provider, urn, terms, timestamp) {
+ _onActivateResult(provider, urn, terms, timestamp) {
this._createWindow();
let doc = documentManager.getItemById(urn);
@@ -534,26 +532,26 @@ var Application = new Lang.Class({
}
}));
}
- },
+ }
- _onLaunchSearch: function(provider, terms, timestamp) {
+ _onLaunchSearch(provider, terms, timestamp) {
this._createWindow();
modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
searchController.setString(terms.join(' '));
this._activationTimestamp = timestamp;
this.activate();
- },
+ }
- getScaleFactor: function() {
+ getScaleFactor() {
let scaleFactor = 1;
if (this._mainWindow)
scaleFactor = this._mainWindow.get_scale_factor();
return scaleFactor;
- },
+ }
- getGdkWindow: function() {
+ getGdkWindow() {
let window = null;
if (this._mainWindow)
window = this._mainWindow.get_window();
diff --git a/src/changeMonitor.js b/src/changeMonitor.js
index a9e3a5ba..20ab907a 100644
--- a/src/changeMonitor.js
+++ b/src/changeMonitor.js
@@ -51,10 +51,8 @@ var ChangeEventType = {
const _RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
-const ChangeEvent = new Lang.Class({
- Name: 'ChangeEvent',
-
- _init: function(urnId, predicateId, isDelete) {
+const ChangeEvent = class ChangeEvent {
+ constructor(urnId, predicateId, isDelete) {
this.urnId = urnId;
this.predicateId = predicateId;
@@ -62,32 +60,30 @@ const ChangeEvent = new Lang.Class({
this.type = ChangeEventType.DELETED;
else
this.type = ChangeEventType.CREATED;
- },
+ }
- setResolvedValues: function(urn, predicate) {
+ setResolvedValues(urn, predicate) {
this.urn = urn;
this.predicate = predicate;
if (predicate != _RDF_TYPE)
this.type = ChangeEventType.CHANGED;
- },
+ }
- merge: function(event) {
+ merge(event) {
// deletions or creations override the current type
if (event.type == ChangeEventType.DELETED ||
event.type == ChangeEventType.CREATED) {
this.type = event.type;
}
}
-});
+}
const CHANGE_MONITOR_TIMEOUT = 500; // msecs
const CHANGE_MONITOR_MAX_ITEMS = 500; // items
-var TrackerChangeMonitor = new Lang.Class({
- Name: 'TrackerChangeMonitor',
-
- _init: function() {
+var TrackerChangeMonitor = class TrackerChangeMonitor {
+ constructor() {
this._pendingChanges = {};
this._unresolvedIds = {};
@@ -96,9 +92,9 @@ var TrackerChangeMonitor = new Lang.Class({
this._resourceService = new TrackerResourcesService();
this._resourceService.connectSignal('GraphUpdated', Lang.bind(this, this._onGraphUpdated));
- },
+ }
- _onGraphUpdated: function(proxy, senderName, [className, deleteEvents, insertEvents]) {
+ _onGraphUpdated(proxy, senderName, [className, deleteEvents, insertEvents]) {
deleteEvents.forEach(Lang.bind(this,
function(event) {
this._addPendingEvent(event, true);
@@ -108,9 +104,9 @@ var TrackerChangeMonitor = new Lang.Class({
function(event) {
this._addPendingEvent(event, false);
}));
- },
+ }
- _addPendingEvent: function(event, isDelete) {
+ _addPendingEvent(event, isDelete) {
if (this._pendingEventsId != 0)
Mainloop.source_remove(this._pendingEventsId);
@@ -123,9 +119,9 @@ var TrackerChangeMonitor = new Lang.Class({
else
this._pendingEventsId =
Mainloop.timeout_add(CHANGE_MONITOR_TIMEOUT, Lang.bind(this, this._processEvents));
- },
+ }
- _processEvents: function() {
+ _processEvents() {
let events = this._pendingEvents;
let idTable = this._unresolvedIds;
@@ -170,9 +166,9 @@ var TrackerChangeMonitor = new Lang.Class({
}));
return false;
- },
+ }
- _addEvent: function(event) {
+ _addEvent(event) {
let urn = event.urn;
let oldEvent = this._pendingChanges[urn];
@@ -182,9 +178,9 @@ var TrackerChangeMonitor = new Lang.Class({
} else {
this._pendingChanges[urn] = event;
}
- },
+ }
- _sendEvents: function(events, idTable) {
+ _sendEvents(events, idTable) {
events.forEach(Lang.bind(this,
function(event) {
event.setResolvedValues(idTable[event.urnId], idTable[event.predicateId]);
@@ -194,5 +190,5 @@ var TrackerChangeMonitor = new Lang.Class({
this.emit('changes-pending', this._pendingChanges);
this._pendingChanges = {};
}
-});
+}
Signals.addSignalMethods(TrackerChangeMonitor.prototype);
diff --git a/src/documents.js b/src/documents.js
index 5c81d77a..7a10c97b 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -48,15 +48,13 @@ const TrackerUtils = imports.trackerUtils;
const Utils = imports.utils;
const WindowMode = imports.windowMode;
-const DeleteItemJob = new Lang.Class({
- Name: 'DeleteItemJob',
-// deletes the given resource
-
- _init: function(urn) {
+const DeleteItemJob = class DeleteItemJob {
+ // deletes the given resource
+ constructor(urn) {
this._urn = urn;
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let query = Application.queryBuilder.buildDeleteResourceQuery(this._urn);
@@ -72,26 +70,23 @@ const DeleteItemJob = new Lang.Class({
this._callback();
}));
}
-});
-
-
-const CollectionIconWatcher = new Lang.Class({
- Name: 'CollectionIconWatcher',
+}
- _init: function(collection) {
+const CollectionIconWatcher = class CollectionIconWatcher {
+ constructor(collection) {
this._collection = collection;
this._pixbuf = null;
this._start();
- },
+ }
- _clear: function() {
+ _clear() {
this._docConnections = {};
this._urns = [];
this._docs = [];
- },
+ }
- _start: function() {
+ _start() {
this._clear();
let query = Application.queryBuilder.buildCollectionIconQuery(this._collection.id);
@@ -107,9 +102,9 @@ const CollectionIconWatcher = new Lang.Class({
cursor.next_async(null, Lang.bind(this, this._onCursorNext));
}));
- },
+ }
- _onCursorNext: function(cursor, res) {
+ _onCursorNext(cursor, res) {
let valid = false;
try {
@@ -131,9 +126,9 @@ const CollectionIconWatcher = new Lang.Class({
this._urns.push(urn);
cursor.next_async(null, Lang.bind(this, this._onCursorNext));
- },
+ }
- _onCollectionIconFinished: function() {
+ _onCollectionIconFinished() {
if (!this._urns.length)
return;
@@ -168,16 +163,16 @@ const CollectionIconWatcher = new Lang.Class({
this._toQueryCollector();
}));
}));
- },
+ }
- _toQueryCollector: function() {
+ _toQueryCollector() {
this._toQueryRemaining--;
if (!this._toQueryRemaining)
this._allDocsReady();
- },
+ }
- _allDocsReady: function() {
+ _allDocsReady() {
this._docs.forEach(Lang.bind(this,
function(doc) {
let updateId = doc.connect('info-updated',
@@ -186,9 +181,9 @@ const CollectionIconWatcher = new Lang.Class({
}));
this._createCollectionIcon();
- },
+ }
- _createCollectionIcon: function() {
+ _createCollectionIcon() {
// now this._docs has an array of Document objects from which we will create the
// collection icon
let pixbufs = [];
@@ -208,30 +203,28 @@ const CollectionIconWatcher = new Lang.Class({
Utils.getIconSize() * Application.application.getScaleFactor(),
pixbufs);
this._emitRefresh();
- },
+ }
- _emitRefresh: function() {
+ _emitRefresh() {
this.emit('icon-updated', this._pixbuf);
- },
+ }
- destroy: function() {
+ destroy() {
for (let id in this._docConnections) {
let doc = this._docConnections[id];
doc.disconnect(id);
}
- },
+ }
- refresh: function() {
+ refresh() {
this.destroy();
this._start();
}
-});
+}
Signals.addSignalMethods(CollectionIconWatcher.prototype);
-const DocCommon = new Lang.Class({
- Name: 'DocCommon',
-
- _init: function(cursor) {
+const DocCommon = class DocCommon {
+ constructor(cursor) {
this.id = null;
this.uri = null;
this.uriToLoad = null;
@@ -264,9 +257,9 @@ const DocCommon = new Lang.Class({
this._refreshIconId =
Application.settings.connect('changed::view-as',
Lang.bind(this, this.refreshIcon));
- },
+ }
- refresh: function() {
+ refresh() {
let job = new TrackerUtils.SingleItemJob(this.id, Application.queryBuilder);
job.run(Query.QueryFlags.NONE, Lang.bind(this,
function(cursor) {
@@ -275,13 +268,13 @@ const DocCommon = new Lang.Class({
this.populateFromCursor(cursor);
}));
- },
+ }
- _sanitizeTitle: function() {
+ _sanitizeTitle() {
this.name = this.name.replace(/Microsoft Word - /g, '');
- },
+ }
- populateFromCursor: function(cursor) {
+ populateFromCursor(cursor) {
this.uri = cursor.get_string(Query.QueryColumns.URI)[0];
this.id = cursor.get_string(Query.QueryColumns.URN)[0];
this.identifier = cursor.get_string(Query.QueryColumns.IDENTIFIER)[0];
@@ -325,9 +318,9 @@ const DocCommon = new Lang.Class({
this._sanitizeTitle();
this.refreshIcon();
- },
+ }
- updateIconFromType: function() {
+ updateIconFromType() {
let icon = null;
if (this.mimeType)
@@ -350,9 +343,9 @@ const DocCommon = new Lang.Class({
logError(e, 'Unable to load pixbuf');
}
}
- },
+ }
- _refreshCollectionIcon: function() {
+ _refreshCollectionIcon() {
if (!this._collectionIconWatcher) {
this._collectionIconWatcher = new CollectionIconWatcher(this);
@@ -363,16 +356,16 @@ const DocCommon = new Lang.Class({
} else {
this._collectionIconWatcher.refresh();
}
- },
+ }
- download: function(useCache, cancellable, callback) {
+ download(useCache, cancellable, callback) {
let localFile = Gio.File.new_for_uri(this.uriToLoad);
let localPath = localFile.get_path();
let localDir = GLib.path_get_dirname(localPath);
GLib.mkdir_with_parents(localDir, 448);
if (!useCache) {
- Utils.debug('Downloading ' + this.__name__ + ' ' + this.id + ' to ' + this.uriToLoad +
+ Utils.debug('Downloading ' + this.constructor.name + ' ' + this.id + ' to ' + this.uriToLoad +
': bypass cache ');
this.downloadImpl(localFile, cancellable, callback);
return;
@@ -389,7 +382,7 @@ const DocCommon = new Lang.Class({
try {
info = object.query_info_finish(res);
} catch (e) {
- Utils.debug('Downloading ' + this.__name__ + ' ' + this.id + ' to ' + this.uriToLoad +
+ Utils.debug('Downloading ' + this.constructor.name + ' ' + this.id + ' to ' +
this.uriToLoad +
': cache miss');
this.downloadImpl(localFile, cancellable, callback);
return;
@@ -401,18 +394,18 @@ const DocCommon = new Lang.Class({
return;
}
- Utils.debug('Downloading ' + this.__name__ + ' ' + this.id + ' to ' + this.uriToLoad +
+ Utils.debug('Downloading ' + this.constructor.name + ' ' + this.id + ' to ' + this.uriToLoad
+
': cache stale (' + this.mtime + ' > ' + cacheMtime + ')');
this.downloadImpl(localFile, cancellable, callback);
}));
- },
+ }
- downloadImpl: function(localFile, cancellable, callback) {
+ downloadImpl(localFile, cancellable, callback) {
throw(new Error('DocCommon implementations must override downloadImpl'));
- },
+ }
- load: function(passwd, cancellable, callback) {
- Utils.debug('Loading ' + this.__name__ + ' ' + this.id);
+ load(passwd, cancellable, callback) {
+ Utils.debug('Loading ' + this.constructor.name + ' ' + this.id);
if (this.collection) {
Mainloop.idle_add(Lang.bind(this,
@@ -458,25 +451,25 @@ const DocCommon = new Lang.Class({
callback(this, docModel, null);
}));
}));
- },
+ }
- canEdit: function() {
+ canEdit() {
throw(new Error('DocCommon implementations must override canEdit'));
- },
+ }
- canEditTitle: function() {
+ canEditTitle() {
return false;
- },
+ }
- canShare: function() {
+ canShare() {
throw(new Error('DocCommon implementations must override canShare'));
- },
+ }
- canTrash: function() {
+ canTrash() {
throw(new Error('DocCommon implementations must override canTrash'));
- },
+ }
- canPrint: function(docModel) {
+ canPrint(docModel) {
if (this.collection)
return false;
@@ -484,9 +477,9 @@ const DocCommon = new Lang.Class({
return false;
return EvView.PrintOperation.exists_for_document(docModel.get_document());
- },
+ }
- trash: function() {
+ trash() {
if (!this.canTrash())
return;
@@ -494,17 +487,17 @@ const DocCommon = new Lang.Class({
let job = new DeleteItemJob(this.id);
job.run(null);
- },
+ }
- trashImpl: function() {
+ trashImpl() {
throw(new Error('DocCommon implementations must override trashImpl'));
- },
+ }
- createThumbnail: function(callback) {
+ createThumbnail(callback) {
throw(new Error('DocCommon implementations must override createThumbnail'));
- },
+ }
- refreshIcon: function() {
+ refreshIcon() {
if (this._thumbPath) {
this._refreshThumbPath();
return;
@@ -526,9 +519,9 @@ const DocCommon = new Lang.Class({
GLib.PRIORITY_DEFAULT,
null,
Lang.bind(this, this._onFileQueryInfo));
- },
+ }
- _onFileQueryInfo: function(object, res) {
+ _onFileQueryInfo(object, res) {
let info = null;
let haveNewIcon = false;
@@ -546,9 +539,9 @@ const DocCommon = new Lang.Class({
} else {
this.createThumbnail(Lang.bind(this, this._onCreateThumbnail));
}
- },
+ }
- _onCreateThumbnail: function(thumbnailed) {
+ _onCreateThumbnail(thumbnailed) {
if (!thumbnailed) {
this._failedThumbnailing = true;
return;
@@ -560,9 +553,9 @@ const DocCommon = new Lang.Class({
GLib.PRIORITY_DEFAULT,
null,
Lang.bind(this, this._onThumbnailPathInfo));
- },
+ }
- _onThumbnailPathInfo: function(object, res) {
+ _onThumbnailPathInfo(object, res) {
let info = null;
try {
@@ -578,9 +571,9 @@ const DocCommon = new Lang.Class({
this._refreshThumbPath();
else
this._failedThumbnailing = true;
- },
+ }
- _refreshThumbPath: function() {
+ _refreshThumbPath() {
let thumbFile = Gio.file_new_for_path(this._thumbPath);
thumbFile.read_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
@@ -622,16 +615,16 @@ const DocCommon = new Lang.Class({
this._setOrigPixbuf(pixbuf);
}));
}));
- },
+ }
- _updateInfoFromType: function() {
+ _updateInfoFromType() {
if (this.rdfType.indexOf('nfo#DataContainer') != -1)
this.collection = true;
this.updateTypeDescription();
- },
+ }
- _createSymbolicEmblem: function(name) {
+ _createSymbolicEmblem(name) {
let pix = Gd.create_symbolic_icon(name, Utils.getIconSize() *
Application.application.getScaleFactor());
@@ -639,17 +632,17 @@ const DocCommon = new Lang.Class({
pix = new Gio.ThemedIcon({ name: name });
return pix;
- },
+ }
- _setOrigPixbuf: function(pixbuf) {
+ _setOrigPixbuf(pixbuf) {
if (pixbuf) {
this.origPixbuf = pixbuf;
}
this._checkEffectsAndUpdateInfo();
- },
+ }
- _checkEffectsAndUpdateInfo: function() {
+ _checkEffectsAndUpdateInfo() {
if (!this.origPixbuf)
return;
@@ -698,19 +691,19 @@ const DocCommon = new Lang.Class({
Application.application.getGdkWindow());
this.emit('info-updated');
- },
+ }
- destroy: function() {
+ destroy() {
if (this._collectionIconWatcher) {
this._collectionIconWatcher.destroy();
this._collectionIconWatcher = null;
}
Application.settings.disconnect(this._refreshIconId);
- },
+ }
- loadLocal: function(passwd, cancellable, callback) {
- Utils.debug('Loading ' + this.__name__ + ' ' + this.id + ' from ' + this.uriToLoad);
+ loadLocal(passwd, cancellable, callback) {
+ Utils.debug('Loading ' + this.constructor.name + ' ' + this.id + ' from ' + this.uriToLoad);
if (LOKView.isOpenDocumentFormat(this.mimeType)) {
let exception = null;
@@ -732,9 +725,9 @@ const DocCommon = new Lang.Class({
callback(this, null, e);
}
}));
- },
+ }
- open: function(parent, timestamp) {
+ open(parent, timestamp) {
if (!this.defaultAppName)
return;
@@ -748,9 +741,9 @@ const DocCommon = new Lang.Class({
} catch (e) {
logError(e, 'Unable to show URI ' + this.uri);
}
- },
+ }
- print: function(toplevel) {
+ print(toplevel) {
this.load(null, null, Lang.bind(this,
function(doc, docModel, error) {
if (error) {
@@ -794,33 +787,29 @@ const DocCommon = new Lang.Class({
printOp.run(toplevel);
}));
- },
+ }
- getSourceLink: function() {
+ getSourceLink() {
// This should return an array of URI and source name
log('Error: DocCommon implementations must override getSourceLink');
- },
+ }
- getWhere: function() {
+ getWhere() {
let retval = '';
if (this.collection)
retval = '{ ?urn nie:isPartOf <' + this.id + '> }';
return retval;
- },
-});
+ }
+}
Signals.addSignalMethods(DocCommon.prototype);
-var LocalDocument = new Lang.Class({
- Name: 'LocalDocument',
- Extends: DocCommon,
+var LocalDocument = class LocalDocument extends DocCommon {
+ constructor(cursor) {
+ super(cursor);
- _init: function(cursor) {
this._failedThumbnailing = false;
-
- this.parent(cursor);
-
this.sourceName = _("Local");
if (this.mimeType) {
@@ -850,10 +839,10 @@ var LocalDocument = new Lang.Class({
if (this.defaultApp)
this.defaultAppName = this.defaultApp.get_name();
- },
+ }
- populateFromCursor: function(cursor) {
- this.parent(cursor);
+ populateFromCursor(cursor) {
+ super.populateFromCursor(cursor);
this.uriToLoad = this.uri;
if (!Application.application.gettingStartedLocation)
@@ -867,9 +856,9 @@ var LocalDocument = new Lang.Class({
this.author = _("GNOME");
this.name = this.title = _("Getting Started with Documents");
}
- },
+ }
- createThumbnail: function(callback) {
+ createThumbnail(callback) {
GdPrivate.queue_thumbnail_job_for_file_async(this._file, Lang.bind(this,
function(object, res) {
let thumbnailed = false;
@@ -884,9 +873,9 @@ var LocalDocument = new Lang.Class({
callback(thumbnailed);
}));
- },
+ }
- updateTypeDescription: function() {
+ updateTypeDescription() {
let description = '';
if (this.collection)
@@ -895,14 +884,14 @@ var LocalDocument = new Lang.Class({
description = Gio.content_type_get_description(this.mimeType);
this.typeDescription = description;
- },
+ }
- downloadImpl: function(localFile, cancellable, callback) {
+ downloadImpl(localFile, cancellable, callback) {
throw(new Error('LocalDocuments need not be downloaded'));
- },
+ }
- load: function(passwd, cancellable, callback) {
- Utils.debug('Loading ' + this.__name__ + ' ' + this.id);
+ load(passwd, cancellable, callback) {
+ Utils.debug('Loading ' + this.constructor.name + ' ' + this.id);
if (this.collection) {
Mainloop.idle_add(Lang.bind(this,
@@ -918,25 +907,25 @@ var LocalDocument = new Lang.Class({
}
this.loadLocal(passwd, cancellable, callback);
- },
+ }
- canEdit: function() {
+ canEdit() {
return this.collection;
- },
+ }
- canEditTitle: function() {
+ canEditTitle() {
return true;
- },
+ }
- canShare: function() {
+ canShare() {
return false;
- },
+ }
- canTrash: function() {
+ canTrash() {
return true;
- },
+ }
- trashImpl: function() {
+ trashImpl() {
if (this.collection)
return;
@@ -949,9 +938,9 @@ var LocalDocument = new Lang.Class({
logError(e, 'Unable to trash ' + this.uri);
}
}));
- },
+ }
- getSourceLink: function() {
+ getSourceLink() {
if (this.collection)
return [ null, this.sourceName ];
@@ -961,25 +950,22 @@ var LocalDocument = new Lang.Class({
let uri = sourceLink.get_uri();
return [ uri, sourcePath ];
}
-});
+}
const GOOGLE_PREFIX = 'google:drive:';
-const GoogleDocument = new Lang.Class({
- Name: 'GoogleDocument',
- Extends: DocCommon,
+const GoogleDocument = class GoogleDocument extends DocCommon {
+ constructor(cursor) {
+ super(cursor);
- _init: function(cursor) {
this._failedThumbnailing = false;
- this.parent(cursor);
-
// overridden
this.defaultAppName = _("Google Docs");
this.sourceName = _("Google");
- },
+ }
- createGDataEntry: function(cancellable, callback) {
+ createGDataEntry(cancellable, callback) {
let source = Application.sourceManager.getItemById(this.resourceUrn);
let authorizer = new GData.GoaAuthorizer({ goa_object: source.object });
@@ -1003,9 +989,9 @@ const GoogleDocument = new Lang.Class({
callback(entry, service, exception);
}));
- },
+ }
- downloadImpl: function(localFile, cancellable, callback) {
+ downloadImpl(localFile, cancellable, callback) {
this.createGDataEntry(cancellable, Lang.bind(this,
function(entry, service, error) {
if (error) {
@@ -1058,9 +1044,9 @@ const GoogleDocument = new Lang.Class({
}));
}));
}))
- },
+ }
- createThumbnail: function(callback) {
+ createThumbnail(callback) {
this.createGDataEntry(null, Lang.bind(this,
function(entry, service, exception) {
if (exception) {
@@ -1112,9 +1098,9 @@ const GoogleDocument = new Lang.Class({
}));
}));
}));
- },
+ }
- updateTypeDescription: function() {
+ updateTypeDescription() {
let description;
if (this.collection)
@@ -1127,12 +1113,12 @@ const GoogleDocument = new Lang.Class({
description = _("Document");
this.typeDescription = description;
- },
+ }
- populateFromCursor: function(cursor) {
+ populateFromCursor(cursor) {
this.shared = cursor.get_boolean(Query.QueryColumns.SHARED);
- this.parent(cursor);
+ super.populateFromCursor(cursor);
let localDir = GLib.build_filenamev([GLib.get_user_cache_dir(), "gnome-documents", "google"]);
@@ -1142,37 +1128,34 @@ const GoogleDocument = new Lang.Class({
let localPath = GLib.build_filenamev([localDir, localFilename]);
let localFile = Gio.File.new_for_path(localPath);
this.uriToLoad = localFile.get_uri();
- },
+ }
- canEdit: function() {
+ canEdit() {
return !this.collection;
- },
+ }
- canShare: function() {
+ canShare() {
return true;
- },
+ }
- canTrash: function() {
+ canTrash() {
return false;
- },
+ }
- getSourceLink: function() {
+ getSourceLink() {
let uri = 'http://docs.google.com/';
return [ uri, this.sourceName ];
}
-});
+}
const OWNCLOUD_PREFIX = 'owncloud:';
-const OwncloudDocument = new Lang.Class({
- Name: 'OwncloudDocument',
- Extends: DocCommon,
+const OwncloudDocument = class OwncloudDocument extends DocCommon {
+ constructor(cursor) {
+ super(cursor);
- _init: function(cursor) {
this._failedThumbnailing = true;
- this.parent(cursor);
-
// overridden
this.sourceName = _("ownCloud");
@@ -1181,10 +1164,10 @@ const OwncloudDocument = new Lang.Class({
if (this.defaultApp)
this.defaultAppName = this.defaultApp.get_name();
- },
+ }
- populateFromCursor: function(cursor) {
- this.parent(cursor);
+ populateFromCursor(cursor) {
+ super.populateFromCursor(cursor);
let localDir = GLib.build_filenamev([GLib.get_user_cache_dir(), "gnome-documents", "owncloud"]);
@@ -1196,9 +1179,9 @@ const OwncloudDocument = new Lang.Class({
let localPath = GLib.build_filenamev([localDir, localFilename]);
let localFile = Gio.File.new_for_path(localPath);
this.uriToLoad = localFile.get_uri();
- },
+ }
- createThumbnail: function(callback) {
+ createThumbnail(callback) {
GdPrivate.queue_thumbnail_job_for_file_async(this._file, Lang.bind(this,
function(object, res) {
let thumbnailed = false;
@@ -1213,9 +1196,9 @@ const OwncloudDocument = new Lang.Class({
callback(thumbnailed);
}));
- },
+ }
- updateTypeDescription: function() {
+ updateTypeDescription() {
let description = '';
if (this.collection)
@@ -1224,9 +1207,9 @@ const OwncloudDocument = new Lang.Class({
description = Gio.content_type_get_description(this.mimeType);
this.typeDescription = description;
- },
+ }
- downloadImpl: function(localFile, cancellable, callback) {
+ downloadImpl(localFile, cancellable, callback) {
let remoteFile = Gio.File.new_for_uri(this.uri);
remoteFile.read_async(GLib.PRIORITY_DEFAULT, cancellable, Lang.bind(this,
function(object, res) {
@@ -1273,47 +1256,44 @@ const OwncloudDocument = new Lang.Class({
}));
}));
}));
- },
+ }
- canEdit: function() {
+ canEdit() {
return false;
- },
+ }
- canShare: function() {
+ canShare() {
return false;
- },
+ }
- canTrash: function() {
+ canTrash() {
return false;
- },
+ }
- getSourceLink: function() {
+ getSourceLink() {
let source = Application.sourceManager.getItemById(this.resourceUrn);
let account = source.object.get_account();
let presentationIdentity = account.presentation_identity;
let uri ='https://' + presentationIdentity + '/';
return [ uri, presentationIdentity ];
}
-});
+}
const SKYDRIVE_PREFIX = 'windows-live:skydrive:';
-const SkydriveDocument = new Lang.Class({
- Name: 'SkydriveDocument',
- Extends: DocCommon,
+const SkydriveDocument = class SkydriveDocument extends DocCommon {
+ constructor(cursor) {
+ super(cursor);
- _init: function(cursor) {
this._failedThumbnailing = true;
- this.parent(cursor);
-
// overridden
this.defaultAppName = _("OneDrive");
this.sourceName = _("OneDrive");
- },
+ }
- populateFromCursor: function(cursor) {
- this.parent(cursor);
+ populateFromCursor(cursor) {
+ super.populateFromCursor(cursor);
let localDir = GLib.build_filenamev([GLib.get_user_cache_dir(), "gnome-documents", "skydrive"]);
@@ -1325,9 +1305,9 @@ const SkydriveDocument = new Lang.Class({
let localPath = GLib.build_filenamev([localDir, localFilename]);
let localFile = Gio.File.new_for_path(localPath);
this.uriToLoad = localFile.get_uri();
- },
+ }
- _createZpjEntry: function(cancellable, callback) {
+ _createZpjEntry(cancellable, callback) {
let source = Application.sourceManager.getItemById(this.resourceUrn);
let authorizer = new Zpj.GoaAuthorizer({ goa_object: source.object });
@@ -1349,9 +1329,9 @@ const SkydriveDocument = new Lang.Class({
callback(entry, service, exception);
}));
- },
+ }
- downloadImpl: function(localFile, cancellable, callback) {
+ downloadImpl(localFile, cancellable, callback) {
this._createZpjEntry(cancellable, Lang.bind(this,
function(entry, service, error) {
if (error) {
@@ -1407,9 +1387,9 @@ const SkydriveDocument = new Lang.Class({
}));
}));
}));
- },
+ }
- updateTypeDescription: function() {
+ updateTypeDescription() {
let description;
if (this.collection)
@@ -1422,32 +1402,29 @@ const SkydriveDocument = new Lang.Class({
description = _("Document");
this.typeDescription = description;
- },
+ }
- canEdit: function() {
+ canEdit() {
return false;
- },
+ }
- canShare: function() {
+ canShare() {
return false;
- },
+ }
- canTrash: function() {
+ canTrash() {
return false;
- },
+ }
- getSourceLink: function() {
+ getSourceLink() {
let uri = 'https://onedrive.live.com';
return [ uri, this.sourceName ];
}
-});
+}
-var DocumentManager = new Lang.Class({
- Name: 'DocumentManager',
- Extends: Manager.BaseManager,
-
- _init: function() {
- this.parent();
+var DocumentManager = class DocumentManager extends Manager.BaseManager {
+ constructor() {
+ super();
this._loaderCancellable = null;
@@ -1460,9 +1437,9 @@ var DocumentManager = new Lang.Class({
Application.changeMonitor.connect('changes-pending',
Lang.bind(this, this._onChangesPending));
- },
+ }
- _onChangesPending: function(monitor, changes) {
+ _onChangesPending(monitor, changes) {
for (let idx in changes) {
let changeEvent = changes[idx];
@@ -1482,9 +1459,9 @@ var DocumentManager = new Lang.Class({
}
}
}
- },
+ }
- _onDocumentCreated: function(urn) {
+ _onDocumentCreated(urn) {
let job = new TrackerUtils.SingleItemJob(urn, Application.queryBuilder);
job.run(Query.QueryFlags.NONE, Lang.bind(this,
function(cursor) {
@@ -1493,24 +1470,24 @@ var DocumentManager = new Lang.Class({
this.addDocumentFromCursor(cursor);
}));
- },
+ }
- _identifierIsGoogle: function(identifier) {
+ _identifierIsGoogle(identifier) {
return (identifier &&
(identifier.indexOf(GOOGLE_PREFIX) != -1));
- },
+ }
- _identifierIsOwncloud: function(identifier) {
+ _identifierIsOwncloud(identifier) {
return (identifier &&
(identifier.indexOf(OWNCLOUD_PREFIX) != -1));
- },
+ }
- _identifierIsSkydrive: function(identifier) {
+ _identifierIsSkydrive(identifier) {
return (identifier &&
(identifier.indexOf(SKYDRIVE_PREFIX) != -1));
- },
+ }
- createDocumentFromCursor: function(cursor) {
+ createDocumentFromCursor(cursor) {
let identifier = cursor.get_string(Query.QueryColumns.IDENTIFIER)[0];
let doc;
@@ -1524,9 +1501,9 @@ var DocumentManager = new Lang.Class({
doc = new LocalDocument(cursor);
return doc;
- },
+ }
- addDocumentFromCursor: function(cursor) {
+ addDocumentFromCursor(cursor) {
let id = cursor.get_string(Query.QueryColumns.URN)[0];
let doc = this.getItemById(id);
@@ -1538,9 +1515,9 @@ var DocumentManager = new Lang.Class({
}
return doc;
- },
+ }
- addItem: function(doc) {
+ addItem(doc) {
if (doc.collection) {
let oldCollection = this._collections[doc.id];
if (oldCollection)
@@ -1549,10 +1526,10 @@ var DocumentManager = new Lang.Class({
this._collections[doc.id] = doc;
}
- this.parent(doc);
- },
+ super.addItem(doc);
+ }
- clear: function() {
+ clear() {
this._collections = {};
this._activeCollection = null;
@@ -1561,34 +1538,34 @@ var DocumentManager = new Lang.Class({
items[idx].destroy();
};
- this.parent();
- },
+ super.clear();
+ }
- clearRowRefs: function() {
+ clearRowRefs() {
let items = this.getItems();
for (let idx in items) {
items[idx].rowRefs = {};
}
- },
+ }
- getActiveCollection: function() {
+ getActiveCollection() {
return this._activeCollection;
- },
+ }
- getCollections: function() {
+ getCollections() {
return this._collections;
- },
+ }
- getWhere: function() {
+ getWhere() {
let retval = '';
if (this._activeCollection)
retval = this._activeCollection.getWhere();
return retval;
- },
+ }
- _humanizeError: function(error) {
+ _humanizeError(error) {
let message = error.message;
if (error.domain == GData.ServiceError) {
switch (error.code) {
@@ -1620,9 +1597,9 @@ var DocumentManager = new Lang.Class({
let exception = new GLib.Error(error.domain, error.code, message);
return exception;
- },
+ }
- _onDocumentLoadError: function(doc, error) {
+ _onDocumentLoadError(doc, error) {
if (error.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
return;
@@ -1637,9 +1614,9 @@ var DocumentManager = new Lang.Class({
let message = _("Oops! Unable to load ā%sā").format(doc.name);
let exception = this._humanizeError(error);
this.emit('load-error', doc, message, exception);
- },
+ }
- _onDocumentLoaded: function(doc, docModel, error) {
+ _onDocumentLoaded(doc, docModel, error) {
this._loaderCancellable = null;
if (error) {
@@ -1648,9 +1625,9 @@ var DocumentManager = new Lang.Class({
}
this.emit('load-finished', doc, docModel);
- },
+ }
- _requestPreview: function(doc) {
+ _requestPreview(doc) {
let windowMode;
if (LOKView.isOpenDocumentFormat(doc.mimeType)) {
windowMode = WindowMode.WindowMode.PREVIEW_LOK;
@@ -1659,18 +1636,18 @@ var DocumentManager = new Lang.Class({
}
Application.modeController.setWindowMode(windowMode);
- },
+ }
- _loadActiveItem: function(passwd) {
+ _loadActiveItem(passwd) {
let doc = this.getActiveItem();
this._loaderCancellable = new Gio.Cancellable();
this._requestPreview(doc);
this.emit('load-started', doc);
doc.load(passwd, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
- },
+ }
- reloadActiveItem: function(passwd) {
+ reloadActiveItem(passwd) {
let doc = this.getActiveItem();
if (!doc)
@@ -1683,17 +1660,17 @@ var DocumentManager = new Lang.Class({
this._clearActiveDocModel();
this._loadActiveItem(passwd);
- },
+ }
- removeItemById: function(id) {
+ removeItemById(id) {
if (this._collections[id]) {
delete this._collections[id];
}
- this.parent(id);
- },
+ super.removeItemById(id);
+ }
- setActiveItem: function(doc) {
+ setActiveItem(doc) {
let activeCollectionChanged = false;
let activeDoc = this.getActiveItem();
let retval = false;
@@ -1729,7 +1706,7 @@ var DocumentManager = new Lang.Class({
}
}
- retval = this.parent(doc);
+ retval = super.setActiveItem(doc);
if (retval && activeCollectionChanged)
this.emit('active-collection-changed', this._activeCollection);
@@ -1742,22 +1719,22 @@ var DocumentManager = new Lang.Class({
}
return retval;
- },
+ }
- activatePreviousCollection: function() {
+ activatePreviousCollection() {
this._clearActiveDocModel();
let collection = this._collectionPath.pop();
this._activeCollection = collection;
Manager.BaseManager.prototype.setActiveItem.call(this, collection);
this.emit('active-collection-changed', this._activeCollection);
- },
+ }
- _clearActiveDocModel: function() {
+ _clearActiveDocModel() {
// cancel any pending load operation
if (this._loaderCancellable) {
this._loaderCancellable.cancel();
this._loaderCancellable = null;
}
}
-});
+}
diff --git a/src/edit.js b/src/edit.js
index 649698d2..15601aa9 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -19,6 +19,7 @@
const WebKit = imports.gi.WebKit2;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
@@ -31,26 +32,23 @@ const Preview = imports.preview;
const _BLANK_URI = "about:blank";
-var EditView = new Lang.Class({
- Name: 'EditView',
- Extends: Preview.Preview,
-
- _init: function(overlay, mainWindow) {
- this.parent(overlay, mainWindow);
+var EditView = GObject.registerClass(class EditView extends Preview.Preview {
+ _init(overlay, mainWindow) {
+ super._init(overlay, mainWindow);
let doc = Application.documentManager.getActiveItem();
if (doc.uri)
this._webView.load_uri(doc.uri);
- },
+ }
- createActions: function() {
+ createActions() {
return [
{ name: 'view-current',
callback: Lang.bind(this, this._viewCurrent) }
];
- },
+ }
- createView: function() {
+ createView() {
let overlay = new Gtk.Overlay();
this._webView = new WebKit.WebView();
@@ -73,32 +71,32 @@ var EditView = new Lang.Class({
cookie_manager.set_persistent_storage(jarfile, WebKit.CookiePersistentStorage.SQLITE);
overlay.show_all();
return overlay;
- },
+ }
- createToolbar: function() {
+ createToolbar() {
return new EditToolbar(this);
- },
+ }
- onLoadStarted: function() {
+ onLoadStarted() {
this.getAction('view-current').enabled = false;
- },
+ }
- onLoadFinished: function(manager, doc) {
+ onLoadFinished(manager, doc) {
if (doc.uri)
this.getAction('view-current').enabled = true;
- },
+ }
- goBack: function() {
+ goBack() {
Application.documentManager.setActiveItem(null);
Application.modeController.goBack(2);
- },
+ }
- _viewCurrent: function() {
+ _viewCurrent() {
Application.modeController.goBack();
Application.documentManager.reloadActiveItem();
- },
+ }
- _onProgressChanged: function() {
+ _onProgressChanged() {
if (!this._webView.uri || this._webView.uri == _BLANK_URI)
return;
@@ -119,21 +117,18 @@ var EditView = new Lang.Class({
if (loading || progress == 1.0)
value = progress;
this._progressBar.fraction = value;
- },
+ }
- _onTimeoutExpired: function() {
+ _onTimeoutExpired() {
this._timeoutId = 0;
this._progressBar.hide();
return false;
}
});
-const EditToolbar = new Lang.Class({
- Name: 'EditToolbar',
- Extends: Preview.PreviewToolbar,
-
- _init: function(preview) {
- this.parent(preview);
+const EditToolbar = GObject.registerClass(class EditToolbar extends Preview.PreviewToolbar {
+ _init(preview) {
+ super._init(preview);
// view button, on the right of the toolbar
let viewButton = new Gtk.Button({ label: _("View"),
@@ -141,13 +136,13 @@ const EditToolbar = new Lang.Class({
visible: true });
viewButton.get_style_context().add_class('suggested-action');
this.toolbar.pack_end(viewButton);
- },
+ }
- createSearchbar: function() {
+ createSearchbar() {
return null;
- },
+ }
- handleEvent: function(event) {
+ handleEvent(event) {
return false;
}
});
diff --git a/src/embed.js b/src/embed.js
index 8fd36809..399ae0ba 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -31,18 +31,16 @@ const Overview = imports.overview;
const WindowMode = imports.windowMode;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
-const View = new Lang.Class({
- Name: 'View',
- Extends: Gtk.Overlay,
-
- _init: function(window) {
+const View = GObject.registerClass(class View extends Gtk.Overlay {
+ _init(window) {
this._toolbar = null;
this._window = window;
- this.parent();
+ super._init();
this._stack = new Gtk.Stack({ visible: true,
homogeneous: true,
@@ -53,16 +51,16 @@ const View = new Lang.Class({
this.add_overlay(Application.notificationManager);
this.show();
- },
+ }
- _clearPreview: function() {
+ _clearPreview() {
if (this._preview) {
this._preview.destroy();
this._preview = null;
}
- },
+ }
- _createPreview: function(mode) {
+ _createPreview(mode) {
let constructor;
switch (mode) {
case WindowMode.WindowMode.PREVIEW_EV:
@@ -80,20 +78,20 @@ const View = new Lang.Class({
this._preview = new constructor(this, this._window);
this._stack.add_named(this._preview, 'preview');
- },
+ }
- _ensureOverview: function(mode) {
+ _ensureOverview(mode) {
if (!this._overview) {
this._overview = new Overview.OverviewStack();
this._stack.add_named(this._overview, 'overview');
}
this._overview.windowMode = mode;
- },
+ }
- _onActivateResult: function() {
+ _onActivateResult() {
this.view.activateResult();
- },
+ }
set windowMode(mode) {
let fromPreview = !!this._preview;
@@ -136,23 +134,20 @@ const View = new Lang.Class({
Lang.bind(this, this._onActivateResult));
this._window.get_titlebar().add(this._toolbar);
}
- },
+ }
get toolbar() {
return this._toolbar;
- },
+ }
get view() {
return this._stack.visible_child;
}
});
-var Embed = new Lang.Class({
- Name: 'Embed',
- Extends: Gtk.Box,
-
- _init: function(mainWindow) {
- this.parent({ orientation: Gtk.Orientation.VERTICAL,
+var Embed = GObject.registerClass(class Embed extends Gtk.Box {
+ _init(mainWindow) {
+ super._init({ orientation: Gtk.Orientation.VERTICAL,
visible: true });
let titlebar = new Gtk.Grid({ visible: true });
@@ -173,9 +168,9 @@ var Embed = new Lang.Class({
Lang.bind(this, this._onSearchChanged));
this._view.windowMode = Application.modeController.getWindowMode();
- },
+ }
- _onSearchChanged: function() {
+ _onSearchChanged() {
// Whenever a search constraint is specified we want to switch to
// the search mode, and when all constraints have been lifted we
// want to go back to the previous mode which can be either
@@ -202,19 +197,19 @@ var Embed = new Lang.Class({
let searchAction = this._view.view.getAction('search');
searchAction.change_state(GLib.Variant.new('b', true));
}
- },
+ }
- _onWindowModeChanged: function(object, newMode, oldMode) {
+ _onWindowModeChanged(object, newMode, oldMode) {
this._view.windowMode = newMode;
- },
+ }
- getMainToolbar: function() {
+ getMainToolbar() {
if (this._view.view.canFullscreen &&
this._view.view.fullscreen)
return this._view.view.getFullscreenToolbar();
return this._view.toolbar;
- },
+ }
get view() {
return this._view;
diff --git a/src/errorBox.js b/src/errorBox.js
index 8fdf154c..a82f8e21 100644
--- a/src/errorBox.js
+++ b/src/errorBox.js
@@ -20,18 +20,14 @@
*/
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
-
const _ICON_SIZE = 128;
-var ErrorBox = new Lang.Class({
- Name: 'ErrorBox',
- Extends: Gtk.Grid,
-
- _init: function(primary, secondary) {
- this.parent({ orientation: Gtk.Orientation.VERTICAL,
+var ErrorBox = GObject.registerClass(class ErrorBox extends Gtk.Grid {
+ _init(primary, secondary) {
+ super._init({ orientation: Gtk.Orientation.VERTICAL,
row_spacing: 12,
hexpand: true,
vexpand: true,
@@ -61,9 +57,9 @@ var ErrorBox = new Lang.Class({
this.add(this._secondaryLabel);
this.show_all();
- },
+ }
- update: function(primary, secondary) {
+ update(primary, secondary) {
let primaryMarkup = '<big><b>' + GLib.markup_escape_text(primary, -1) + '</b></big>';
let secondaryMarkup = GLib.markup_escape_text(secondary, -1);
diff --git a/src/evinceview.js b/src/evinceview.js
index 6df5d94b..6d82c730 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -24,6 +24,7 @@ const EvView = imports.gi.EvinceView;
const GdPrivate = imports.gi.GdPrivate;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
@@ -38,66 +39,63 @@ const Preview = imports.preview;
const Utils = imports.utils;
const WindowMode = imports.windowMode;
-var EvinceView = new Lang.Class({
- Name: 'EvinceView',
- Extends: Preview.Preview,
-
- _init: function(overlay, mainWindow) {
+var EvinceView = GObject.registerClass(class EvinceView extends Preview.Preview {
+ _init(overlay, mainWindow) {
this._model = null;
this._jobFind = null;
this._pageChanged = false;
this._hasSelection = false;
this._viewSelectionChanged = false;
- this.parent(overlay, mainWindow);
+ super._init(overlay, mainWindow);
this.getAction('bookmark-page').enabled = false;
- },
+ }
- _copy: function() {
+ _copy() {
this._evView.copy();
- },
+ }
- _zoomIn: function() {
+ _zoomIn() {
if (!this._model)
return;
this._model.set_sizing_mode(EvView.SizingMode.FREE);
this._evView.zoom_in();
- },
+ }
- _zoomOut: function() {
+ _zoomOut() {
if (!this._model)
return;
this._model.set_sizing_mode(EvView.SizingMode.FREE);
this._evView.zoom_out();
- },
+ }
- _rotateLeft: function() {
+ _rotateLeft() {
let rotation = this._model.get_rotation();
this._model.set_rotation(rotation - 90);
- },
+ }
- _rotateRight: function() {
+ _rotateRight() {
let rotation = this._model.get_rotation();
this._model.set_rotation(rotation + 90);
- },
+ }
- findPrev: function() {
+ findPrev() {
this._evView.find_previous();
- },
+ }
- findNext: function() {
+ findNext() {
this._evView.find_next();
- },
+ }
- _places: function() {
+ _places() {
let dialog = new Places.PlacesDialog(this._model, this._bookmarks);
dialog.connect('response', Lang.bind(this, function(widget, response) {
widget.destroy();
}));
- },
+ }
- _findStateChanged: function(action) {
+ _findStateChanged(action) {
let toolbar = this.toolbar;
if (this.fullscreen)
toolbar = this.getFullscreenToolbar().toolbar;
@@ -109,9 +107,9 @@ var EvinceView = new Lang.Class({
toolbar.searchbar.conceal();
this._evView.find_set_highlight_search(false);
}
- },
+ }
- _bookmarkStateChanged: function(action) {
+ _bookmarkStateChanged(action) {
let pageNumber = this._model.page;
let bookmark = new GdPrivate.Bookmark({ page_number: pageNumber });
@@ -119,9 +117,9 @@ var EvinceView = new Lang.Class({
this._bookmarks.add(bookmark);
else
this._bookmarks.remove(bookmark);
- },
+ }
- _presentStateChanged: function(action) {
+ _presentStateChanged(action) {
if (!this._model)
return;
@@ -129,27 +127,27 @@ var EvinceView = new Lang.Class({
this._promptPresentation();
else
this._hidePresentation();
- },
+ }
- _edit: function() {
+ _edit() {
Application.modeController.setWindowMode(WindowMode.WindowMode.EDIT);
- },
+ }
- _print: function() {
+ _print() {
let doc = Application.documentManager.getActiveItem();
if (doc)
doc.print(this.mainWindow);
- },
+ }
- _scrollUp: function() {
+ _scrollUp() {
this._evView.scroll(Gtk.ScrollType.PAGE_BACKWARD, false);
- },
+ }
- _scrollDown: function() {
+ _scrollDown() {
this._evView.scroll(Gtk.ScrollType.PAGE_FORWARD, false);
- },
+ }
- createActions: function() {
+ createActions() {
let actions = [
{ name: 'zoom-in',
callback: Lang.bind(this, this._zoomIn),
@@ -205,17 +203,17 @@ var EvinceView = new Lang.Class({
accels: ['F5'] });
return actions;
- },
+ }
- createNavControls: function() {
+ createNavControls() {
return new EvinceViewNavControls(this, this.overlay);
- },
+ }
- createToolbar: function() {
+ createToolbar() {
return new EvinceViewToolbar(this);
- },
+ }
- createView: function() {
+ createView() {
let sw = new Gtk.ScrolledWindow({ hexpand: true,
vexpand: true });
sw.get_style_context().add_class('documents-scrolledwin');
@@ -242,23 +240,23 @@ var EvinceView = new Lang.Class({
this._handleExternalLink));
return sw;
- },
+ }
- onLoadStarted: function(manager, doc) {
- this.parent(manager, doc);
+ onLoadStarted(manager, doc) {
+ super.onLoadStarted(manager, doc);
this.getAction('bookmark-page').enabled = false;
this.getAction('find').enabled = false;
this.getAction('gear-menu').enabled = false;
this.getAction('places').enabled = false;
- },
+ }
- onLoadFinished: function(manager, doc, docModel) {
+ onLoadFinished(manager, doc, docModel) {
this.controlsVisible = false;
this._lastSearch = '';
this._model = docModel;
- this.parent(manager, doc, docModel);
+ super.onLoadFinished(manager, doc, docModel);
docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
@@ -293,16 +291,16 @@ var EvinceView = new Lang.Class({
this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
this.grab_focus();
- },
+ }
- onLoadError: function(manager, doc, message, exception) {
+ onLoadError(manager, doc, message, exception) {
this._controlsVisible = true;
this._syncControlsVisible();
- this.parent(manager, doc, message, exception);
- },
+ super.onLoadError(manager, doc, message, exception);
+ }
- _enableSearch: function() {
+ _enableSearch() {
let canFind = true;
try {
@@ -318,9 +316,9 @@ var EvinceView = new Lang.Class({
}
this.getAction('find').enabled = (this.hasPages && canFind);
- },
+ }
- _onPageChanged: function() {
+ _onPageChanged() {
let pageNumber = this._model.page;
this._pageChanged = true;
if (this._metadata)
@@ -333,25 +331,25 @@ var EvinceView = new Lang.Class({
let hasBookmark = (this._bookmarks.find_bookmark(bookmark) != null);
this.getAction('bookmark-page').change_state(GLib.Variant.new('b', hasBookmark));
- },
+ }
- _hidePresentation: function() {
+ _hidePresentation() {
if (this._presentation) {
this._presentation.close();
this._presentation = null;
}
this.getAction('present-current').change_state(GLib.Variant.new('b', false));
- },
+ }
- _showPresentation: function(output) {
+ _showPresentation(output) {
this._presentation = new Presentation.PresentationWindow(this._model);
this._presentation.connect('destroy', Lang.bind(this, this._hidePresentation));
if (output)
this._presentation.setOutput(output);
- },
+ }
- _promptPresentation: function() {
+ _promptPresentation() {
let outputs = new Presentation.PresentationOutputs();
if (outputs.list.length < 2) {
this._showPresentation();
@@ -367,9 +365,9 @@ var EvinceView = new Lang.Class({
}));
}
- },
+ }
- _onViewSelectionChanged: function() {
+ _onViewSelectionChanged() {
let hasSelection = this._evView.get_has_selection();
this.getAction('copy').enabled = hasSelection;
@@ -383,9 +381,9 @@ var EvinceView = new Lang.Class({
this._viewSelectionChanged = true;
if (!hasSelection)
this.cancelControlsFlip();
- },
+ }
- _uriRewrite: function(uri) {
+ _uriRewrite(uri) {
if (uri.substring(0, 3) != 'www.') {
/* Prepending "http://" when the url is a webpage (starts with
* "www.").
@@ -406,9 +404,9 @@ var EvinceView = new Lang.Class({
}
return uri;
- },
+ }
- _launchExternalUri: function(widget, action) {
+ _launchExternalUri(widget, action) {
let uri = action.get_uri();
let screen = widget.get_screen();
let context = screen.get_display().get_app_launch_context();
@@ -434,22 +432,22 @@ var EvinceView = new Lang.Class({
} catch (e) {
logError(e, 'Unable to open external link');
}
- },
+ }
- _handleExternalLink: function(widget, action) {
+ _handleExternalLink(widget, action) {
if (action.type == EvDocument.LinkActionType.EXTERNAL_URI)
this._launchExternalUri(widget, action);
- },
+ }
- _onCanZoomInChanged: function() {
+ _onCanZoomInChanged() {
this.getAction('zoom-in').enabled = this._evView.can_zoom_in;
- },
+ }
- _onCanZoomOutChanged: function() {
+ _onCanZoomOutChanged() {
this.getAction('zoom-out').enabled = this._evView.can_zoom_out;
- },
+ }
- _onButtonPressEvent: function(widget, event) {
+ _onButtonPressEvent(widget, event) {
let button = event.get_button()[1];
if (button == 3) {
@@ -460,9 +458,9 @@ var EvinceView = new Lang.Class({
this._viewSelectionChanged = false;
return false;
- },
+ }
- _onButtonReleaseEvent: function(widget, event) {
+ _onButtonReleaseEvent(widget, event) {
let button = event.get_button()[1];
let clickCount = event.get_click_count()[1];
@@ -476,26 +474,26 @@ var EvinceView = new Lang.Class({
this._viewSelectionChanged = false;
return false;
- },
+ }
- _onScrollbarClick: function() {
+ _onScrollbarClick() {
this.controlsVisible = false;
return false;
- },
+ }
- _onAdjustmentChanged: function() {
+ _onAdjustmentChanged() {
if (!this._pageChanged)
this.controlsVisible = false;
this._pageChanged = false;
- },
+ }
- search: function(str) {
+ search(str) {
this._evView.find_search_changed();
if (!this._model)
return;
- this.parent(str);
+ super.search(str);
if (this._jobFind) {
if (!this._jobFind.is_finished())
@@ -515,15 +513,15 @@ var EvinceView = new Lang.Class({
this._evView.find_started(this._jobFind);
this._jobFind.scheduler_push_job(EvView.JobPriority.PRIORITY_NONE);
- },
+ }
- _onSearchJobUpdated: function(job, page) {
+ _onSearchJobUpdated(job, page) {
let hasResults = job.has_results();
this.getAction('find-prev').enabled = hasResults;
this.getAction('find-next').enabled = hasResults;
- },
+ }
- _loadMetadata: function() {
+ _loadMetadata() {
let evDoc = this._model.get_document();
let file = Gio.File.new_for_uri(evDoc.get_uri());
if (!GdPrivate.is_metadata_supported_for_file(file))
@@ -536,31 +534,31 @@ var EvinceView = new Lang.Class({
this._model.set_page(val);
return metadata;
- },
+ }
- goPrev: function() {
+ goPrev() {
this._evView.previous_page();
- },
+ }
- goNext: function() {
+ goNext() {
this._evView.next_page();
- },
+ }
get hasPages() {
return this._model ? (this._model.document.get_n_pages() > 0) : false;
- },
+ }
get page() {
return this._model ? this._model.page : 0;
- },
+ }
get numPages() {
return this._model ? this._model.document.get_n_pages() : 0;
- },
+ }
get canFullscreen() {
return true;
- },
+ }
set nightMode(v) {
if (this._model)
@@ -568,11 +566,8 @@ var EvinceView = new Lang.Class({
}
});
-const EvinceViewNavControls = new Lang.Class({
- Name: 'EvinceViewNavControls',
- Extends: Preview.PreviewNavControls,
-
- createBarWidget: function() {
+const EvinceViewNavControls = class EvinceViewNavControls extends Preview.PreviewNavControls {
+ createBarWidget() {
let barWidget = new GdPrivate.NavBar();
let buttonArea = barWidget.get_button_area();
@@ -594,20 +589,17 @@ const EvinceViewNavControls = new Lang.Class({
buttonArea.pack_start(button, false, false, 0);
return barWidget;
- },
+ }
- setModel: function(model) {
+ setModel(model) {
this.barWidget.document_model = model;
model.connect('page-changed', Lang.bind(this, this._updateVisibility));
}
-});
-
-const EvinceViewToolbar = new Lang.Class({
- Name: 'EvinceViewToolbar',
- Extends: Preview.PreviewToolbar,
+}
- _init: function(preview) {
- this.parent(preview);
+const EvinceViewToolbar = GObject.registerClass(class EvinceViewToolbar extends Preview.PreviewToolbar {
+ _init(preview) {
+ super._init(preview);
this._handleEvent = false;
diff --git a/src/fullscreenAction.js b/src/fullscreenAction.js
index df12a9e1..d5b89913 100644
--- a/src/fullscreenAction.js
+++ b/src/fullscreenAction.js
@@ -27,9 +27,7 @@ const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
-var FullscreenAction = new Lang.Class({
- Name: 'FullscreenAction',
- Extends: GObject.Object,
+var FullscreenAction = GObject.registerClass({
Implements: [Gio.Action],
Properties: {
'enabled': GObject.ParamSpec.boolean('enabled', 'enabled', 'Whether the action is enabled',
@@ -42,33 +40,33 @@ var FullscreenAction = new Lang.Class({
'window': GObject.ParamSpec.object('window', 'Window', 'The GtkWindow',
GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
Gtk.Window.$gtype)
- },
-
- _init: function(params) {
+ }
+}, class FullscreenAction extends GObject.Object {
+ _init(params) {
this._enabled = true;
this._fullscreen = false;
this._window = null;
this._windowStateId = 0;
- this.parent(params);
- },
+ super._init(params);
+ }
- _disconnectFromWindow: function() {
+ _disconnectFromWindow() {
if (this._windowStateId != 0) {
this._window.disconnect(this._windowStateId);
this._windowStateId = 0;
}
- },
+ }
- _connectToWindow: function() {
+ _connectToWindow() {
if (this._window) {
this._windowStateId = this._window.connect('window-state-event',
Lang.bind(this, this._onWindowStateEvent));
this._onWindowStateEvent();
}
- },
+ }
- _onWindowStateEvent: function() {
+ _onWindowStateEvent() {
let window = this._window.get_window();
if (!window)
return;
@@ -80,9 +78,9 @@ var FullscreenAction = new Lang.Class({
this._fullscreen = fullscreen;
this.notify('state');
- },
+ }
- _changeState: function(fullscreen) {
+ _changeState(fullscreen) {
if (!this._window)
return;
@@ -90,40 +88,40 @@ var FullscreenAction = new Lang.Class({
this._window.fullscreen();
else
this._window.unfullscreen();
- },
+ }
- vfunc_activate: function() {
+ vfunc_activate() {
this._changeState(!this._fullscreen);
- },
+ }
- vfunc_change_state: function(state) {
+ vfunc_change_state(state) {
let fullscreen = state.get_boolean();
this._changeState(fullscreen);
- },
+ }
- vfunc_get_enabled: function() {
+ vfunc_get_enabled() {
return this.enabled;
- },
+ }
- vfunc_get_name: function() {
+ vfunc_get_name() {
return this.name;
- },
+ }
- vfunc_get_parameter_type: function() {
+ vfunc_get_parameter_type() {
return this.parameter_type;
- },
+ }
- vfunc_get_state: function() {
+ vfunc_get_state() {
return this.state;
- },
+ }
- vfunc_get_state_hint: function() {
+ vfunc_get_state_hint() {
return null;
- },
+ }
- vfunc_get_state_type: function() {
+ vfunc_get_state_type() {
return this.state_type;
- },
+ }
set enabled(v) {
if (v == this._enabled)
@@ -131,27 +129,27 @@ var FullscreenAction = new Lang.Class({
this._enabled = v;
this.notify('enabled');
- },
+ }
get enabled() {
return this._enabled;
- },
+ }
get name() {
return 'fullscreen';
- },
+ }
get parameter_type() {
return null;
- },
+ }
get state() {
return new GLib.Variant('b', this._fullscreen);
- },
+ }
get state_type() {
return new GLib.VariantType('b');
- },
+ }
set window(w) {
if (w == this._window)
@@ -162,9 +160,9 @@ var FullscreenAction = new Lang.Class({
this._connectToWindow();
this.notify('window');
- },
+ }
get window() {
return this._window;
- },
+ }
});
diff --git a/src/lokview.js b/src/lokview.js
index dfa0b962..ba363903 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -30,6 +30,7 @@ try {
const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
@@ -97,20 +98,17 @@ function isOpenDocumentFormat(mimeType) {
return false;
}
-var LOKView = new Lang.Class({
- Name: 'LOKView',
- Extends: Preview.Preview,
-
- _init: function(overlay, mainWindow) {
- this.parent(overlay, mainWindow);
+var LOKView = GObject.registerClass(class LOKView extends Preview.Preview {
+ _init(overlay, mainWindow) {
+ super._init(overlay, mainWindow);
this._progressBar = new Gtk.ProgressBar({ halign: Gtk.Align.FILL,
valign: Gtk.Align.START });
this._progressBar.get_style_context().add_class('osd');
this.overlay.add_overlay(this._progressBar);
- },
+ }
- createActions: function() {
+ createActions() {
return [
{ name: 'zoom-in',
callback: Lang.bind(this, this._zoomIn),
@@ -122,9 +120,9 @@ var LOKView = new Lang.Class({
callback: Lang.bind(this, this._copy),
accels: ['<Primary>c'] }
];
- },
+ }
- createView: function() {
+ createView() {
let sw = new Gtk.ScrolledWindow({ hexpand: true,
vexpand: true });
sw.get_style_context().add_class('documents-scrolledwin');
@@ -142,58 +140,58 @@ var LOKView = new Lang.Class({
}
return sw;
- },
+ }
- onLoadFinished: function(manager, doc) {
- this.parent(manager, doc);
+ onLoadFinished(manager, doc) {
+ super.onLoadFinished(manager, doc);
if (!isAvailable())
return;
this._doc = doc;
this._lokview.open_document(doc.uriToLoad, '{}', null, Lang.bind(this, this._onDocumentOpened));
this._progressBar.show();
- },
+ }
- _onDocumentOpened: function(res, doc) {
+ _onDocumentOpened(res, doc) {
// TODO: Call _finish and check failure
this._progressBar.hide();
this.set_visible_child_name('view');
this._lokview.set_edit(false);
- },
+ }
- _copy: function() {
+ _copy() {
let [selectedText, mimeType] = this._lokview.copy_selection('text/plain;charset=utf-8');
let display = Gdk.Display.get_default();
let clipboard = Gtk.Clipboard.get_default(display);
clipboard.set_text(selectedText, selectedText.length);
- },
+ }
- _zoomIn: function() {
+ _zoomIn() {
// FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97301
if (!this._doc)
return;
let zoomLevel = this._lokview.get_zoom() * ZOOM_IN_FACTOR;
this._lokview.set_zoom(zoomLevel);
- },
+ }
- _zoomOut: function() {
+ _zoomOut() {
// FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97301
if (!this._doc)
return;
let zoomLevel = this._lokview.get_zoom() * ZOOM_OUT_FACTOR;
this._lokview.set_zoom(zoomLevel);
- },
+ }
- _onCanZoomInChanged: function() {
+ _onCanZoomInChanged() {
this.getAction('zoom-in').enabled = this._lokview.can_zoom_in;
- },
+ }
- _onCanZoomOutChanged: function() {
+ _onCanZoomOutChanged() {
this.getAction('zoom-out').enabled = this._lokview.can_zoom_out;
- },
+ }
- _onButtonPressEvent: function(widget, event) {
+ _onButtonPressEvent(widget, event) {
let button = event.get_button()[1];
if (button == 3) {
@@ -203,17 +201,17 @@ var LOKView = new Lang.Class({
}
return false;
- },
+ }
- _onProgressChanged: function() {
+ _onProgressChanged() {
this._progressBar.fraction = this._lokview.load_progress;
- },
+ }
- _onTextSelection: function(hasSelection) {
+ _onTextSelection(hasSelection) {
this.getAction('copy').enabled = hasSelection;
- },
+ }
- goPrev: function() {
+ goPrev() {
let currentPart = this._lokview.get_part();
currentPart -= 1;
if (currentPart < 0)
@@ -221,9 +219,9 @@ var LOKView = new Lang.Class({
this._lokview.set_part(currentPart);
// FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97236
this._lokview.reset_view();
- },
+ }
- goNext: function() {
+ goNext() {
let totalParts = this._lokview.get_parts();
let currentPart = this._lokview.get_part();
currentPart += 1;
@@ -232,15 +230,15 @@ var LOKView = new Lang.Class({
this._lokview.set_part(currentPart);
// FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97236
this._lokview.reset_view();
- },
+ }
get hasPages() {
return this._doc ? isOpenDocumentPartDocument(this._doc.mimeType) : false;
- },
+ }
get page() {
return this._lokview.get_part();
- },
+ }
get numPages() {
return this._lokview.get_parts();
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 8cbf88bf..7da80b3e 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -22,6 +22,7 @@
const Gd = imports.gi.Gd;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gettext = imports.gettext;
@@ -32,15 +33,12 @@ const Lang = imports.lang;
const Application = imports.application;
const Searchbar = imports.searchbar;
-var MainToolbar = new Lang.Class({
- Name: 'MainToolbar',
- Extends: Gtk.Box,
-
- _init: function() {
+var MainToolbar = GObject.registerClass(class MainToolbar extends Gtk.Box {
+ _init() {
this._model = null;
this._handleEvent = true;
- this.parent({ orientation: Gtk.Orientation.VERTICAL });
+ super._init({ orientation: Gtk.Orientation.VERTICAL });
this.show();
this.toolbar = new Gtk.HeaderBar({ hexpand: true });
@@ -68,25 +66,25 @@ var MainToolbar = new Lang.Class({
Application.documentManager.disconnect(loadErrorId);
Application.documentManager.disconnect(passwordNeededId);
}));
- },
+ }
- createSearchbar: function() {
+ createSearchbar() {
return null;
- },
+ }
- _onLoadErrorOrPassword: function() {
+ _onLoadErrorOrPassword() {
this._handleEvent = false;
- },
+ }
- handleEvent: function(event) {
+ handleEvent(event) {
if (!this._handleEvent)
return false;
let res = this.searchbar.handleEvent(event);
return res;
- },
+ }
- addMenuButton: function() {
+ addMenuButton() {
let model_name = null;
let builder = Gtk.Builder.new_from_resource("/org/gnome/Documents/ui/documents-app-menu.ui");
@@ -98,18 +96,18 @@ var MainToolbar = new Lang.Class({
this.toolbar.pack_end(menuButton);
return menuButton;
- },
+ }
- addSearchButton: function(actionName) {
+ addSearchButton(actionName) {
let searchButton = new Gtk.ToggleButton({ image: new Gtk.Image ({ icon_name: 'edit-find-symbolic' }),
tooltip_text: Gettext.pgettext("toolbar button tooltip",
"Search"),
action_name: actionName,
visible: true });
this.toolbar.pack_start(searchButton);
return searchButton;
- },
+ }
- addBackButton: function() {
+ addBackButton() {
let backButton = new Gtk.Button({ image: new Gtk.Image({ icon_name: 'go-previous-symbolic' }),
tooltip_text: _("Back"),
action_name: 'view.go-back' });
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 505a91ea..74b49709 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -22,6 +22,7 @@
const GdPrivate = imports.gi.GdPrivate;
const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
@@ -37,14 +38,11 @@ const _CONFIGURE_ID_TIMEOUT = 100; // msecs
const _WINDOW_MIN_WIDTH = 600;
const _WINDOW_MIN_HEIGHT = 500;
-var MainWindow = new Lang.Class({
- Name: 'MainWindow',
- Extends: Gtk.ApplicationWindow,
-
- _init: function(app) {
+var MainWindow = GObject.registerClass(class MainWindow extends Gtk.ApplicationWindow {
+ _init(app) {
this._configureId = 0;
- this.parent({ application: app,
+ super._init({ application: app,
width_request: _WINDOW_MIN_WIDTH,
height_request: _WINDOW_MIN_HEIGHT,
window_position: Gtk.WindowPosition.CENTER,
@@ -78,9 +76,9 @@ var MainWindow = new Lang.Class({
this._embed = new Embed.Embed(this);
this.add(this._embed);
- },
+ }
- _saveWindowGeometry: function() {
+ _saveWindowGeometry() {
let window = this.get_window();
let state = window.get_state();
@@ -95,9 +93,9 @@ var MainWindow = new Lang.Class({
let position = this.get_position();
variant = GLib.Variant.new ('ai', position);
Application.settings.set_value('window-position', variant);
- },
+ }
- _onConfigureEvent: function(widget, event) {
+ _onConfigureEvent(widget, event) {
let window = this.get_window();
let state = window.get_state();
@@ -115,16 +113,16 @@ var MainWindow = new Lang.Class({
this._saveWindowGeometry();
return false;
}));
- },
+ }
- _onWindowStateEvent: function(widget, event) {
+ _onWindowStateEvent(widget, event) {
let window = widget.get_window();
let state = window.get_state();
let maximized = (state & Gdk.WindowState.MAXIMIZED);
Application.settings.set_boolean('window-maximized', maximized);
- },
+ }
- _onButtonPressEvent: function(widget, event) {
+ _onButtonPressEvent(widget, event) {
let button = event.get_button()[1];
let clickCount = event.get_click_count()[1];
@@ -143,14 +141,14 @@ var MainWindow = new Lang.Class({
}
return false;
- },
+ }
- _onKeyPressEvent: function(widget, event) {
+ _onKeyPressEvent(widget, event) {
let toolbar = this._embed.getMainToolbar();
return toolbar.handleEvent(event);
- },
+ }
- _quit: function() {
+ _quit() {
// remove configure event handler if still there
if (this._configureId != 0) {
Mainloop.source_remove(this._configureId);
@@ -161,9 +159,9 @@ var MainWindow = new Lang.Class({
this._saveWindowGeometry();
return false;
- },
+ }
- showAbout: function() {
+ showAbout() {
GdPrivate.show_about_dialog(this);
}
});
diff --git a/src/manager.js b/src/manager.js
index c7749e57..b9b3ea2d 100644
--- a/src/manager.js
+++ b/src/manager.js
@@ -21,14 +21,13 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Lang = imports.lang;
const Signals = imports.signals;
-var BaseManager = new Lang.Class({
- Name: 'BaseManager',
-
- _init: function(title, actionId, context) {
+var BaseManager = class BaseManager {
+ constructor(title, actionId, context) {
this._items = {};
this._activeItem = null;
this._title = null;
@@ -41,26 +40,26 @@ var BaseManager = new Lang.Class({
this._actionId = actionId;
this.context = context;
- },
+ }
- getActionId: function() {
+ getActionId() {
return this._actionId;
- },
+ }
- getTitle: function() {
+ getTitle() {
return this._title;
- },
+ }
- getItemById: function(id) {
+ getItemById(id) {
let retval = this._items[id];
if (!retval)
retval = null;
return retval;
- },
+ }
- addItem: function(item) {
+ addItem(item) {
item._manager = this;
let oldItem = this._items[item.id];
@@ -69,9 +68,9 @@ var BaseManager = new Lang.Class({
this._items[item.id] = item;
this.emit('item-added', item);
- },
+ }
- setActiveItem: function(item) {
+ setActiveItem(item) {
if (item != this._activeItem) {
this._activeItem = item;
this.emit('active-changed', this._activeItem);
@@ -80,30 +79,30 @@ var BaseManager = new Lang.Class({
}
return false;
- },
+ }
- setActiveItemById: function(id) {
+ setActiveItemById(id) {
let item = this.getItemById(id);
return this.setActiveItem(item);
- },
+ }
- getItems: function() {
+ getItems() {
return this._items;
- },
+ }
- getItemsCount: function() {
+ getItemsCount() {
return Object.keys(this._items).length;
- },
+ }
- getActiveItem: function() {
+ getActiveItem() {
return this._activeItem;
- },
+ }
- removeItem: function(item) {
+ removeItem(item) {
this.removeItemById(item.id);
- },
+ }
- removeItemById: function(id) {
+ removeItemById(id) {
let item = this._items[id];
if (item) {
@@ -111,19 +110,19 @@ var BaseManager = new Lang.Class({
this.emit('item-removed', item);
item._manager = null;
}
- },
+ }
- clear: function() {
+ clear() {
this._items = {};
this._activeItem = null;
this.emit('clear');
- },
+ }
- getFilter: function(flags) {
+ getFilter(flags) {
log('Error: BaseManager implementations must override getFilter');
- },
+ }
- getWhere: function() {
+ getWhere() {
let item = this.getActiveItem();
let retval = '';
@@ -131,14 +130,14 @@ var BaseManager = new Lang.Class({
retval = item.getWhere();
return retval;
- },
+ }
- forEachItem: function(func) {
+ forEachItem(func) {
for (let idx in this._items)
func(this._items[idx]);
- },
+ }
- getAllFilter: function() {
+ getAllFilter() {
let filters = [];
this.forEachItem(function(item) {
@@ -147,9 +146,9 @@ var BaseManager = new Lang.Class({
});
return '(' + filters.join(' || ') + ')';
- },
+ }
- processNewItems: function(newItems) {
+ processNewItems(newItems) {
let oldItems = this.getItems();
let idx;
@@ -171,23 +170,20 @@ var BaseManager = new Lang.Class({
// TODO: merge existing item properties with new values
}
-});
+}
Signals.addSignalMethods(BaseManager.prototype);
-var BaseModel = new Lang.Class({
- Name: 'BaseModel',
- Extends: Gio.Menu,
-
- _init: function(manager) {
- this.parent();
+var BaseModel = GObject.registerClass(class BaseModel extends Gio.Menu {
+ _init(manager) {
+ super._init();
this._manager = manager;
this._manager.connect('item-added', Lang.bind(this, this._refreshModel));
this._manager.connect('item-removed', Lang.bind(this, this._refreshModel));
this._refreshModel();
- },
+ }
- _refreshModel: function() {
+ _refreshModel() {
this.remove_all();
let menuItem;
diff --git a/src/notifications.js b/src/notifications.js
index 6e542b09..02838e8f 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -21,6 +21,7 @@
const Gd = imports.gi.Gd;
const Gettext = imports.gettext;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const TrackerControl = imports.gi.TrackerControl;
const _ = imports.gettext.gettext;
@@ -33,10 +34,8 @@ const Mainloop = imports.mainloop;
var DELETE_TIMEOUT = 10; // seconds
-var DeleteNotification = new Lang.Class({
- Name: 'DeleteNotification',
-
- _init: function(docs) {
+var DeleteNotification = class DeleteNotification {
+ constructor(docs) {
this._docs = docs;
this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
column_spacing: 12 });
@@ -89,9 +88,9 @@ var DeleteNotification = new Lang.Class({
this._deleteItems();
return false;
}));
- },
+ }
- _deleteItems: function() {
+ _deleteItems() {
this._docs.forEach(Lang.bind(this,
function(doc) {
doc.trash();
@@ -99,20 +98,18 @@ var DeleteNotification = new Lang.Class({
this._removeTimeout();
this.widget.destroy();
- },
+ }
- _removeTimeout: function() {
+ _removeTimeout() {
if (this._timeoutId != 0) {
Mainloop.source_remove(this._timeoutId);
this._timeoutId = 0;
}
}
-});
-
-var PrintNotification = new Lang.Class({
- Name: 'PrintNotification',
+}
- _init: function(printOp, doc) {
+var PrintNotification = class PrintNotification {
+ constructor(printOp, doc) {
this.widget = null;
this._printOp = printOp;
this._doc = doc;
@@ -121,9 +118,9 @@ var PrintNotification = new Lang.Class({
Lang.bind(this, this._onPrintBegin));
this._printOp.connect('status-changed',
Lang.bind(this, this._onPrintStatus));
- },
+ }
- _onPrintBegin: function() {
+ _onPrintBegin() {
this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
row_spacing: 6 });
@@ -148,9 +145,9 @@ var PrintNotification = new Lang.Class({
}));
Application.notificationManager.addNotification(this);
- },
+ }
- _onPrintStatus: function() {
+ _onPrintStatus() {
if (!this.widget)
return;
@@ -164,15 +161,13 @@ var PrintNotification = new Lang.Class({
if (fraction == 1)
this.widget.destroy();
}
-});
+}
const REMOTE_MINER_TIMEOUT = 10; // seconds
const TRACKER_MINER_FILES_NAME = 'org.freedesktop.Tracker1.Miner.Files';
-const IndexingNotification = new Lang.Class({
- Name: 'IndexingNotification',
-
- _init: function() {
+const IndexingNotification = class IndexingNotification {
+ constructor() {
this._closed = false;
this._timeoutId = 0;
@@ -187,9 +182,9 @@ const IndexingNotification = new Lang.Class({
Application.application.connect('miners-changed', Lang.bind(this, this._checkNotification));
Application.modeController.connect('window-mode-changed', Lang.bind(this, this._checkNotification));
- },
+ }
- _checkNotification: function() {
+ _checkNotification() {
if (Application.modeController.getWindowMode() == WindowMode.WindowMode.PREVIEW_EV) {
this._destroy(false);
return;
@@ -220,9 +215,9 @@ const IndexingNotification = new Lang.Class({
} else {
this._destroy(false);
}
- },
+ }
- _onTimeoutExpired: function() {
+ _onTimeoutExpired() {
this._timeoutId = 0;
let primary = null;
@@ -243,16 +238,16 @@ const IndexingNotification = new Lang.Class({
this._display(primary, null);
return false;
- },
+ }
- _removeTimeout: function() {
+ _removeTimeout() {
if (this._timeoutId != 0) {
Mainloop.source_remove(this._timeoutId);
this._timeoutId = 0;
}
- },
+ }
- _buildWidget: function() {
+ _buildWidget() {
this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
column_spacing: 12 });
@@ -286,9 +281,9 @@ const IndexingNotification = new Lang.Class({
this.widget.add(close);
Application.notificationManager.addNotification(this);
- },
+ }
- _update: function(primaryText, secondaryText) {
+ _update(primaryText, secondaryText) {
this._primaryLabel.label = primaryText;
this._secondaryLabel.label = secondaryText;
@@ -299,9 +294,9 @@ const IndexingNotification = new Lang.Class({
this._primaryLabel.vexpand = true;
this._secondaryLabel.hide();
}
- },
+ }
- _display: function(primaryText, secondaryText) {
+ _display(primaryText, secondaryText) {
if (this._closed) {
return;
}
@@ -310,9 +305,9 @@ const IndexingNotification = new Lang.Class({
this._buildWidget();
this._update(primaryText, secondaryText);
- },
+ }
- _destroy: function(closed) {
+ _destroy(closed) {
this._removeTimeout();
if (this.widget) {
@@ -322,14 +317,11 @@ const IndexingNotification = new Lang.Class({
this._closed = closed;
}
-});
-
-var NotificationManager = new Lang.Class({
- Name: 'NotificationManager',
- Extends: Gtk.Revealer,
+}
- _init: function() {
- this.parent({ halign: Gtk.Align.CENTER,
+var NotificationManager = GObject.registerClass(class NotificationManager extends Gtk.Revealer {
+ _init() {
+ super._init({ halign: Gtk.Align.CENTER,
valign: Gtk.Align.START });
let frame = new Gtk.Frame();
@@ -343,17 +335,17 @@ var NotificationManager = new Lang.Class({
// add indexing monitor notification
this._indexingNotification = new IndexingNotification();
- },
+ }
- addNotification: function(notification) {
+ addNotification(notification) {
this._grid.add(notification.widget);
notification.widget.connect('destroy', Lang.bind(this, this._onWidgetDestroy));
this.show_all();
this.reveal_child = true;
- },
+ }
- _onWidgetDestroy: function() {
+ _onWidgetDestroy() {
let children = this._grid.get_children();
if (children.length == 0)
diff --git a/src/overview.js b/src/overview.js
index 4dc60fae..328fe7ee 100644
--- a/src/overview.js
+++ b/src/overview.js
@@ -70,12 +70,9 @@ function getController(windowMode) {
const _RESET_COUNT_TIMEOUT = 500; // msecs
-const ViewModel = new Lang.Class({
- Name: 'ViewModel',
- Extends: Gtk.ListStore,
-
- _init: function(windowMode) {
- this.parent();
+const ViewModel = GObject.registerClass(class ViewModel extends Gtk.ListStore {
+ _init(windowMode) {
+ super._init();
this.set_column_types(
[ GObject.TYPE_STRING,
GObject.TYPE_STRING,
@@ -110,9 +107,9 @@ const ViewModel = new Lang.Class({
for (let idx in items) {
this._onItemAdded(Application.documentManager, items[idx]);
}
- },
+ }
- _clear: function() {
+ _clear() {
let items = Application.documentManager.getItems();
for (let idx in items) {
let doc = items[idx];
@@ -120,9 +117,9 @@ const ViewModel = new Lang.Class({
}
this.clear();
- },
+ }
- _addItem: function(doc) {
+ _addItem(doc) {
// Update the count so that OffsetController has the correct
// values. Otherwise things like loading more items and "No
// Results" page will not work correctly.
@@ -137,9 +134,9 @@ const ViewModel = new Lang.Class({
let treePath = this.get_path(iter);
let treeRowRef = Gtk.TreeRowReference.new(this, treePath);
doc.rowRefs[this._rowRefKey] = treeRowRef;
- },
+ }
- _removeItem: function(doc) {
+ _removeItem(doc) {
// Update the count so that OffsetController has the correct
// values. Otherwise things like loading more items and "No
// Results" page will not work correctly.
@@ -158,9 +155,9 @@ const ViewModel = new Lang.Class({
}));
doc.rowRefs[this._rowRefKey] = null;
- },
+ }
- _onInfoUpdated: function(doc) {
+ _onInfoUpdated(doc) {
let activeCollection = Application.documentManager.getActiveCollection();
let treeRowRef = doc.rowRefs[this._rowRefKey];
@@ -191,9 +188,9 @@ const ViewModel = new Lang.Class({
[ doc.id, doc.uri, doc.name,
doc.author, doc.surface, doc.mtime ]);
}
- },
+ }
- _onItemAdded: function(source, doc) {
+ _onItemAdded(source, doc) {
if (doc.rowRefs[this._rowRefKey])
return;
@@ -216,15 +213,15 @@ const ViewModel = new Lang.Class({
this._addItem(doc);
this._infoUpdatedIds[doc.id] = doc.connect('info-updated', Lang.bind(this, this._onInfoUpdated));
- },
+ }
- _onItemRemoved: function(source, doc) {
+ _onItemRemoved(source, doc) {
this._removeItem(doc);
doc.disconnect(this._infoUpdatedIds[doc.id]);
delete this._infoUpdatedIds[doc.id];
- },
+ }
- _resetCount: function() {
+ _resetCount() {
if (this._resetCountId == 0) {
this._resetCountId = Mainloop.timeout_add(_RESET_COUNT_TIMEOUT, Lang.bind(this,
function() {
@@ -236,13 +233,10 @@ const ViewModel = new Lang.Class({
}
});
-const EmptyResultsBox = new Lang.Class({
- Name: 'EmptyResultsBox',
- Extends: Gtk.Grid,
-
- _init: function(mode) {
+const EmptyResultsBox = GObject.registerClass(class EmptyResultsBox extends Gtk.Grid {
+ _init(mode) {
this._mode = mode;
- this.parent({ orientation: Gtk.Orientation.VERTICAL,
+ super._init({ orientation: Gtk.Orientation.VERTICAL,
row_spacing: 12,
hexpand: true,
vexpand: true,
@@ -255,9 +249,9 @@ const EmptyResultsBox = new Lang.Class({
this._addSecondaryLabel();
this.show_all();
- },
+ }
- _addImage: function() {
+ _addImage() {
let iconName;
if (this._mode == WindowMode.WindowMode.SEARCH)
iconName = 'system-search-symbolic';
@@ -267,9 +261,9 @@ const EmptyResultsBox = new Lang.Class({
iconName = 'x-office-document-symbolic';
this.add(new Gtk.Image({ pixel_size: 128, icon_name: iconName, margin_bottom: 9 }));
- },
+ }
- _addPrimaryLabel: function() {
+ _addPrimaryLabel() {
let text;
if (this._mode == WindowMode.WindowMode.COLLECTIONS)
text = _("No collections found");
@@ -279,9 +273,9 @@ const EmptyResultsBox = new Lang.Class({
this.add(new Gtk.Label({ label: '<b><span size="large">' + text + '</span></b>',
use_markup: true,
margin_top: 9 }));
- },
+ }
- _addSecondaryLabel: function() {
+ _addSecondaryLabel() {
if (this._mode == WindowMode.WindowMode.SEARCH) {
this.add(new Gtk.Label({ label: _("Try a different search") }));
return;
@@ -325,14 +319,11 @@ const EmptyResultsBox = new Lang.Class({
}
});
-const OverviewSearchbar = new Lang.Class({
- Name: 'OverviewSearchbar',
- Extends: Searchbar.Searchbar,
-
- _init: function(view) {
+const OverviewSearchbar = GObject.registerClass(class OverviewSearchbar extends Searchbar.Searchbar {
+ _init(view) {
this._view = view;
- this.parent();
+ super._init();
let sourcesId = Application.sourceManager.connect('active-changed',
Lang.bind(this, this._onActiveSourceChanged));
@@ -367,9 +358,9 @@ const OverviewSearchbar = new Lang.Class({
searchAction.disconnect(searchStateId);
}));
- },
+ }
- createSearchWidget: function() {
+ createSearchWidget() {
// create the search entry
this.searchEntry = new Gd.TaggedEntry({ width_request: 500 });
this.searchEntry.connect('tag-clicked',
@@ -403,9 +394,9 @@ const OverviewSearchbar = new Lang.Class({
box.show_all();
return box;
- },
+ }
- entryChanged: function() {
+ entryChanged() {
let currentText = this.searchEntry.get_text();
Application.searchController.disconnect(this._searchChangedId);
@@ -414,13 +405,13 @@ const OverviewSearchbar = new Lang.Class({
// connect to search string changes in the controller
this._searchChangedId = Application.searchController.connect('search-string-changed',
Lang.bind(this, this._onSearchStringChanged));
- },
+ }
- _onSearchStringChanged: function(controller, string) {
+ _onSearchStringChanged(controller, string) {
this.searchEntry.set_text(string);
- },
+ }
- _onActiveCollectionChanged: function(manager, collection) {
+ _onActiveCollectionChanged(manager, collection) {
if (!collection)
return;
@@ -431,9 +422,9 @@ const OverviewSearchbar = new Lang.Class({
Application.searchTypeManager.setActiveItemById('all');
this.searchEntry.set_text('');
}
- },
+ }
- _onActiveChangedCommon: function(id, manager, tag) {
+ _onActiveChangedCommon(id, manager, tag) {
let item = manager.getActiveItem();
if (item.id == 'all') {
@@ -444,21 +435,21 @@ const OverviewSearchbar = new Lang.Class({
}
this.searchEntry.grab_focus_without_selecting();
- },
+ }
- _onActiveSourceChanged: function() {
+ _onActiveSourceChanged() {
this._onActiveChangedCommon('source', Application.sourceManager, this._sourceTag);
- },
+ }
- _onActiveTypeChanged: function() {
+ _onActiveTypeChanged() {
this._onActiveChangedCommon('type', Application.searchTypeManager, this._typeTag);
- },
+ }
- _onActiveMatchChanged: function() {
+ _onActiveMatchChanged() {
this._onActiveChangedCommon('match', Application.searchMatchManager, this._matchTag);
- },
+ }
- _onTagButtonClicked: function(entry, tag) {
+ _onTagButtonClicked(entry, tag) {
let manager = null;
if (tag == this._matchTag) {
@@ -472,35 +463,32 @@ const OverviewSearchbar = new Lang.Class({
if (manager) {
manager.setActiveItemById('all');
}
- },
+ }
- _onTagClicked: function() {
+ _onTagClicked() {
this._dropdownButton.set_active(true);
- },
+ }
- _onActionStateChanged: function(action) {
+ _onActionStateChanged(action) {
if (action.state.get_boolean())
this.reveal();
else
this.conceal();
- },
+ }
- conceal: function() {
+ conceal() {
this._dropdownButton.set_active(false);
Application.searchTypeManager.setActiveItemById('all');
Application.searchMatchManager.setActiveItemById('all');
Application.sourceManager.setActiveItemById('all');
- this.parent();
+ super.conceal();
}
});
-const OverviewToolbar = new Lang.Class({
- Name: 'OverviewToolbar',
- Extends: MainToolbar.MainToolbar,
-
- _init: function(view) {
+const OverviewToolbar = GObject.registerClass(class OverviewToolbar extends MainToolbar.MainToolbar {
+ _init(view) {
this._collBackButton = null;
this._collectionId = 0;
this._selectionChangedId = 0;
@@ -512,7 +500,7 @@ const OverviewToolbar = new Lang.Class({
this._view = view;
- this.parent();
+ super._init();
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Documents/ui/selection-menu.ui');
@@ -542,9 +530,9 @@ const OverviewToolbar = new Lang.Class({
this._clearStateData();
selectionModeAction.disconnect(selectionModeStateId);
}));
- },
+ }
- _addViewMenuButton: function() {
+ _addViewMenuButton() {
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Documents/ui/view-menu.ui');
let viewMenu = builder.get_object('viewMenu');
@@ -557,15 +545,15 @@ const OverviewToolbar = new Lang.Class({
this._viewSettingsId = Application.settings.connect('changed::view-as',
Lang.bind(this, this._updateViewMenuButton));
this._updateViewMenuButton();
- },
+ }
- _updateViewMenuButton: function() {
+ _updateViewMenuButton() {
let viewType = Application.settings.get_enum('view-as');
let iconName = viewType == Gd.MainViewType.ICON ? 'view-grid-symbolic' : 'view-list-symbolic';
this._viewMenuButton.image = new Gtk.Image({ icon_name: iconName, pixel_size: 16 })
- },
+ }
- _setToolbarTitle: function() {
+ _setToolbarTitle() {
let selectionMode = this._view.getAction('selection-mode').state.get_boolean();
let activeCollection = Application.documentManager.getActiveCollection();
let primary = null;
@@ -598,9 +586,9 @@ const OverviewToolbar = new Lang.Class({
} else {
this.toolbar.set_title(primary);
}
- },
+ }
- _populateForSelectionMode: function() {
+ _populateForSelectionMode() {
this.toolbar.get_style_context().add_class('selection-mode');
this.toolbar.set_custom_title(this._selectionMenu);
@@ -614,9 +602,9 @@ const OverviewToolbar = new Lang.Class({
Lang.bind(this, this._setToolbarTitle));
this.addSearchButton('view.search');
- },
+ }
- _checkCollectionWidgets: function() {
+ _checkCollectionWidgets() {
let customTitle;
let item = Application.documentManager.getActiveCollection();
@@ -636,9 +624,9 @@ const OverviewToolbar = new Lang.Class({
}
this.toolbar.set_custom_title(customTitle);
- },
+ }
- _onActiveCollectionChanged: function(manager, activeCollection) {
+ _onActiveCollectionChanged(manager, activeCollection) {
if (activeCollection) {
this._infoUpdatedId = activeCollection.connect('info-updated', Lang.bind(this,
this._setToolbarTitle));
} else {
@@ -650,9 +638,9 @@ const OverviewToolbar = new Lang.Class({
this._activeCollection = activeCollection;
this._checkCollectionWidgets();
this._setToolbarTitle();
- },
+ }
- _populateForOverview: function() {
+ _populateForOverview() {
this.toolbar.set_show_close_button(true);
this.toolbar.set_custom_title(this._stackSwitcher);
this._checkCollectionWidgets();
@@ -671,9 +659,9 @@ const OverviewToolbar = new Lang.Class({
this._collectionId =
Application.documentManager.connect('active-collection-changed',
Lang.bind(this, this._onActiveCollectionChanged));
- },
+ }
- _clearStateData: function() {
+ _clearStateData() {
this._collBackButton = null;
this._viewMenuButton = null;
this.toolbar.set_custom_title(null);
@@ -697,18 +685,18 @@ const OverviewToolbar = new Lang.Class({
Application.settings.disconnect(this._viewSettingsId);
this._viewSettingsId = 0;
}
- },
+ }
- _clearToolbar: function() {
+ _clearToolbar() {
this._clearStateData();
this.toolbar.set_show_close_button(false);
this.toolbar.get_style_context().remove_class('selection-mode');
let children = this.toolbar.get_children();
children.forEach(function(child) { child.destroy(); });
- },
+ }
- _resetToolbarMode: function() {
+ _resetToolbarMode() {
this._clearToolbar();
let selectionMode = this._view.getAction('selection-mode').state.get_boolean();
@@ -730,24 +718,21 @@ const OverviewToolbar = new Lang.Class({
if (Application.searchController.getString() != '')
this._view.getAction('search').change_state(GLib.Variant.new('b', true));
- },
+ }
- createSearchbar: function() {
+ createSearchbar() {
return new OverviewSearchbar(this._view);
}
});
-const ViewContainer = new Lang.Class({
- Name: 'ViewContainer',
- Extends: Gtk.Stack,
-
- _init: function(overview, windowMode) {
+const ViewContainer = GObject.registerClass(class ViewContainer extends Gtk.Stack {
+ _init(overview, windowMode) {
this._edgeHitId = 0;
this._mode = windowMode;
this._model = new ViewModel(this._mode);
- this.parent({ homogeneous: true,
+ super._init({ homogeneous: true,
transition_type: Gtk.StackTransitionType.CROSSFADE });
this.view = new Gd.MainView({ shadow_type: Gtk.ShadowType.NONE });
@@ -807,14 +792,14 @@ const ViewContainer = new Lang.Class({
// this will create the model if we're done querying
this._onQueryStatusChanged();
- },
+ }
- _onViewTypeChanged: function() {
+ _onViewTypeChanged() {
if (this.view.view_type == Gd.MainViewType.LIST)
this._addListRenderers();
- },
+ }
- _onSizeAllocate: function() {
+ _onSizeAllocate() {
let vadjustment = this.view.get_vadjustment();
let viewHeight = this.view.get_generic_view().get_allocation().height;
let scrollIsAtTop = vadjustment.value == 0;
@@ -822,12 +807,10 @@ const ViewContainer = new Lang.Class({
let hasMoreDocuments = this._offsetController.getRemainingDocs() > 0;
if (scrollIsAtTop && scrollMaxIsHeight && hasMoreDocuments)
- {
this._offsetController.increaseOffset();
- }
- },
+ }
- _getFirstDocument: function() {
+ _getFirstDocument() {
let doc = null;
let [success, iter] = this._model.get_iter_first();
@@ -837,9 +820,9 @@ const ViewContainer = new Lang.Class({
}
return doc;
- },
+ }
- _addListRenderers: function() {
+ _addListRenderers() {
let listWidget = this.view.get_generic_view();
let typeRenderer =
@@ -908,21 +891,21 @@ const ViewContainer = new Lang.Class({
years).format(years);
}
}));
- },
+ }
- _onSelectionModeRequest: function() {
+ _onSelectionModeRequest() {
this._selectionModeAction.change_state(GLib.Variant.new('b', true));
- },
+ }
- _onItemActivated: function(widget, id, path) {
+ _onItemActivated(widget, id, path) {
Application.documentManager.setActiveItemById(id);
- },
+ }
- _onQueryError: function(manager, message, exception) {
+ _onQueryError(manager, message, exception) {
this._setError(message, exception.message);
- },
+ }
- _onQueryStatusChanged: function() {
+ _onQueryStatusChanged() {
let status = this._trackerController.getQueryStatus();
if (!status) {
@@ -948,14 +931,14 @@ const ViewContainer = new Lang.Class({
this._spinner.start();
this.set_visible_child_name('spinner');
}
- },
+ }
- _setError: function(primary, secondary) {
+ _setError(primary, secondary) {
this._errorBox.update(primary, secondary);
this.set_visible_child_name('error');
- },
+ }
- _updateSelection: function() {
+ _updateSelection() {
let selected = Application.selectionController.getSelection();
let newSelection = [];
@@ -986,14 +969,14 @@ const ViewContainer = new Lang.Class({
}));
Application.selectionController.setSelection(newSelection);
- },
+ }
- _onSelectionModeChanged: function() {
+ _onSelectionModeChanged() {
let selectionMode = this._selectionModeAction.state.get_boolean();
this.view.set_selection_mode(selectionMode);
- },
+ }
- _onViewSelectionChanged: function() {
+ _onViewSelectionChanged() {
let mode = Application.modeController.getWindowMode();
if (this._mode != mode)
return;
@@ -1002,48 +985,45 @@ const ViewContainer = new Lang.Class({
let selectedURNs = Utils.getURNsFromPaths(this.view.get_selection(),
this._model);
Application.selectionController.setSelection(selectedURNs);
- },
+ }
- _onWindowModeChanged: function() {
+ _onWindowModeChanged() {
let mode = Application.modeController.getWindowMode();
if (mode == this._mode)
this._connectView();
else
this._disconnectView();
- },
+ }
- _connectView: function() {
+ _connectView() {
this._edgeHitId = this.view.connect('edge-reached', Lang.bind(this,
function (view, pos) {
if (pos == Gtk.PositionType.BOTTOM)
this._offsetController.increaseOffset();
}));
- },
+ }
- _disconnectView: function() {
+ _disconnectView() {
if (this._edgeHitId != 0) {
this.view.disconnect(this._edgeHitId);
this._edgeHitId = 0;
}
- },
+ }
- activateResult: function() {
+ activateResult() {
let doc = this._getFirstDocument();
if (doc)
Application.documentManager.setActiveItem(doc)
- },
+ }
get model() {
return this._model;
}
});
-var OverviewStack = new Lang.Class({
- Name: 'OverviewStack',
- Extends: Gtk.Box,
-
- _init: function() {
- this.parent({ orientation: Gtk.Orientation.VERTICAL,
+var OverviewStack = GObject.registerClass(class OverviewStack extends Gtk.Box {
+ _init() {
+ super._init({ orientation: Gtk.Orientation.VERTICAL,
visible: true });
let actions = this._getDefaultActions();
@@ -1069,9 +1049,9 @@ var OverviewStack = new Lang.Class({
this._stack.connect('notify::visible-child',
Lang.bind(this, this._onVisibleChildChanged));
- },
+ }
- _getDefaultActions: function() {
+ _getDefaultActions() {
let backAccels = ['Back'];
if (this.get_direction() == Gtk.TextDirection.LTR)
backAccels.push('<Alt>Left');
@@ -1115,27 +1095,27 @@ var OverviewStack = new Lang.Class({
stateChanged: Lang.bind(this, this._updateSearchMatch),
create_hook: Lang.bind(this, this._initSearchMatch) }
];
- },
+ }
- _goBack: function() {
+ _goBack() {
Application.documentManager.activatePreviousCollection();
- },
+ }
- _selectAll: function() {
+ _selectAll() {
this.getAction('selection-mode').change_state(GLib.Variant.new('b', true));
this.view.view.select_all();
- },
+ }
- _selectNone: function() {
+ _selectNone() {
this.view.view.unselect_all();
- },
+ }
- _updateTypeForSettings: function() {
+ _updateTypeForSettings() {
let viewType = Application.settings.get_enum('view-as');
this.view.view.set_view_type(viewType);
- },
+ }
- _updateSortForSettings: function() {
+ _updateSortForSettings() {
let sortBy = Application.settings.get_enum('sort-by');
let sortType;
@@ -1156,9 +1136,9 @@ var OverviewStack = new Lang.Class({
}
this.view.model.set_sort_column_id(sortBy, sortType);
- },
+ }
- _updateSelectionMode: function(action) {
+ _updateSelectionMode(action) {
let selectionMode = action.state.get_boolean();
if (selectionMode) {
@@ -1168,42 +1148,42 @@ var OverviewStack = new Lang.Class({
Application.application.set_accels_for_action('view.selection-mode', []);
this._selectionToolbar.hide();
}
- },
+ }
- _initSearchSource: function(action) {
+ _initSearchSource(action) {
Application.sourceManager.connect('active-changed', Lang.bind(this, function(manager, activeItem) {
action.state = GLib.Variant.new('s', activeItem.id);
}));
- },
+ }
- _initSearchType: function(action) {
+ _initSearchType(action) {
Application.searchTypeManager.connect('active-changed', Lang.bind(this, function(manager,
activeItem) {
action.state = GLib.Variant.new('s', activeItem.id);
}));
- },
+ }
- _initSearchMatch: function(action) {
+ _initSearchMatch(action) {
Application.searchMatchManager.connect('active-changed', Lang.bind(this, function(manager,
activeItem) {
action.state = GLib.Variant.new('s', activeItem.id);
}));
- },
+ }
- _updateSearchSource: function(action) {
+ _updateSearchSource(action) {
let itemId = action.state.get_string()[0];
Application.sourceManager.setActiveItemById(itemId);
- },
+ }
- _updateSearchType: function(action) {
+ _updateSearchType(action) {
let itemId = action.state.get_string()[0];
Application.searchTypeManager.setActiveItemById(itemId);
- },
+ }
- _updateSearchMatch: function(action) {
+ _updateSearchMatch(action) {
let itemId = action.state.get_string()[0];
Application.searchMatchManager.setActiveItemById(itemId);
- },
+ }
- _onVisibleChildChanged: function() {
+ _onVisibleChildChanged() {
let windowMode;
if (this.view == this._collections)
@@ -1214,7 +1194,7 @@ var OverviewStack = new Lang.Class({
return;
Application.modeController.setWindowMode(windowMode);
- },
+ }
set windowMode(mode) {
let visibleChild;
@@ -1236,23 +1216,23 @@ var OverviewStack = new Lang.Class({
this._stack.visible_child = visibleChild;
this._updateSortForSettings();
this._updateTypeForSettings();
- },
+ }
- activateResult: function() {
+ activateResult() {
this.view.activateResult();
- },
+ }
- createToolbar: function() {
+ createToolbar() {
return new OverviewToolbar(this);
- },
+ }
- getAction: function(name) {
+ getAction(name) {
return this.actionGroup.lookup_action(name);
- },
+ }
get stack() {
return this._stack;
- },
+ }
get view() {
return this._stack.visible_child;
diff --git a/src/password.js b/src/password.js
index 5a179be9..ee125be1 100644
--- a/src/password.js
+++ b/src/password.js
@@ -19,6 +19,7 @@
*
*/
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
@@ -26,13 +27,10 @@ const Application = imports.application;
const Lang = imports.lang;
-var PasswordDialog = new Lang.Class({
- Name: 'PasswordDialog',
- Extends: Gtk.Dialog,
-
- _init: function(doc) {
+var PasswordDialog = GObject.registerClass(class PasswordDialog extends Gtk.Dialog {
+ _init(doc) {
let toplevel = Application.application.get_windows()[0];
- this.parent({ resizable: false,
+ super._init({ resizable: false,
transient_for: toplevel,
modal: true,
destroy_with_parent: true,
diff --git a/src/places.js b/src/places.js
index 0bebbde0..14458971 100644
--- a/src/places.js
+++ b/src/places.js
@@ -17,6 +17,7 @@
*
*/
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const EvDocument = imports.gi.EvinceDocument;
@@ -25,13 +26,10 @@ const Application = imports.application;
const Lang = imports.lang;
-var PlacesDialog = new Lang.Class({
- Name: 'PlacesDialog',
- Extends: Gtk.Dialog,
-
- _init: function(model, bookmarks) {
+var PlacesDialog = GObject.registerClass(class PlacesDialog extends Gtk.Dialog {
+ _init(model, bookmarks) {
let toplevel = Application.application.get_windows()[0];
- this.parent({ resizable: true,
+ super._init({ resizable: true,
transient_for: toplevel,
modal: true,
destroy_with_parent: true,
@@ -45,9 +43,9 @@ var PlacesDialog = new Lang.Class({
this._bookmarks = bookmarks;
this._createWindow();
this.show_all();
- },
+ }
- _createWindow: function() {
+ _createWindow() {
let contentArea = this.get_content_area();
this._stack = new Gtk.Stack({ border_width: 5,
homogeneous: true });
@@ -90,21 +88,21 @@ var PlacesDialog = new Lang.Class({
let switcher = new Gtk.StackSwitcher({ stack: this._stack });
header.set_custom_title(switcher);
}
- },
+ }
- _handleLink: function(link) {
+ _handleLink(link) {
if (link.action.type == EvDocument.LinkActionType.GOTO_DEST) {
this._gotoDest(link.action.dest);
}
this.response(Gtk.ResponseType.DELETE_EVENT);
- },
+ }
- _handleBookmark: function(bookmark) {
+ _handleBookmark(bookmark) {
this._model.set_page(bookmark.page_number);
this.response(Gtk.ResponseType.DELETE_EVENT);
- },
+ }
- _gotoDest: function(dest) {
+ _gotoDest(dest) {
switch (dest.type) {
case EvDocument.LinkDestType.PAGE:
case EvDocument.LinkDestType.XYZ:
@@ -120,9 +118,9 @@ var PlacesDialog = new Lang.Class({
this._model.set_page_by_label(dest.page_label);
break;
}
- },
+ }
- _addPage: function(widget) {
+ _addPage(widget) {
widget.document_model = this._model;
this._stack.add_titled(widget, widget.name, widget.name);
}
diff --git a/src/presentation.js b/src/presentation.js
index 5f0b455a..f1577b64 100644
--- a/src/presentation.js
+++ b/src/presentation.js
@@ -21,6 +21,7 @@ const EvView = imports.gi.EvinceView;
const GnomeDesktop = imports.gi.GnomeDesktop;
const GdPrivate = imports.gi.GdPrivate;
const Gdk = imports.gi.Gdk;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
@@ -28,16 +29,13 @@ const Lang = imports.lang;
const Application = imports.application;
-var PresentationWindow = new Lang.Class({
- Name: 'PresentationWindow',
- Extends: Gtk.Window,
-
- _init: function(model) {
+var PresentationWindow = GObject.registerClass(class PresentationWindow extends Gtk.Window {
+ _init(model) {
this._model = model;
this._inhibitId = 0;
let toplevel = Application.application.get_windows()[0];
- this.parent({ type: Gtk.WindowType.TOPLEVEL,
+ super._init({ type: Gtk.WindowType.TOPLEVEL,
transient_for: toplevel,
destroy_with_parent: true,
title: _("Presentation"),
@@ -51,28 +49,28 @@ var PresentationWindow = new Lang.Class({
this._createView();
this.fullscreen();
this.show_all();
- },
+ }
- _onPageChanged: function() {
+ _onPageChanged() {
this.view.current_page = this._model.page;
- },
+ }
- _onPresentationPageChanged: function() {
+ _onPresentationPageChanged() {
this._model.page = this.view.current_page;
- },
+ }
- _onKeyPressEvent: function(widget, event) {
+ _onKeyPressEvent(widget, event) {
let keyval = event.get_keyval()[1];
if (keyval == Gdk.KEY_Escape)
this.close();
- },
+ }
- setOutput: function(output) {
+ setOutput(output) {
let [x, y, width, height] = output.get_geometry();
this.move(x, y);
- },
+ }
- _createView: function() {
+ _createView() {
let doc = this._model.get_document();
let inverted = this._model.inverted_colors;
let page = this._model.page;
@@ -88,20 +86,20 @@ var PresentationWindow = new Lang.Class({
this.view.show();
this._inhibitIdle();
- },
+ }
- close: function() {
+ close() {
this._uninhibitIdle();
this.destroy();
- },
+ }
- _inhibitIdle: function() {
+ _inhibitIdle() {
this._inhibitId = Application.application.inhibit(null,
Gtk.ApplicationInhibitFlags.IDLE,
_("Running in presentation mode"));
- },
+ }
- _uninhibitIdle: function() {
+ _uninhibitIdle() {
if (this._inhibitId == 0)
return;
@@ -110,18 +108,16 @@ var PresentationWindow = new Lang.Class({
}
});
-var PresentationOutputChooser = new Lang.Class({
- Name: 'PresentationOutputChooser',
- Extends: Gtk.Dialog,
+var PresentationOutputChooser = GObject.registerClass({
Signals: {
'output-activated': {
param_types: [GnomeDesktop.RROutputInfo.$gtype]
}
- },
-
- _init: function(outputs) {
+ }
+}, class PresentationOutputChooser extends Gtk.Dialog {
+ _init(outputs) {
let toplevel = Application.application.get_windows()[0];
- this.parent({ resizable: false,
+ super._init({ resizable: false,
modal: true,
transient_for: toplevel,
destroy_with_parent: true,
@@ -136,9 +132,9 @@ var PresentationOutputChooser = new Lang.Class({
this._createWindow();
this._populateList();
this.show_all();
- },
+ }
- _populateList: function() {
+ _populateList() {
let sizeGroup = new Gtk.SizeGroup({ mode: Gtk.SizeGroupMode.HORIZONTAL });
for (let i = 0; i < this._outputs.list.length; i++) {
@@ -181,9 +177,9 @@ var PresentationOutputChooser = new Lang.Class({
if (!output.is_active())
row.sensitive = false;
}
- },
+ }
- _onActivated: function(box, row) {
+ _onActivated(box, row) {
let output = row.get_child().output;
if (!output.is_active())
return;
@@ -191,13 +187,13 @@ var PresentationOutputChooser = new Lang.Class({
this.output = output;
this.emit('output-activated', this.output);
this.close();
- },
+ }
- close: function() {
+ close() {
this.destroy();
- },
+ }
- _createWindow: function() {
+ _createWindow() {
this.connect('response', Lang.bind(this,
function(widget, response) {
this.emit('output-activated', null);
@@ -228,10 +224,8 @@ var PresentationOutputChooser = new Lang.Class({
}
});
-var PresentationOutputs = new Lang.Class({
- Name: 'PresentationOutputs',
-
- _init: function() {
+var PresentationOutputs = class PresentationOutputs {
+ constructor() {
this.list = [];
let gdkscreen = Gdk.Screen.get_default();
@@ -243,13 +237,13 @@ var PresentationOutputs = new Lang.Class({
this._infos = this._config.get_outputs();
this.load();
- },
+ }
- _onScreenChanged: function() {
+ _onScreenChanged() {
this.load();
- },
+ }
- load: function() {
+ load() {
this.list = [];
for (let idx in this._infos) {
let info = this._infos[idx];
@@ -262,4 +256,4 @@ var PresentationOutputs = new Lang.Class({
this.list.push(info);
}
}
-});
+}
diff --git a/src/preview.js b/src/preview.js
index dd3766d3..3910e078 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -2,6 +2,7 @@ const GdPrivate = imports.gi.GdPrivate;
const Gio = imports.gi.Gio;
const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
@@ -19,11 +20,8 @@ const Utils = imports.utils;
const _ICON_SIZE = 32;
const _PDF_LOADER_TIMEOUT = 400;
-var Preview = new Lang.Class({
- Name: 'Preview',
- Extends: Gtk.Stack,
-
- _init: function(overlay, mainWindow) {
+var Preview = GObject.registerClass(class Preview extends Gtk.Stack {
+ _init(overlay, mainWindow) {
this._lastSearch = '';
this._loadShowId = 0;
this._controlsFlipId = 0;
@@ -33,7 +31,7 @@ var Preview = new Lang.Class({
this.overlay = overlay;
this.mainWindow = mainWindow;
- this.parent({ homogeneous: true,
+ super._init({ homogeneous: true,
transition_type: Gtk.StackTransitionType.CROSSFADE });
this.actionGroup = this._createActionGroup();
@@ -112,9 +110,9 @@ var Preview = new Lang.Class({
this._nightModeId = 0;
}
}));
- },
+ }
- _getDefaultActions: function() {
+ _getDefaultActions() {
let backAccels = ['Back'];
if (this.get_direction() == Gtk.TextDirection.LTR)
backAccels.push('<Alt>Left');
@@ -140,9 +138,9 @@ var Preview = new Lang.Class({
callback: Lang.bind(this, this.goBack),
accels: backAccels }
];
- },
+ }
- _properties: function() {
+ _properties() {
let doc = Application.documentManager.getActiveItem();
if (!doc)
return;
@@ -151,19 +149,19 @@ var Preview = new Lang.Class({
dialog.connect('response', Lang.bind(this, function(widget, response) {
widget.destroy();
}));
- },
+ }
- _openCurrent: function() {
+ _openCurrent() {
let doc = Application.documentManager.getActiveItem();
if (doc)
doc.open(this.mainWindow, Gtk.get_current_event_time());
- },
+ }
- _updateNightMode: function() {
+ _updateNightMode() {
this.nightMode = Application.settings.get_boolean('night-mode');
- },
+ }
- _onFullscreenChanged: function(action) {
+ _onFullscreenChanged(action) {
let fullscreen = action.state.get_boolean();
this.toolbar.visible = !fullscreen;
@@ -188,15 +186,15 @@ var Preview = new Lang.Class({
}
this._syncControlsVisible();
- },
+ }
- getFullscreenToolbar: function() {
+ getFullscreenToolbar() {
return this._fsToolbar;
- },
+ }
get controlsVisible() {
return this._controlsVisible;
- },
+ }
set controlsVisible(visible) {
// reset any pending timeout, as we're about to change controls state
@@ -207,17 +205,17 @@ var Preview = new Lang.Class({
this._controlsVisible = visible;
this._syncControlsVisible();
- },
+ }
- _flipControlsTimeout: function() {
+ _flipControlsTimeout() {
this._controlsFlipId = 0;
let visible = this.controlsVisible;
this.controlsVisible = !visible;
return false;
- },
+ }
- queueControlsFlip: function() {
+ queueControlsFlip() {
if (this._controlsFlipId)
return;
@@ -225,16 +223,16 @@ var Preview = new Lang.Class({
let doubleClick = settings.gtk_double_click_time;
this._controlsFlipId = Mainloop.timeout_add(doubleClick, Lang.bind(this,
this._flipControlsTimeout));
- },
+ }
- cancelControlsFlip: function() {
+ cancelControlsFlip() {
if (this._controlsFlipId != 0) {
Mainloop.source_remove(this._controlsFlipId);
this._controlsFlipId = 0;
}
- },
+ }
- _syncControlsVisible: function() {
+ _syncControlsVisible() {
if (this._controlsVisible) {
if (this._fsToolbar)
this._fsToolbar.reveal();
@@ -242,9 +240,9 @@ var Preview = new Lang.Class({
if (this._fsToolbar)
this._fsToolbar.conceal();
}
- },
+ }
- _createActionGroup: function() {
+ _createActionGroup() {
let actions = this.createActions().concat(this._getDefaultActions());
let actionGroup = new Gio.SimpleActionGroup();
Utils.populateActionGroup(actionGroup, actions, 'view');
@@ -257,47 +255,47 @@ var Preview = new Lang.Class({
}
return actionGroup;
- },
+ }
- createActions: function() {
+ createActions() {
return [];
- },
+ }
- createNavControls: function() {
+ createNavControls() {
return new PreviewNavControls(this, this.overlay);
- },
+ }
- activateResult: function() {
+ activateResult() {
this.findNext();
- },
+ }
- createFullscreenToolbar: function() {
+ createFullscreenToolbar() {
return new PreviewFullscreenToolbar(this);
- },
+ }
- createToolbar: function() {
+ createToolbar() {
return new PreviewToolbar(this);
- },
+ }
- createView: function() {
+ createView() {
throw(new Error('Not implemented'));
- },
+ }
- createContextMenu: function() {
+ createContextMenu() {
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Documents/ui/preview-context-menu.ui');
let model = builder.get_object('preview-context-menu');
return Gtk.Menu.new_from_model(model);
- },
+ }
- _clearLoadTimer: function() {
+ _clearLoadTimer() {
if (this._loadShowId != 0) {
Mainloop.source_remove(this._loadShowId);
this._loadShowId = 0;
}
- },
+ }
- onPasswordNeeded: function(manager, doc) {
+ onPasswordNeeded(manager, doc) {
this._clearLoadTimer();
this._spinner.stop();
@@ -307,9 +305,9 @@ var Preview = new Lang.Class({
if (response == Gtk.ResponseType.CANCEL || response == Gtk.ResponseType.DELETE_EVENT)
Application.documentManager.setActiveItem(null);
}));
- },
+ }
- onLoadStarted: function(manager, doc) {
+ onLoadStarted(manager, doc) {
this._clearLoadTimer();
this._loadShowId = Mainloop.timeout_add(_PDF_LOADER_TIMEOUT, Lang.bind(this, function() {
this._loadShowId = 0;
@@ -318,95 +316,92 @@ var Preview = new Lang.Class({
this._spinner.start();
return false;
}));
- },
+ }
- onLoadFinished: function(manager, doc) {
+ onLoadFinished(manager, doc) {
this._clearLoadTimer();
this._spinner.stop();
this.set_visible_child_name('view');
this.getAction('open-current').enabled = (doc.defaultAppName != null);
this._updateNightMode();
- },
+ }
- onLoadError: function(manager, doc, message, exception) {
+ onLoadError(manager, doc, message, exception) {
this._clearLoadTimer();
this._spinner.stop();
this._errorBox.update(message, exception.message);
this.set_visible_child_name('error');
- },
+ }
- getAction: function(name) {
+ getAction(name) {
return this.actionGroup.lookup_action(name);
- },
+ }
- goBack: function() {
+ goBack() {
Application.documentManager.setActiveItem(null);
Application.modeController.goBack();
- },
+ }
- goPrev: function() {
+ goPrev() {
throw (new Error('Not implemented'));
- },
+ }
- goNext: function() {
+ goNext() {
throw (new Error('Not implemented'));
- },
+ }
get hasPages() {
return false;
- },
+ }
get page() {
return 0;
- },
+ }
get numPages() {
return 0;
- },
+ }
- search: function(str) {
+ search(str) {
this._lastSearch = str;
- },
+ }
get lastSearch() {
return this._lastSearch;
- },
+ }
get fullscreen() {
if (!this.canFullscreen)
return false;
return this.getAction('fullscreen').state.get_boolean();
- },
+ }
get canFullscreen() {
return false;
- },
+ }
set nightMode(v) {
// do nothing
- },
+ }
- findPrev: function() {
+ findPrev() {
throw (new Error('Not implemented'));
- },
+ }
- findNext: function() {
+ findNext() {
throw (new Error('Not implemented'));
}
});
-var PreviewToolbar = new Lang.Class({
- Name: 'PreviewToolbar',
- Extends: MainToolbar.MainToolbar,
-
- _init: function(preview) {
+var PreviewToolbar = GObject.registerClass(class PreviewToolbar extends MainToolbar.MainToolbar {
+ _init(preview) {
this._fsStateId = 0;
this.preview = preview;
- this.parent();
+ super._init();
this.toolbar.set_show_close_button(true);
// back button, on the left of the toolbar
@@ -425,9 +420,9 @@ var PreviewToolbar = new Lang.Class({
if (this._fsStateId > 0)
this.preview.getAction('fullscreen').disconnect(this._fsStateId);
}));
- },
+ }
- _getPreviewMenu: function() {
+ _getPreviewMenu() {
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Documents/ui/preview-menu.ui');
let menu = builder.get_object('preview-menu');
@@ -440,18 +435,18 @@ var PreviewToolbar = new Lang.Class({
}
return menu;
- },
+ }
- _addNightmodeButton: function() {
+ _addNightmodeButton() {
let nightmodeButton = new Gtk.ToggleButton({ image: new Gtk.Image ({ icon_name:
'display-brightness-symbolic' }),
tooltip_text: _("Night Mode"),
action_name: 'app.night-mode',
visible: true });
this.toolbar.pack_end(nightmodeButton);
return nightmodeButton;
- },
+ }
- _addFullscreenButton: function() {
+ _addFullscreenButton() {
this._fullscreenButton = new Gtk.Button({ image: new Gtk.Image ({ icon_name:
'view-fullscreen-symbolic' }),
tooltip_text: _("Fullscreen"),
action_name: 'view.fullscreen',
@@ -461,9 +456,9 @@ var PreviewToolbar = new Lang.Class({
let action = this.preview.getAction('fullscreen');
this._fsStateId = action.connect('notify::state', Lang.bind(this, this._fullscreenStateChanged));
this._fullscreenStateChanged();
- },
+ }
- _fullscreenStateChanged: function() {
+ _fullscreenStateChanged() {
let action = this.preview.getAction('fullscreen');
let fullscreen = action.state.get_boolean();
@@ -471,13 +466,13 @@ var PreviewToolbar = new Lang.Class({
this._fullscreenButton.image.icon_name = 'view-restore-symbolic';
else
this._fullscreenButton.image.icon_name = 'view-fullscreen-symbolic';
- },
+ }
- createSearchbar: function() {
+ createSearchbar() {
return new PreviewSearchbar(this.preview);
- },
+ }
- updateTitle: function() {
+ updateTitle() {
let primary = null;
let doc = Application.documentManager.getActiveItem();
@@ -488,15 +483,13 @@ var PreviewToolbar = new Lang.Class({
}
});
-const PreviewFullscreenToolbar = new Lang.Class({
- Name: 'PreviewFullscreenToolbar',
- Extends: Gtk.Revealer,
+const PreviewFullscreenToolbar = GObject.registerClass({
Signals: {
'show-controls': {}
- },
-
- _init: function(preview) {
- this.parent({ valign: Gtk.Align.START });
+ }
+}, class PreviewFullscreenToolbar extends Gtk.Revealer {
+ _init(preview) {
+ super._init({ valign: Gtk.Align.START });
this.toolbar = preview.createToolbar();
@@ -524,17 +517,17 @@ const PreviewFullscreenToolbar = new Lang.Class({
preview.actionGroup.disconnect(signalId);
});
}));
- },
+ }
- handleEvent: function(event) {
+ handleEvent(event) {
this.toolbar.handleEvent(event);
- },
+ }
- reveal: function() {
+ reveal() {
this.set_reveal_child(true);
- },
+ }
- conceal: function() {
+ conceal() {
this.set_reveal_child(false);
this.toolbar.preview.getAction('find').change_state(GLib.Variant.new('b', false));
}
@@ -543,10 +536,8 @@ const PreviewFullscreenToolbar = new Lang.Class({
const _AUTO_HIDE_TIMEOUT = 2;
var PREVIEW_NAVBAR_MARGIN = 30;
-var PreviewNavControls = new Lang.Class({
- Name: 'PreviewNavControls',
-
- _init: function(preview, overlay) {
+var PreviewNavControls = class PreviewNavControls {
+ constructor(preview, overlay) {
this._barRevealer = null;
this.preview = preview;
this._overlay = overlay;
@@ -615,32 +606,32 @@ var PreviewNavControls = new Lang.Class({
widget: this.preview.view });
this._tapGesture.connect('released', Lang.bind(this, this._onMultiPressReleased));
this._tapGesture.connect('stopped', Lang.bind(this, this._onMultiPressStopped));
- },
+ }
- createBarWidget: function() {
+ createBarWidget() {
return null;
- },
+ }
- _onEnterNotify: function() {
+ _onEnterNotify() {
this._unqueueAutoHide();
return false;
- },
+ }
- _onLeaveNotify: function() {
+ _onLeaveNotify() {
this._queueAutoHide();
return false;
- },
+ }
- _motionTimeout: function() {
+ _motionTimeout() {
this._motionId = 0;
this._visibleInternal = true;
this._updateVisibility();
if (this.barWidget && !this.barWidget.hover)
this._queueAutoHide();
return false;
- },
+ }
- _onMotion: function(widget, event) {
+ _onMotion(widget, event) {
if (this._motionId != 0)
return false;
@@ -650,48 +641,48 @@ var PreviewNavControls = new Lang.Class({
this._motionId = Mainloop.idle_add(Lang.bind(this, this._motionTimeout));
return false;
- },
+ }
- _onMultiPressReleased: function() {
+ _onMultiPressReleased() {
this._tapGesture.set_state(Gtk.EventSequenceState.CLAIMED);
this._visibleInternal = !this._visibleInternal;
this._unqueueAutoHide();
this._updateVisibility();
- },
+ }
- _onMultiPressStopped: function() {
+ _onMultiPressStopped() {
this._tapGesture.set_state(Gtk.EventSequenceState.DENIED);
- },
+ }
- _onPrevClicked: function() {
+ _onPrevClicked() {
this.preview.goPrev();
- },
+ }
- _onNextClicked: function() {
+ _onNextClicked() {
this.preview.goNext();
- },
+ }
- _autoHide: function() {
+ _autoHide() {
this._autoHideId = 0;
this._visibleInternal = false;
this._updateVisibility();
return false;
- },
+ }
- _unqueueAutoHide: function() {
+ _unqueueAutoHide() {
if (this._autoHideId == 0)
return;
Mainloop.source_remove(this._autoHideId);
this._autoHideId = 0;
- },
+ }
- _queueAutoHide: function() {
+ _queueAutoHide() {
this._unqueueAutoHide();
this._autoHideId = Mainloop.timeout_add_seconds(_AUTO_HIDE_TIMEOUT, Lang.bind(this, this._autoHide));
- },
+ }
- _updateVisibility: function() {
+ _updateVisibility() {
let currentPage = this.preview.page;
let numPages = this.preview.numPages;
@@ -708,46 +699,43 @@ var PreviewNavControls = new Lang.Class({
this._prevRevealer.reveal_child = currentPage > 0;
this._nextRevealer.reveal_child = numPages > currentPage + 1;
- },
+ }
- show: function() {
+ show() {
this._visible = true;
this._visibleInternal = true;
this._updateVisibility();
this._queueAutoHide();
- },
+ }
- hide: function() {
+ hide() {
this._visible = false;
this._visibleInternal = false;
this._updateVisibility();
- },
+ }
- destroy: function() {
+ destroy() {
if (this._barRevealer)
this._barRevealer.destroy();
this._prevRevealer.destroy();
this._nextRevealer.destroy();
this._tapGesture = null;
}
-});
-
-var PreviewSearchbar = new Lang.Class({
- Name: 'PreviewSearchbar',
- Extends: Searchbar.Searchbar,
+}
- _init: function(preview) {
+var PreviewSearchbar = GObject.registerClass(class PreviewSearchbar extends Searchbar.Searchbar {
+ _init(preview) {
this.preview = preview;
- this.parent();
+ super._init();
this.connect('notify::search-mode-enabled', Lang.bind(this, function() {
let action = this.preview.getAction('find');
action.change_state(GLib.Variant.new('b', this.search_mode_enabled));
}));
- },
+ }
- createSearchWidget: function() {
+ createSearchWidget() {
let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
halign: Gtk.Align.CENTER});
box.get_style_context().add_class('linked');
@@ -771,14 +759,14 @@ var PreviewSearchbar = new Lang.Class({
box.add(this._next);
return box;
- },
+ }
- entryChanged: function() {
+ entryChanged() {
this.preview.search(this.searchEntry.get_text());
- },
+ }
- reveal: function() {
- this.parent();
+ reveal() {
+ super.reveal();
if (!this.searchEntry.get_text()) {
this.searchEntry.set_text(this.preview.lastSearch);
@@ -786,11 +774,11 @@ var PreviewSearchbar = new Lang.Class({
}
this.preview.search(this.searchEntry.get_text());
- },
+ }
- conceal: function() {
+ conceal() {
this.searchChangeBlocked = true;
- this.parent();
+ super.conceal();
this.searchChangeBlocked = false;
}
});
diff --git a/src/properties.js b/src/properties.js
index 88a52f18..319f94cf 100644
--- a/src/properties.js
+++ b/src/properties.js
@@ -21,6 +21,7 @@
*/
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango;
const _ = imports.gettext.gettext;
@@ -34,11 +35,8 @@ const Lang = imports.lang;
const _TITLE_ENTRY_TIMEOUT = 200;
-var PropertiesDialog = new Lang.Class({
- Name: 'PropertiesDialog',
- Extends: Gtk.Dialog,
-
- _init: function(urn) {
+var PropertiesDialog = GObject.registerClass(class PropertiesDialog extends Gtk.Dialog {
+ _init(urn) {
let doc = Application.documentManager.getItemById(urn);
let dateModified = GLib.DateTime.new_from_unix_local(doc.mtime);
@@ -51,7 +49,7 @@ var PropertiesDialog = new Lang.Class({
}
let toplevel = Application.application.get_windows()[0];
- this.parent({ resizable: false,
+ super._init({ resizable: false,
transient_for: toplevel,
modal: true,
destroy_with_parent: true,
diff --git a/src/query.js b/src/query.js
index d296e718..0dcc75d5 100644
--- a/src/query.js
+++ b/src/query.js
@@ -51,19 +51,17 @@ var QueryFlags = {
var LOCAL_DOCUMENTS_COLLECTIONS_IDENTIFIER = 'gd:collection:local:';
-var QueryBuilder = new Lang.Class({
- Name: 'QueryBuilder',
-
- _init: function(context) {
+var QueryBuilder = class QueryBuilder {
+ constructor(context) {
this._context = context;
- },
+ }
- _createQuery: function(sparql) {
+ _createQuery(sparql) {
return { sparql: sparql,
activeSource: this._context.sourceManager.getActiveItem() };
- },
+ }
- _buildFilterString: function(currentType, flags, isFtsEnabled) {
+ _buildFilterString(currentType, flags, isFtsEnabled) {
let filters = [];
if (!isFtsEnabled)
@@ -75,17 +73,17 @@ var QueryBuilder = new Lang.Class({
}
return 'FILTER (' + filters.join(' && ') + ')';
- },
+ }
- _buildOptional: function() {
+ _buildOptional() {
let sparql =
'OPTIONAL { ?urn nco:creator ?creator . } ' +
'OPTIONAL { ?urn nco:publisher ?publisher . } ';
return sparql;
- },
+ }
- _addWhereClauses: function(partsList, global, flags, searchTypes, ftsQuery) {
+ _addWhereClauses(partsList, global, flags, searchTypes, ftsQuery) {
// build an array of WHERE clauses; each clause maps to one
// type of resource we're looking for.
searchTypes.forEach(Lang.bind(this,
@@ -103,9 +101,9 @@ var QueryBuilder = new Lang.Class({
part += ' }';
partsList.push(part);
}));
- },
+ }
- _buildWhere: function(global, flags) {
+ _buildWhere(global, flags) {
let whereSparql = 'WHERE { ';
let whereParts = [];
let searchTypes = [];
@@ -142,9 +140,9 @@ var QueryBuilder = new Lang.Class({
whereSparql += ' }';
return whereSparql;
- },
+ }
- _buildQueryInternal: function(global, flags, offsetController, sortBy) {
+ _buildQueryInternal(global, flags, offsetController, sortBy) {
let whereSparql = this._buildWhere(global, flags);
let tailSparql = '';
@@ -194,28 +192,28 @@ var QueryBuilder = new Lang.Class({
whereSparql + tailSparql;
return sparql;
- },
+ }
- buildSingleQuery: function(flags, resource) {
+ buildSingleQuery(flags, resource) {
let sparql = this._buildQueryInternal(false, flags, null);
sparql = sparql.replace(/\?urn/g, '<' + resource + '>');
return this._createQuery(sparql);
- },
+ }
- buildGlobalQuery: function(flags, offsetController, sortBy) {
+ buildGlobalQuery(flags, offsetController, sortBy) {
return this._createQuery(this._buildQueryInternal(true, flags, offsetController, sortBy));
- },
+ }
- buildCountQuery: function(flags) {
+ buildCountQuery(flags) {
let sparql = 'SELECT DISTINCT COUNT(?urn) ' +
this._buildWhere(true, flags);
return this._createQuery(sparql);
- },
+ }
// queries for all the items which are part of the given collection
- buildCollectionIconQuery: function(resource) {
+ buildCollectionIconQuery(resource) {
let sparql =
('SELECT ' +
'?urn ' +
@@ -225,10 +223,10 @@ var QueryBuilder = new Lang.Class({
'LIMIT 4').replace(/\?collUrn/, '<' + resource + '>');
return this._createQuery(sparql);
- },
+ }
// queries for all the collections the given item is part of
- buildFetchCollectionsQuery: function(resource) {
+ buildFetchCollectionsQuery(resource) {
let sparql =
('SELECT ' +
'?urn ' +
@@ -236,25 +234,25 @@ var QueryBuilder = new Lang.Class({
).replace(/\?docUrn/, '<' + resource + '>');
return this._createQuery(sparql);
- },
+ }
// adds or removes the given item to the given collection
- buildSetCollectionQuery: function(itemUrn, collectionUrn, setting) {
+ buildSetCollectionQuery(itemUrn, collectionUrn, setting) {
let sparql = ('%s { <%s> nie:isPartOf <%s> }'
).format((setting ? 'INSERT' : 'DELETE'), itemUrn, collectionUrn);
return this._createQuery(sparql);
- },
+ }
// bumps the mtime to current time for the given resource
- buildUpdateMtimeQuery: function(resource) {
+ buildUpdateMtimeQuery(resource) {
let time = GdPrivate.iso8601_from_timestamp(GLib.get_real_time() / GLib.USEC_PER_SEC);
let sparql = ('INSERT OR REPLACE { <%s> nie:contentLastModified \"%s\" }'
).format(resource, time);
return this._createQuery(sparql);
- },
+ }
- buildCreateCollectionQuery: function(name) {
+ buildCreateCollectionQuery(name) {
let time = GdPrivate.iso8601_from_timestamp(GLib.get_real_time() / GLib.USEC_PER_SEC);
let sparql = ('INSERT { _:res a nfo:DataContainer ; a nie:DataObject ; ' +
'nie:contentLastModified \"' + time + '\" ; ' +
@@ -262,11 +260,11 @@ var QueryBuilder = new Lang.Class({
'nao:identifier \"' + LOCAL_DOCUMENTS_COLLECTIONS_IDENTIFIER + name + '\" }');
return this._createQuery(sparql);
- },
+ }
- buildDeleteResourceQuery: function(resource) {
+ buildDeleteResourceQuery(resource) {
let sparql = ('DELETE { <%s> a rdfs:Resource }').format(resource);
return this._createQuery(sparql);
}
-});
+}
diff --git a/src/search.js b/src/search.js
index 281bb4cf..5bc461a6 100644
--- a/src/search.js
+++ b/src/search.js
@@ -42,62 +42,56 @@ function initSearch(context) {
context.queryBuilder = new Query.QueryBuilder(context);
};
-const SearchState = new Lang.Class({
- Name: 'SearchState',
-
- _init: function(searchMatch, searchType, source, str) {
+const SearchState = class SearchState {
+ constructor(searchMatch, searchType, source, str) {
this.searchMatch = searchMatch;
this.searchType = searchType;
this.source = source;
this.str = str;
}
-});
-
-const SearchController = new Lang.Class({
- Name: 'SearchController',
+}
- _init: function() {
+const SearchController = class SearchController {
+ constructor() {
this._string = '';
- },
+ }
- setString: function(string) {
+ setString(string) {
if (this._string == string)
return;
this._string = string;
this.emit('search-string-changed', this._string);
- },
+ }
- getString: function() {
+ getString() {
return this._string;
- },
+ }
- getTerms: function() {
+ getTerms() {
let escapedStr = Tracker.sparql_escape_string(this._string);
let [tokens, ] = GLib.str_tokenize_and_fold(escapedStr, null);
return tokens;
}
-});
+}
Signals.addSignalMethods(SearchController.prototype);
-const SearchType = new Lang.Class({
- Name: 'SearchType',
-
- _init: function(params) {
+const SearchType = class SearchType {
+ constructor(params) {
this.id = params.id;
this.name = params.name;
this._filter = (params.filter) ? (params.filter) : '(true)';
this._where = (params.where) ? (params.where) : '';
- },
+ }
- getFilter: function() {
+ getFilter() {
return this._filter;
- },
+ }
- getWhere: function() {
+ getWhere() {
return this._where;
}
-});
+}
var SearchTypeStock = {
ALL: 'all',
@@ -108,14 +102,11 @@ var SearchTypeStock = {
TEXTDOCS: 'textdocs'
};
-const SearchTypeManager = new Lang.Class({
- Name: 'SearchTypeManager',
- Extends: Manager.BaseManager,
-
- _init: function(context) {
+const SearchTypeManager = class SearchTypeManager extends Manager.BaseManager {
+ constructor(context) {
// Translators: "Type" refers to a search filter on the document type
// (PDF, spreadsheet, ...)
- this.parent(C_("Search Filter", "Type"), 'search-type', context);
+ super(C_("Search Filter", "Type"), 'search-type', context);
this.addItem(new SearchType({ id: SearchTypeStock.ALL,
name: _("All") }));
@@ -140,18 +131,18 @@ const SearchTypeManager = new Lang.Class({
where: '?urn rdf:type nfo:PaginatedTextDocument .' }));
this.setActiveItemById(SearchTypeStock.ALL);
- },
+ }
- getCurrentTypes: function() {
+ getCurrentTypes() {
let activeItem = this.getActiveItem();
if (activeItem.id == SearchTypeStock.ALL)
return this.getAllTypes();
return [ activeItem ];
- },
+ }
- getDocumentTypes: function() {
+ getDocumentTypes() {
let types = [];
types.push(this.getItemById(SearchTypeStock.PDF));
@@ -160,9 +151,9 @@ const SearchTypeManager = new Lang.Class({
types.push(this.getItemById(SearchTypeStock.TEXTDOCS));
return types;
- },
+ }
- getAllTypes: function() {
+ getAllTypes() {
let types = [];
this.forEachItem(function(item) {
@@ -172,7 +163,7 @@ const SearchTypeManager = new Lang.Class({
return types;
}
-});
+}
var SearchMatchStock = {
ALL: 'all',
@@ -181,20 +172,18 @@ var SearchMatchStock = {
CONTENT: 'content'
};
-const SearchMatch = new Lang.Class({
- Name: 'SearchMatch',
-
- _init: function(params) {
+const SearchMatch = class SearchMatch {
+ constructor(params) {
this.id = params.id;
this.name = params.name;
this._term = '';
- },
+ }
- setFilterTerm: function(term) {
+ setFilterTerm(term) {
this._term = term;
- },
+ }
- getFilter: function() {
+ getFilter() {
if (this.id == SearchMatchStock.TITLE)
return ('fn:contains ' +
'(tracker:unaccent(tracker:case-fold' +
@@ -217,17 +206,14 @@ const SearchMatch = new Lang.Class({
return '(false)';
return '';
}
-});
+}
-const SearchMatchManager = new Lang.Class({
- Name: 'SearchMatchManager',
- Extends: Manager.BaseManager,
-
- _init: function(context) {
+const SearchMatchManager = class SearchMatchManager extends Manager.BaseManager {
+ constructor(context) {
// Translators: this is a verb that refers to "All", "Title", "Author",
// and "Content" as in "Match All", "Match Title", "Match Author", and
// "Match Content"
- this.parent(_("Match"), 'search-match', context);
+ super(_("Match"), 'search-match', context);
this.addItem(new SearchMatch({ id: SearchMatchStock.ALL,
name: _("All") }));
@@ -242,9 +228,9 @@ const SearchMatchManager = new Lang.Class({
name: C_("Search Filter", "Content") }));
this.setActiveItemById(SearchMatchStock.ALL);
- },
+ }
- getWhere: function() {
+ getWhere() {
let item = this.getActiveItem();
if (item.id != SearchMatchStock.ALL &&
item.id != SearchMatchStock.CONTENT)
@@ -261,9 +247,9 @@ const SearchMatchManager = new Lang.Class({
}
return '?urn fts:match \'%s\' . '.format(ftsterms.join(' '));
- },
+ }
- getFilter: function(flags) {
+ getFilter(flags) {
if ((flags & Query.QueryFlags.SEARCH) == 0)
return '(true)';
@@ -287,7 +273,7 @@ const SearchMatchManager = new Lang.Class({
}
return filters.length ? '( ' + filters.join(' && ') + ')' : '(true)';
}
-});
+}
var SearchSourceStock = {
ALL: 'all',
@@ -297,10 +283,8 @@ var SearchSourceStock = {
const TRACKER_SCHEMA = 'org.freedesktop.Tracker.Miner.Files';
const TRACKER_KEY_RECURSIVE_DIRECTORIES = 'index-recursive-directories';
-const Source = new Lang.Class({
- Name: 'Source',
-
- _init: function(params) {
+const Source = class Source {
+ constructor(params) {
this.id = null;
this.name = null;
this.icon = null;
@@ -318,16 +302,16 @@ const Source = new Lang.Class({
}
this.builtin = params.builtin;
- },
+ }
- _getGettingStartedLocations: function() {
+ _getGettingStartedLocations() {
if (Application.application.gettingStartedLocation)
return Application.application.gettingStartedLocation;
else
return [];
- },
+ }
- _getTrackerLocations: function() {
+ _getTrackerLocations() {
let settings = new Gio.Settings({ schema_id: TRACKER_SCHEMA });
let locations = settings.get_strv(TRACKER_KEY_RECURSIVE_DIRECTORIES);
let files = [];
@@ -355,9 +339,9 @@ const Source = new Lang.Class({
}));
return files;
- },
+ }
- _getBuiltinLocations: function() {
+ _getBuiltinLocations() {
let files = [];
let xdgDirs = [GLib.UserDirectory.DIRECTORY_DESKTOP,
GLib.UserDirectory.DIRECTORY_DOCUMENTS,
@@ -371,9 +355,9 @@ const Source = new Lang.Class({
}));
return files;
- },
+ }
- _buildFilterLocal: function() {
+ _buildFilterLocal() {
let locations = this._getBuiltinLocations();
locations = locations.concat(
this._getTrackerLocations(),
@@ -388,9 +372,9 @@ const Source = new Lang.Class({
filters.push('(fn:starts-with (nao:identifier(?urn), "gd:collection:local:"))');
return '(' + filters.join(' || ') + ')';
- },
+ }
- getFilter: function() {
+ getFilter() {
let filters = [];
if (this.id == SearchSourceStock.LOCAL) {
@@ -403,9 +387,9 @@ const Source = new Lang.Class({
}
return '(' + filters.join(' || ') + ')';
- },
+ }
- _buildFilterResource: function() {
+ _buildFilterResource() {
let filter = '(false)';
if (!this.builtin)
@@ -413,14 +397,11 @@ const Source = new Lang.Class({
return filter;
}
-});
-
-const SourceManager = new Lang.Class({
- Name: 'SourceManager',
- Extends: Manager.BaseManager,
+}
- _init: function(context) {
- this.parent(_("Sources"), 'search-source', context);
+const SourceManager = class SourceManager extends Manager.BaseManager {
+ constructor(context) {
+ super(_("Sources"), 'search-source', context);
let source = new Source({ id: SearchSourceStock.ALL,
// Translators: this refers to documents
@@ -441,9 +422,9 @@ const SourceManager = new Lang.Class({
this._refreshGoaAccounts();
this.setActiveItemById(SearchSourceStock.ALL);
- },
+ }
- _refreshGoaAccounts: function() {
+ _refreshGoaAccounts() {
let newItems = {};
let newSources = new Map();
let accounts = Application.goaClient.get_accounts();
@@ -483,9 +464,9 @@ const SourceManager = new Lang.Class({
});
this.processNewItems(newItems);
- },
+ }
- getFilter: function(flags) {
+ getFilter(flags) {
let item;
if (flags & Query.QueryFlags.SEARCH)
@@ -501,9 +482,9 @@ const SourceManager = new Lang.Class({
filter = item.getFilter();
return filter;
- },
+ }
- getFilterNotLocal: function() {
+ getFilterNotLocal() {
let sources = this.getItems();
let filters = [];
@@ -517,9 +498,9 @@ const SourceManager = new Lang.Class({
filters.push('false');
return '(' + filters.join(' || ') + ')';
- },
+ }
- hasOnlineSources: function() {
+ hasOnlineSources() {
let hasOnline = false;
this.forEachItem(
function(source) {
@@ -528,14 +509,14 @@ const SourceManager = new Lang.Class({
});
return hasOnline;
- },
+ }
- hasProviderType: function(providerType) {
+ hasProviderType(providerType) {
let items = this.getForProviderType(providerType);
return (items.length > 0);
- },
+ }
- getForProviderType: function(providerType) {
+ getForProviderType(providerType) {
let items = [];
this.forEachItem(Lang.bind(this,
function(source) {
@@ -549,26 +530,24 @@ const SourceManager = new Lang.Class({
return items;
}
-});
+}
var OFFSET_STEP = 50;
-const OffsetController = new Lang.Class({
- Name: 'OffsetController',
-
- _init: function() {
+const OffsetController = class OffsetController {
+ constructor() {
this._offset = 0;
this._itemCount = 0;
- },
+ }
// to be called by the view
- increaseOffset: function() {
+ increaseOffset() {
this._offset += OFFSET_STEP;
this.emit('offset-changed', this._offset);
- },
+ }
// to be called by the model
- resetItemCount: function() {
+ resetItemCount() {
let query = this.getQuery();
Application.connectionQueue.add
@@ -594,44 +573,37 @@ const OffsetController = new Lang.Class({
cursor.close();
}));
}));
- },
+ }
- getQuery: function() {
+ getQuery() {
log('Error: OffsetController implementations must override getQuery');
- },
+ }
// to be called by the model
- resetOffset: function() {
+ resetOffset() {
this._offset = 0;
- },
+ }
- getItemCount: function() {
+ getItemCount() {
return this._itemCount;
- },
+ }
- getRemainingDocs: function() {
+ getRemainingDocs() {
return (this._itemCount - (this._offset + OFFSET_STEP));
- },
+ }
- getOffsetStep: function() {
+ getOffsetStep() {
return OFFSET_STEP;
- },
+ }
- getOffset: function() {
+ getOffset() {
return this._offset;
}
-});
+}
Signals.addSignalMethods(OffsetController.prototype);
-var OffsetCollectionsController = new Lang.Class({
- Name: 'OffsetCollectionsController',
- Extends: OffsetController,
-
- _init: function() {
- this.parent();
- },
-
- getQuery: function() {
+var OffsetCollectionsController = class OffsetCollectionsController extends OffsetController {
+ getQuery() {
let activeCollection = Application.documentManager.getActiveCollection();
let flags;
@@ -642,30 +614,16 @@ var OffsetCollectionsController = new Lang.Class({
return Application.queryBuilder.buildCountQuery(flags);
}
-});
-
-var OffsetDocumentsController = new Lang.Class({
- Name: 'OffsetDocumentsController',
- Extends: OffsetController,
-
- _init: function() {
- this.parent();
- },
+}
- getQuery: function() {
+var OffsetDocumentsController = class OffsetDocumentsController extends OffsetController {
+ getQuery() {
return Application.queryBuilder.buildCountQuery(Query.QueryFlags.DOCUMENTS);
}
-});
-
-var OffsetSearchController = new Lang.Class({
- Name: 'OffsetSearchController',
- Extends: OffsetController,
-
- _init: function() {
- this.parent();
- },
+}
- getQuery: function() {
+var OffsetSearchController = class OffsetSearchController extends OffsetController {
+ getQuery() {
return Application.queryBuilder.buildCountQuery(Query.QueryFlags.SEARCH);
}
-});
+}
diff --git a/src/searchbar.js b/src/searchbar.js
index cb338796..45793c3c 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -21,6 +21,7 @@
const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
@@ -28,17 +29,15 @@ const Lang = imports.lang;
const Application = imports.application;
const Manager = imports.manager;
-var Searchbar = new Lang.Class({
- Name: 'Searchbar',
- Extends: Gtk.SearchBar,
+var Searchbar = GObject.registerClass({
Signals: {
'activate-result': {}
- },
-
- _init: function() {
+ }
+}, class Searchbar extends Gtk.SearchBar {
+ _init() {
this.searchChangeBlocked = false;
- this.parent();
+ super._init();
// subclasses will create this.searchEntry
let searchWidget = this.createSearchWidget();
@@ -55,17 +54,17 @@ var Searchbar = new Lang.Class({
}));
this.show_all();
- },
+ }
- createSearchWidget: function() {
+ createSearchWidget() {
log('Error: Searchbar implementations must override createSearchWidget');
- },
+ }
- entryChanged: function() {
+ entryChanged() {
log('Error: Searchbar implementations must override entryChanged');
- },
+ }
- handleEvent: function(event) {
+ handleEvent(event) {
// Skip if the search bar is shown and the focus is elsewhere
if (this.search_mode_enabled && !this.searchEntry.is_focus)
return false;
@@ -80,13 +79,13 @@ var Searchbar = new Lang.Class({
if (retval == Gdk.EVENT_STOP)
this.searchEntry.grab_focus_without_selecting();
return retval;
- },
+ }
- reveal: function() {
+ reveal() {
this.search_mode_enabled = true;
- },
+ }
- conceal: function() {
+ conceal() {
this.search_mode_enabled = false;
// clear all the search properties when hiding the entry
@@ -94,12 +93,9 @@ var Searchbar = new Lang.Class({
}
});
-var Dropdown = new Lang.Class({
- Name: 'Dropdown',
- Extends: Gtk.Popover,
-
- _init: function() {
- this.parent({ position: Gtk.PositionType.BOTTOM });
+var Dropdown = GObject.registerClass(class Dropdown extends Gtk.Popover {
+ _init() {
+ super._init({ position: Gtk.PositionType.BOTTOM });
let grid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
row_homogeneous: true,
diff --git a/src/selections.js b/src/selections.js
index 98f2d961..1a4c1022 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -23,6 +23,7 @@
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango;
const _ = imports.gettext.gettext;
@@ -41,15 +42,13 @@ const Lang = imports.lang;
const Signals = imports.signals;
// fetch all the collections a given item is part of
-const FetchCollectionsJob = new Lang.Class({
- Name: 'FetchCollectionsJob',
-
- _init: function(urn) {
+const FetchCollectionsJob = class FetchCollectionsJob {
+ constructor(urn) {
this._urn = urn;
this._collections = [];
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let query = Application.queryBuilder.buildFetchCollectionsQuery(this._urn);
@@ -65,9 +64,9 @@ const FetchCollectionsJob = new Lang.Class({
this._emitCallback();
}
}));
- },
+ }
- _onCursorNext: function(cursor, res) {
+ _onCursorNext(cursor, res) {
let valid = false;
try {
@@ -87,13 +86,13 @@ const FetchCollectionsJob = new Lang.Class({
this._collections.push(urn);
cursor.next_async(null, Lang.bind(this, this._onCursorNext));
- },
+ }
- _emitCallback: function() {
+ _emitCallback() {
if (this._callback)
this._callback(this._collections);
}
-});
+}
// fetch the state of every collection applicable to the selected items
const OrganizeCollectionState = {
@@ -103,15 +102,13 @@ const OrganizeCollectionState = {
HIDDEN: 1 << 2
};
-const FetchCollectionStateForSelectionJob = new Lang.Class({
- Name: 'FetchCollectionStateForSelectionJob',
-
- _init: function() {
+const FetchCollectionStateForSelectionJob = class FetchCollectionStateForSelectionJob {
+ constructor() {
this._collectionsForItems = {};
this._runningJobs = 0;
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let urns = Application.selectionController.getSelection();
@@ -122,17 +119,17 @@ const FetchCollectionStateForSelectionJob = new Lang.Class({
this._runningJobs++;
job.run(Lang.bind(this, this._jobCollector, urn));
}));
- },
+ }
- _jobCollector: function(collectionsForItem, urn) {
+ _jobCollector(collectionsForItem, urn) {
this._collectionsForItems[urn] = collectionsForItem;
this._runningJobs--;
if (!this._runningJobs)
this._emitCallback();
- },
+ }
- _emitCallback: function() {
+ _emitCallback() {
let collectionState = {};
let collections = Application.documentManager.getCollections();
@@ -188,17 +185,15 @@ const FetchCollectionStateForSelectionJob = new Lang.Class({
if (this._callback)
this._callback(collectionState);
}
-});
+}
// updates the mtime for the given resource to the current system time
-const UpdateMtimeJob = new Lang.Class({
- Name: 'UpdateMtimeJob',
-
- _init: function(urn) {
+const UpdateMtimeJob = class UpdateMtimeJob {
+ constructor(urn) {
this._urn = urn;
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let query = Application.queryBuilder.buildUpdateMtimeQuery(this._urn);
@@ -214,19 +209,17 @@ const UpdateMtimeJob = new Lang.Class({
this._callback();
}));
}
-});
+}
// adds or removes the selected items to the given collection
-const SetCollectionForSelectionJob = new Lang.Class({
- Name: 'SetCollectionForSelectionJob',
-
- _init: function(collectionUrn, setting) {
+const SetCollectionForSelectionJob = class SetCollectionForSelectionJob {
+ constructor(collectionUrn, setting) {
this._collectionUrn = collectionUrn;
this._setting = setting;
this._runningJobs = 0;
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let urns = Application.selectionController.getSelection();
@@ -251,9 +244,9 @@ const SetCollectionForSelectionJob = new Lang.Class({
this._jobCollector();
}));
}));
- },
+ }
- _jobCollector: function() {
+ _jobCollector() {
this._runningJobs--;
if (this._runningJobs == 0) {
@@ -266,18 +259,16 @@ const SetCollectionForSelectionJob = new Lang.Class({
}));
}
}
-});
+}
// creates an (empty) collection with the given name
-const CreateCollectionJob = new Lang.Class({
- Name: 'CreateCollectionJob',
-
- _init: function(name) {
+const CreateCollectionJob = class CreateCollectionJob {
+ constructor(name) {
this._name = name;
this._createdUrn = null;
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let query = Application.queryBuilder.buildCreateCollectionQuery(this._name);
@@ -304,7 +295,7 @@ const CreateCollectionJob = new Lang.Class({
this._callback(this._createdUrn);
}));
}
-});
+}
const CollectionRowViews = {
DEFAULT: 'default-view',
@@ -312,21 +303,18 @@ const CollectionRowViews = {
RENAME: 'rename-view'
};
-const CollectionRow = new Lang.Class({
- Name: "CollectionRow",
- Extends: Gtk.ListBoxRow,
-
- _init: function(collection, collectionState) {
+const CollectionRow = GObject.registerClass(class CollectionRow extends Gtk.ListBoxRow {
+ _init(collection, collectionState) {
this.collection = collection;
this._collectionState = collectionState;
this._timeoutId = 0;
this.views = new Gtk.Stack();
- this.parent();
+ super._init();
this.add(this.views);
this.setDefaultView();
- },
+ }
- _initDefaultView: function() {
+ _initDefaultView() {
let isActive = (this._collectionState & OrganizeCollectionState.ACTIVE);
let isInconsistent = (this._collectionState & OrganizeCollectionState.INCONSISTENT);
@@ -368,9 +356,9 @@ const CollectionRow = new Lang.Class({
grid.add(menuButton);
grid.show_all();
this.views.add_named(grid, CollectionRowViews.DEFAULT);
- },
+ }
- _initDeleteView: function() {
+ _initDeleteView() {
let grid = new Gtk.Grid({ margin: 6, orientation: Gtk.Orientation.HORIZONTAL });
let message = _("ā%sā removed").format(this.collection.name);
let deleteLabel = new Gtk.Label({ label: message,
@@ -390,9 +378,9 @@ const CollectionRow = new Lang.Class({
grid.show_all();
this.views.add_named(grid, CollectionRowViews.DELETE);
- },
+ }
- _initRenameView: function() {
+ _initRenameView() {
this.renameEntry = new Gtk.Entry({ activates_default: true,
expand: true,
text: this.collection.name,
@@ -412,23 +400,23 @@ const CollectionRow = new Lang.Class({
}));
this.renameEntry.show();
this.views.add_named(this.renameEntry, CollectionRowViews.RENAME);
- },
+ }
- _resetTimeout: function() {
+ _resetTimeout() {
if (this._timeoutId != 0) {
Mainloop.source_remove(this._timeoutId);
this._timeoutId = 0;
}
- },
+ }
- applyRename: function() {
+ applyRename() {
let newName = this.renameEntry.get_text();
this.collection.name = newName;
TrackerUtils.setEditedName(newName, this.collection.id, null);
this.checkButton.set_label(newName);
- },
+ }
- conceal: function() {
+ conceal() {
let revealer = new Gtk.Revealer({ reveal_child: true, transition_duration: 500 });
revealer.show();
// inserting revealer between (this) and (this.views)
@@ -438,23 +426,23 @@ const CollectionRow = new Lang.Class({
revealer.connect("notify::child-revealed", Lang.bind(this, this.deleteCollection));
revealer.reveal_child = false;
- },
+ }
- deleteCollection: function() {
+ deleteCollection() {
this._resetTimeout();
Application.documentManager.removeItem(this.collection);
this.collection.trash();
- },
+ }
- setDefaultView: function() {
+ setDefaultView() {
if (!this.views.get_child_by_name(CollectionRowViews.DEFAULT))
this._initDefaultView();
this.get_style_context().remove_class('delete-row');
this.views.set_visible_child_name(CollectionRowViews.DEFAULT);
- },
+ }
- setDeleteView: function() {
+ setDeleteView() {
if (!this.views.get_child_by_name(CollectionRowViews.DELETE))
this._initDeleteView();
@@ -469,9 +457,9 @@ const CollectionRow = new Lang.Class({
this.get_style_context().add_class('delete-row');
this.views.set_visible_child_name(CollectionRowViews.DELETE);
- },
+ }
- setRenameView: function(onTextChanged) {
+ setRenameView(onTextChanged) {
if (!this.views.get_child_by_name(CollectionRowViews.RENAME)) {
this._initRenameView();
this.renameEntry.connect('changed', onTextChanged);
@@ -481,16 +469,13 @@ const CollectionRow = new Lang.Class({
this.views.set_transition_duration(200);
this.renameEntry.set_text(this.collection.name);
this.views.set_visible_child_name(CollectionRowViews.RENAME);
- },
+ }
});
-const CollectionList = new Lang.Class({
- Name: 'CollectionList',
- Extends: Gtk.ListBox,
-
- _init: function() {
- this.parent({ vexpand: false,
+const CollectionList = GObject.registerClass(class CollectionList extends Gtk.ListBox {
+ _init() {
+ super._init({ vexpand: false,
margin: 0,
selection_mode: Gtk.SelectionMode.NONE });
@@ -533,18 +518,18 @@ const CollectionList = new Lang.Class({
// populate the list
let job = new FetchCollectionStateForSelectionJob();
job.run(Lang.bind(this, this._onFetchCollectionStateForSelection));
- },
+ }
- _onCollectionAdded: function(manager, itemAdded) {
+ _onCollectionAdded(manager, itemAdded) {
if (!itemAdded.collection)
return;
let collection = new CollectionRow(itemAdded, OrganizeCollectionState.ACTIVE);
collection.show_all();
this.add(collection);
- },
+ }
- _onCollectionRemoved: function(manager, itemRemoved) {
+ _onCollectionRemoved(manager, itemRemoved) {
if (!itemRemoved.collection)
return;
@@ -555,9 +540,9 @@ const CollectionList = new Lang.Class({
return;
}
}
- },
+ }
- _onFetchCollectionStateForSelection: function(collectionState) {
+ _onFetchCollectionStateForSelection(collectionState) {
for (let idx in collectionState) {
let item = Application.documentManager.getItemById(idx);
@@ -569,14 +554,14 @@ const CollectionList = new Lang.Class({
this.add(collection);
}
- },
+ }
- isEmpty: function() {
+ isEmpty() {
let rows = this.get_children();
return (rows.length == 0);
- },
+ }
- isValidName: function(name) {
+ isValidName(name) {
if (!name || name == '')
return false;
@@ -590,9 +575,7 @@ const CollectionList = new Lang.Class({
}
});
-const OrganizeCollectionDialog = new Lang.Class({
- Name: 'OrganizeCollectionDialog',
- Extends: Gtk.Window,
+const OrganizeCollectionDialog = GObject.registerClass({
Template: 'resource:///org/gnome/Documents/ui/organize-collection-dialog.ui',
InternalChildren: [ 'content',
'viewEmpty',
@@ -607,9 +590,9 @@ const OrganizeCollectionDialog = new Lang.Class({
'headerBar',
'cancelButton',
'doneButton' ],
-
- _init: function(toplevel) {
- this.parent({ transient_for: toplevel });
+}, class OrganizeCollectionDialog extends Gtk.Window {
+ _init(toplevel) {
+ super._init({ transient_for: toplevel });
this._renameMode = false;
@@ -666,9 +649,9 @@ const OrganizeCollectionDialog = new Lang.Class({
this._content.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
return false;
}));
- },
+ }
- _onAddClicked: function() {
+ _onAddClicked() {
let addEntry = this._collectionList.isEmpty() ? this._addEntryEmpty : this._addEntryCollections;
let newText = addEntry.get_text();
let job = new CreateCollectionJob(newText);
@@ -687,9 +670,9 @@ const OrganizeCollectionDialog = new Lang.Class({
} else {
this._scrolledWindowCollections.get_vadjustment().set_value(0);
}
- },
+ }
- _onTextChanged: function(entry) {
+ _onTextChanged(entry) {
let sensitive = this._collectionList.isValidName(entry.get_text());
if (this._renameMode)
this._doneButton.set_sensitive(sensitive);
@@ -697,9 +680,9 @@ const OrganizeCollectionDialog = new Lang.Class({
let addButton = this._collectionList.isEmpty() ? this._addButtonEmpty :
this._addButtonCollections;
addButton.set_sensitive(sensitive);
}
- },
+ }
- _onKeyPressed: function (window, event) {
+ _onKeyPressed (window, event) {
let keyval = event.get_keyval()[1];
if (keyval == Gdk.KEY_Escape) {
if (this._renameMode)
@@ -710,9 +693,9 @@ const OrganizeCollectionDialog = new Lang.Class({
return Gdk.EVENT_STOP;
}
return Gdk.EVENT_PROPAGATE;
- },
+ }
- _renameModeStart: function(action, parameter) {
+ _renameModeStart(action, parameter) {
let collId = parameter.get_string()[0];
this._setRenameMode(true);
@@ -732,9 +715,9 @@ const OrganizeCollectionDialog = new Lang.Class({
row.setRenameView(Lang.bind(this, this._onTextChanged));
}));
- },
+ }
- _renameModeStop: function(rename) {
+ _renameModeStop(rename) {
this._setRenameMode(false);
let rows = this._collectionList.get_children();
@@ -750,9 +733,9 @@ const OrganizeCollectionDialog = new Lang.Class({
row.setDefaultView();
});
- },
+ }
- _onCollectionListChanged: function() {
+ _onCollectionListChanged() {
if (this._collectionList.isEmpty()) {
this._viewSpinner.stop();
this._content.set_visible_child(this._viewEmpty);
@@ -764,9 +747,9 @@ const OrganizeCollectionDialog = new Lang.Class({
this._addEntryCollections.grab_focus();
this._addButtonCollections.grab_default();
}
- },
+ }
- _setRenameMode: function(renameMode) {
+ _setRenameMode(renameMode) {
this._renameMode = renameMode;
if (this._renameMode) {
this._headerBar.set_title(_("Rename"));
@@ -786,17 +769,15 @@ const OrganizeCollectionDialog = new Lang.Class({
}
});
-var SelectionController = new Lang.Class({
- Name: 'SelectionController',
-
- _init: function() {
+var SelectionController = class SelectionController {
+ constructor() {
this._selection = [];
Application.documentManager.connect('item-removed',
Lang.bind(this, this._onDocumentRemoved));
- },
+ }
- _onDocumentRemoved: function(manager, item) {
+ _onDocumentRemoved(manager, item) {
let changed = false;
let filtered = this._selection.filter(Lang.bind(this,
function(value, index) {
@@ -809,9 +790,9 @@ var SelectionController = new Lang.Class({
this._selection = filtered;
this.emit('selection-changed', this._selection);
}
- },
+ }
- setSelection: function(selection) {
+ setSelection(selection) {
if (this._isFrozen)
return;
@@ -821,26 +802,24 @@ var SelectionController = new Lang.Class({
this._selection = selection;
this.emit('selection-changed', this._selection);
- },
+ }
- getSelection: function() {
+ getSelection() {
return this._selection;
- },
+ }
- freezeSelection: function(freeze) {
+ freezeSelection(freeze) {
if (freeze == this._isFrozen)
return;
this._isFrozen = freeze;
}
-});
+}
Signals.addSignalMethods(SelectionController.prototype);
const _SELECTION_TOOLBAR_DEFAULT_WIDTH = 500;
-var SelectionToolbar = new Lang.Class({
- Name: 'SelectionToolbar',
- Extends: Gtk.ActionBar,
+var SelectionToolbar = GObject.registerClass({
Template: 'resource:///org/gnome/Documents/ui/selection-toolbar.ui',
InternalChildren: [ 'toolbarOpen',
'toolbarPrint',
@@ -848,14 +827,15 @@ var SelectionToolbar = new Lang.Class({
'toolbarShare',
'toolbarProperties',
'toolbarCollection' ],
+}, class SelectionToolbar extends Gtk.ActionBar {
- _init: function(overview) {
+ _init(overview) {
this._docToPrint = null;
this._docBeginPrintId = 0;
this._itemListeners = {};
this._insideRefresh = false;
- this.parent();
+ super._init();
this._selectionModeAction = overview.getAction('selection-mode');
@@ -882,38 +862,38 @@ var SelectionToolbar = new Lang.Class({
function() {
this._disconnectDocToPrint();
}));
- },
+ }
- vfunc_hide: function() {
+ vfunc_hide() {
this._disconnectDocToPrint();
- this.parent();
- },
+ super.vfunc_hide();
+ }
- _disconnectDocToPrint: function() {
+ _disconnectDocToPrint() {
if (this._docToPrint != null && this._docBeginPrintId != 0) {
this._docToPrint.disconnect(this._docBeginPrintId);
this._docToPrint = null;
this._docBeginPrintId = 0;
}
- },
+ }
- _updateCollectionsButton: function() {
+ _updateCollectionsButton() {
let windowMode = Application.modeController.getWindowMode();
let activeCollection = Application.documentManager.getActiveCollection();
if (windowMode == WindowMode.WindowMode.COLLECTIONS && !activeCollection)
this._toolbarCollection.hide();
else
this._toolbarCollection.show();
- },
+ }
- _onSelectionChanged: function() {
+ _onSelectionChanged() {
let selection = Application.selectionController.getSelection();
this._setItemListeners(selection);
this._setItemVisibility();
- },
+ }
- _setItemListeners: function(selection) {
+ _setItemListeners(selection) {
for (let idx in this._itemListeners) {
let doc = this._itemListeners[idx];
doc.disconnect(idx);
@@ -926,9 +906,9 @@ var SelectionToolbar = new Lang.Class({
let id = doc.connect('info-updated', Lang.bind(this, this._setItemVisibility));
this._itemListeners[id] = doc;
}));
- },
+ }
- _setItemVisibility: function() {
+ _setItemVisibility() {
let apps = [];
let selection = Application.selectionController.getSelection();
let hasSelection = (selection.length > 0);
@@ -991,9 +971,9 @@ var SelectionToolbar = new Lang.Class({
this._toolbarCollection.set_sensitive(showCollection);
this._insideRefresh = false;
- },
+ }
- _onToolbarCollection: function() {
+ _onToolbarCollection() {
let toplevel = this.get_toplevel();
if (!toplevel.is_toplevel())
throw(new Error('Code should not be reached'));
@@ -1002,9 +982,9 @@ var SelectionToolbar = new Lang.Class({
dialog.connect('destroy', Lang.bind(this, function() {
this._selectionModeAction.change_state(GLib.Variant.new('b', false));
}));
- },
+ }
- _onToolbarOpen: function(widget) {
+ _onToolbarOpen(widget) {
let selection = Application.selectionController.getSelection();
this._selectionModeAction.change_state(GLib.Variant.new('b', false));
@@ -1017,9 +997,9 @@ var SelectionToolbar = new Lang.Class({
doc.open(toplevel, Gtk.get_current_event_time());
}));
- },
+ }
- _onToolbarTrash: function(widget) {
+ _onToolbarTrash(widget) {
let selection = Application.selectionController.getSelection();
let docs = [];
@@ -1038,9 +1018,9 @@ var SelectionToolbar = new Lang.Class({
let deleteNotification = new Notifications.DeleteNotification(docs);
this._selectionModeAction.change_state(GLib.Variant.new('b', false));
- },
+ }
- _onToolbarProperties: function(widget) {
+ _onToolbarProperties(widget) {
let selection = Application.selectionController.getSelection();
let dialog = new Properties.PropertiesDialog(selection[0]);
@@ -1049,9 +1029,9 @@ var SelectionToolbar = new Lang.Class({
dialog.destroy();
this._selectionModeAction.change_state(GLib.Variant.new('b', false));
}));
- },
+ }
- _onToolbarShare: function(widget) {
+ _onToolbarShare(widget) {
let dialog = new Sharing.SharingDialog();
dialog.connect('response', Lang.bind(this,
@@ -1059,9 +1039,9 @@ var SelectionToolbar = new Lang.Class({
dialog.destroy();
this._selectionModeAction.change_state(GLib.Variant.new('b', false));
}));
- },
+ }
- _onToolbarPrint: function(widget) {
+ _onToolbarPrint(widget) {
let selection = Application.selectionController.getSelection();
if (selection.length != 1)
@@ -1076,5 +1056,5 @@ var SelectionToolbar = new Lang.Class({
}));
this._docToPrint.print(this.get_toplevel());
- },
+ }
});
diff --git a/src/sharing.js b/src/sharing.js
index 7f5d0f20..182b8fac 100644
--- a/src/sharing.js
+++ b/src/sharing.js
@@ -68,11 +68,8 @@ const DocumentUpdateType = {
DELETE_SHARE_LINK: 4
};
-var SharingDialog = new Lang.Class({
- Name: 'SharingDialog',
- Extends: Gtk.Dialog,
-
- _init: function() {
+var SharingDialog = GObject.registerClass(class SharingDialog extends Gtk.Dialog {
+ _init() {
let urn = Application.selectionController.getSelection();
this._doc = Application.documentManager.getItemById(urn);
@@ -98,7 +95,7 @@ var SharingDialog = new Lang.Class({
this._changePermissionVisible = false;
let toplevel = Application.application.get_windows()[0];
- this.parent({ resizable: false,
+ super._init({ resizable: false,
transient_for: toplevel,
modal: true,
destroy_with_parent: true,
@@ -237,9 +234,9 @@ var SharingDialog = new Lang.Class({
this.show_all();
this._updatePermissionButtons();
- },
+ }
- _ensureTreeview: function() {
+ _ensureTreeview() {
if (this._model) {
this._model.clear();
return;
@@ -271,9 +268,9 @@ var SharingDialog = new Lang.Class({
if (child)
child.destroy();
this._scrolledWin.add(this._treeView);
- },
+ }
- _onPermissionsButtonClicked: function() {
+ _onPermissionsButtonClicked() {
this._changePermissionVisible = !this._changePermissionVisible;
if (!this._changePermissionVisible) {
this._changeButton.set_sensitive(false);
@@ -281,15 +278,15 @@ var SharingDialog = new Lang.Class({
}
this._updatePermissionButtons();
- },
+ }
- _permissionChangeFinished: function() {
+ _permissionChangeFinished() {
this._changePermissionVisible = false;
this._changeButton.set_sensitive(true);
this._updatePermissionButtons();
- },
+ }
- _updateSettingString: function() {
+ _updateSettingString() {
let primary = '';
let detail = '';
@@ -310,9 +307,9 @@ var SharingDialog = new Lang.Class({
this._setting.label = primary;
this._settingDetail.label = detail;
- },
+ }
- _updatePermissionButtons: function() {
+ _updatePermissionButtons() {
if (this._changePermissionVisible) {
this._changeButton.label = _("Save");
this._setting.hide();
@@ -334,10 +331,10 @@ var SharingDialog = new Lang.Class({
this._privateRadio.hide();
this._publicBox.hide();
}
- },
+ }
// Return a feed containing the acl related to the entry
- _refreshEntryACL: function() {
+ _refreshEntryACL() {
this._entry.get_rules_async(this._service, null, null, Lang.bind(this,
function(entry, result) {
try {
@@ -347,9 +344,9 @@ var SharingDialog = new Lang.Class({
logError(e, 'Error getting ACL Feed');
}
}));
- },
+ }
- _getAccountNames: function() {
+ _getAccountNames() {
let retval = [];
let sources = Application.sourceManager.getForProviderType('google');
@@ -360,10 +357,10 @@ var SharingDialog = new Lang.Class({
}));
return retval;
- },
+ }
// Get the roles, and make a new array containing strings that start with capital letters
- _getUserRoleString: function(role) {
+ _getUserRoleString(role) {
if (role.charAt(0) == 'o')
return _("Owner"); // Owner permission for document user listed in treeview
@@ -374,10 +371,10 @@ var SharingDialog = new Lang.Class({
return _("Can view"); // Reader permission for document user listed in treeview
return '';
- },
+ }
// Get each entry (person) from the feed, and get the scope for each person, and then store the emails
and values in an array
- _getScopeRulesEntry: function() {
+ _getScopeRulesEntry() {
let entries = this._feed.get_entries();
let accountNames = this._getAccountNames();
@@ -436,10 +433,10 @@ var SharingDialog = new Lang.Class({
this._noPermission.show();
this._noPermission.set_text(_("You can ask %s for access").format(ownerId));
}
- },
+ }
// Get the role for the new contact from the combobox
- _getNewContactRule: function() {
+ _getNewContactRule() {
let activeItem = this._comboBoxText.get_active();
let role;
@@ -451,10 +448,10 @@ var SharingDialog = new Lang.Class({
return new GData.AccessRule({ role: role,
scope_type: GData.ACCESS_SCOPE_USER,
scope_value: this._contactEntry.get_text() });
- },
+ }
// Send the new contact and its permissions to Google Docs
- _onAddClicked: function() {
+ _onAddClicked() {
let accessRule = this._getNewContactRule();
let aclLink = this._entry.look_up_link(GData.LINK_ACCESS_CONTROL_LIST);
@@ -474,27 +471,27 @@ var SharingDialog = new Lang.Class({
this._showErrorDialog(_("The document was not updated"));
}
}));
- },
+ }
// Get the scope from the radiobuttons
- _getNewScopeType: function() {
+ _getNewScopeType() {
let scope = GData.ACCESS_SCOPE_USER;
if (this._publicRadio.get_active())
scope = GData.ACCESS_SCOPE_DEFAULT;
return scope;
- },
+ }
// Get the role from the checkbox
- _getNewRole: function() {
+ _getNewRole() {
let role = GData.DOCUMENTS_ACCESS_ROLE_READER;
if (this._pubEditCheck.get_active())
role = GData.DOCUMENTS_ACCESS_ROLE_WRITER;
return role;
- },
+ }
- _insertNewPermission: function(scopeType, role) {
+ _insertNewPermission(scopeType, role) {
let aclLink = this._entry.look_up_link(GData.LINK_ACCESS_CONTROL_LIST);
let accessRule = new GData.AccessRule({ scope_type: scopeType,
role: role });
@@ -512,9 +509,9 @@ var SharingDialog = new Lang.Class({
this._permissionChangeFinished();
}));
- },
+ }
- _sendNewDocumentRule: function() {
+ _sendNewDocumentRule() {
let newScopeType = this._getNewScopeType();
let newRole = this._getNewRole();
let entries = this._feed.get_entries();
@@ -604,15 +601,15 @@ var SharingDialog = new Lang.Class({
}
}));
}
- },
+ }
- _isValidEmail: function() {
+ _isValidEmail() {
let emailString = this._contactEntry.get_text();
// Use Ross Kendell's RegEx to check for valid email address
return
/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test(emailString);
- },
+ }
- _showErrorDialog: function(errorStr) {
+ _showErrorDialog(errorStr) {
let errorDialog = new Gtk.MessageDialog ({ transient_for: this,
modal: true,
destroy_with_parent: true,
diff --git a/src/shellSearchProvider.js b/src/shellSearchProvider.js
index 02bac4e3..f72e78b2 100644
--- a/src/shellSearchProvider.js
+++ b/src/shellSearchProvider.js
@@ -119,17 +119,15 @@ function _createGIcon(cursor) {
return gicon;
}
-const CreateCollectionIconJob = new Lang.Class({
- Name: 'CreateCollectionIconJob',
-
- _init: function(id) {
+const CreateCollectionIconJob = class CreateCollectionIconJob {
+ constructor(id) {
this._id = id;
this._itemIcons = [];
this._itemIds = [];
this._itemJobs = 0;
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
let query = queryBuilder.buildCollectionIconQuery(this._id);
@@ -145,9 +143,9 @@ const CreateCollectionIconJob = new Lang.Class({
this._hasItemIds();
}
}));
- },
+ }
- _createItemIcon: function(cursor) {
+ _createItemIcon(cursor) {
let pixbuf = null;
let icon = _createGIcon(cursor);
@@ -174,9 +172,9 @@ const CreateCollectionIconJob = new Lang.Class({
}
return pixbuf;
- },
+ }
- _onCursorNext: function(cursor, res) {
+ _onCursorNext(cursor, res) {
let valid = false;
try {
@@ -195,9 +193,9 @@ const CreateCollectionIconJob = new Lang.Class({
cursor.close();
this._hasItemIds();
}
- },
+ }
- _hasItemIds: function() {
+ _hasItemIds() {
if (this._itemIds.length == 0) {
this._returnPixbuf();
return;
@@ -215,36 +213,34 @@ const CreateCollectionIconJob = new Lang.Class({
this._itemJobCollector();
}));
}));
- },
+ }
- _itemJobCollector: function() {
+ _itemJobCollector() {
this._itemJobs--;
if (this._itemJobs == 0)
this._returnPixbuf();
- },
+ }
- _returnPixbuf: function() {
+ _returnPixbuf() {
this._callback(GdPrivate.create_collection_icon(_SHELL_SEARCH_ICON_SIZE, this._itemIcons));
}
-});
-
-const FetchMetasJob = new Lang.Class({
- Name: 'FetchMetasJob',
+}
- _init: function(ids) {
+const FetchMetasJob = class FetchMetasJob {
+ constructor(ids) {
this._ids = ids;
this._metas = [];
- },
+ }
- _jobCollector: function() {
+ _jobCollector() {
this._activeJobs--;
if (this._activeJobs == 0)
this._callback(this._metas);
- },
+ }
- _createCollectionPixbuf: function(meta) {
+ _createCollectionPixbuf(meta) {
let job = new CreateCollectionIconJob(meta.id);
job.run(Lang.bind(this,
function(icon) {
@@ -254,9 +250,9 @@ const FetchMetasJob = new Lang.Class({
this._metas.push(meta);
this._jobCollector();
}));
- },
+ }
- run: function(callback) {
+ run(callback) {
this._callback = callback;
this._activeJobs = this._ids.length;
@@ -295,17 +291,15 @@ const FetchMetasJob = new Lang.Class({
}));
}));
}
-});
-
-const FetchIdsJob = new Lang.Class({
- Name: 'FetchIdsJob',
+}
- _init: function(terms) {
+const FetchIdsJob = class FetchIdsJob {
+ constructor(terms) {
this._terms = terms;
this._ids = [];
- },
+ }
- run: function(callback, cancellable) {
+ run(callback, cancellable) {
this._callback = callback;
this._cancellable = cancellable;
searchController.setString(this._terms.join(' '));
@@ -324,9 +318,9 @@ const FetchIdsJob = new Lang.Class({
callback(this._ids);
}
}));
- },
+ }
- _onCursorNext: function(cursor, res) {
+ _onCursorNext(cursor, res) {
let valid = false;
try {
@@ -346,26 +340,24 @@ const FetchIdsJob = new Lang.Class({
this._callback(this._ids);
}
}
-});
-
-var ShellSearchProvider = new Lang.Class({
- Name: 'ShellSearchProvider',
+}
- _init: function() {
+var ShellSearchProvider = class ShellSearchProvider {
+ constructor() {
this._impl = Gio.DBusExportedObject.wrapJSObject(SearchProviderIface, this);
this._cache = {};
this._cancellable = new Gio.Cancellable();
- },
+ }
- export: function(connection) {
+ export(connection) {
return this._impl.export(connection, SEARCH_PROVIDER_PATH);
- },
+ }
- unexport: function(connection) {
+ unexport(connection) {
return this._impl.unexport_from_connection(connection);
- },
+ }
- _returnMetasFromCache: function(ids, invocation) {
+ _returnMetasFromCache(ids, invocation) {
let metas = [];
for (let i = 0; i < ids.length; i++) {
let id = ids[i];
@@ -383,9 +375,9 @@ var ShellSearchProvider = new Lang.Class({
Application.application.release();
invocation.return_value(GLib.Variant.new('(aa{sv})', [ metas ]));
- },
+ }
- GetInitialResultSetAsync: function(params, invocation) {
+ GetInitialResultSetAsync(params, invocation) {
let terms = params[0];
Application.application.hold();
@@ -398,9 +390,9 @@ var ShellSearchProvider = new Lang.Class({
Application.application.release();
invocation.return_value(GLib.Variant.new('(as)', [ ids ]));
}), this._cancellable);
- },
+ }
- GetSubsearchResultSetAsync: function(params, invocation) {
+ GetSubsearchResultSetAsync(params, invocation) {
let [previousResults, terms] = params;
Application.application.hold();
@@ -413,9 +405,9 @@ var ShellSearchProvider = new Lang.Class({
Application.application.release();
invocation.return_value(GLib.Variant.new('(as)', [ ids ]));
}), this._cancellable);
- },
+ }
- GetResultMetasAsync: function(params, invocation) {
+ GetResultMetasAsync(params, invocation) {
let ids = params[0];
Application.application.hold();
@@ -439,14 +431,14 @@ var ShellSearchProvider = new Lang.Class({
} else {
this._returnMetasFromCache(ids, invocation);
}
- },
+ }
- ActivateResult: function(id, terms, timestamp) {
+ ActivateResult(id, terms, timestamp) {
this.emit('activate-result', id, terms, timestamp);
- },
+ }
- LaunchSearch: function(terms, timestamp) {
+ LaunchSearch(terms, timestamp) {
this.emit('launch-search', terms, timestamp);
}
-});
+}
Signals.addSignalMethods(ShellSearchProvider.prototype);
diff --git a/src/trackerController.js b/src/trackerController.js
index e45f3a7f..9aa2cc11 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -37,15 +37,13 @@ const QueryType = {
UPDATE_BLANK: 2
};
-var TrackerConnectionQueue = new Lang.Class({
- Name: 'TrackerConnectionQueue',
-
- _init: function() {
+var TrackerConnectionQueue = class TrackerConnectionQueue {
+ constructor() {
this._queue = [];
this._running = false;
- },
+ }
- add: function(query, cancellable, callback) {
+ add(query, cancellable, callback) {
let params = { query: query,
cancellable: cancellable,
callback: callback,
@@ -53,9 +51,9 @@ var TrackerConnectionQueue = new Lang.Class({
this._queue.push(params);
this._checkQueue();
- },
+ }
- update: function(query, cancellable, callback) {
+ update(query, cancellable, callback) {
let params = { query: query,
cancellable: cancellable,
callback: callback,
@@ -63,9 +61,9 @@ var TrackerConnectionQueue = new Lang.Class({
this._queue.push(params);
this._checkQueue();
- },
+ }
- updateBlank: function(query, cancellable, callback) {
+ updateBlank(query, cancellable, callback) {
let params = { query: query,
cancellable: cancellable,
callback: callback,
@@ -73,9 +71,9 @@ var TrackerConnectionQueue = new Lang.Class({
this._queue.push(params);
this._checkQueue();
- },
+ }
- _checkQueue: function() {
+ _checkQueue() {
if (this._running)
return;
@@ -94,24 +92,22 @@ var TrackerConnectionQueue = new Lang.Class({
else if (params.queryType == QueryType.UPDATE_BLANK)
Application.connection.update_blank_async(params.query, GLib.PRIORITY_DEFAULT,
params.cancellable,
Lang.bind(this, this._queueCollector, params));
- },
+ }
- _queueCollector: function(connection, res, params) {
+ _queueCollector(connection, res, params) {
params.callback(connection, res);
this._running = false;
this._checkQueue();
}
-});
+}
const RefreshFlags = {
NONE: 0,
RESET_OFFSET: 1 << 0
};
-const TrackerController = new Lang.Class({
- Name: 'TrackerController',
-
- _init: function(windowMode) {
+const TrackerController = class TrackerController {
+ constructor(windowMode) {
this._currentQuery = null;
this._cancellable = new Gio.Cancellable();
this._mode = windowMode;
@@ -139,13 +135,13 @@ const TrackerController = new Lang.Class({
Application.settings.connect('changed::sort-by', Lang.bind(this, this._updateSortForSettings));
this._updateSortForSettings();
- },
+ }
- getOffsetController: function() {
+ getOffsetController() {
log('Error: TrackerController implementations must override getOffsetController');
- },
+ }
- _setQueryStatus: function(status) {
+ _setQueryStatus(status) {
if (this._querying == status)
return;
@@ -159,25 +155,25 @@ const TrackerController = new Lang.Class({
this._querying = status;
this.emit('query-status-changed', this._querying);
- },
+ }
- getQuery: function() {
+ getQuery() {
log('Error: TrackerController implementations must override getQuery');
- },
+ }
- getQueryStatus: function() {
+ getQueryStatus() {
return this._querying;
- },
+ }
- _onQueryError: function(exception) {
+ _onQueryError(exception) {
if (exception.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
return;
let message = _("Unable to fetch the list of documents");
this.emit('query-error', message, exception);
- },
+ }
- _onQueryFinished: function(exception) {
+ _onQueryFinished(exception) {
this._setQueryStatus(false);
if (exception)
@@ -189,9 +185,9 @@ const TrackerController = new Lang.Class({
this._queryQueued = false;
this._refreshInternal(this._queryQueuedFlags);
}
- },
+ }
- _onCursorNext: function(cursor, res) {
+ _onCursorNext(cursor, res) {
try {
let valid = cursor.next_finish(res);
@@ -211,9 +207,9 @@ const TrackerController = new Lang.Class({
+ (GLib.get_monotonic_time() - this._lastQueryTime) / 1000000);
Application.documentManager.addDocumentFromCursor(cursor);
cursor.next_async(this._cancellable, Lang.bind(this, this._onCursorNext));
- },
+ }
- _onQueryExecuted: function(object, res) {
+ _onQueryExecuted(object, res) {
try {
Utils.debug('Query Executed: '
+ (GLib.get_monotonic_time() - this._lastQueryTime) / 1000000);
@@ -223,17 +219,17 @@ const TrackerController = new Lang.Class({
} catch (e) {
this._onQueryFinished(e);
}
- },
+ }
- _performCurrentQuery: function() {
+ _performCurrentQuery() {
this._currentQuery = this.getQuery();
this._cancellable.reset();
Application.connectionQueue.add(this._currentQuery.sparql,
this._cancellable, Lang.bind(this, this._onQueryExecuted));
- },
+ }
- _refreshInternal: function(flags) {
+ _refreshInternal(flags) {
if (!this._isStarted)
throw(new Error('!this._isStarted'));
@@ -250,13 +246,13 @@ const TrackerController = new Lang.Class({
this._setQueryStatus(true);
this._performCurrentQuery();
- },
+ }
- refreshForObject: function(_object, _item) {
+ refreshForObject(_object, _item) {
this._refreshInternal(RefreshFlags.RESET_OFFSET);
- },
+ }
- _refreshForSource: function() {
+ _refreshForSource() {
// When a source is added or removed, refresh the model only if
// the current source is All.
// If it was the current source to be removed, we will get an
@@ -266,18 +262,18 @@ const TrackerController = new Lang.Class({
this._refreshInternal(RefreshFlags.NONE);
this._refreshPending = false;
- },
+ }
- _onSourceAddedRemoved: function(manager, item) {
+ _onSourceAddedRemoved(manager, item) {
let mode = Application.modeController.getWindowMode();
if (mode == this._mode)
this._refreshForSource();
else
this._refreshPending = true;
- },
+ }
- _updateSortForSettings: function() {
+ _updateSortForSettings() {
let sortBy = Application.settings.get_enum('sort-by');
if(this.sortBy == sortBy)
@@ -289,24 +285,21 @@ const TrackerController = new Lang.Class({
return;
this._refreshInternal(RefreshFlags.RESET_OFFSET);
- },
+ }
- start: function() {
+ start() {
if (this._isStarted)
return;
this._isStarted = true;
this._refreshInternal(RefreshFlags.NONE);
}
-});
+}
Signals.addSignalMethods(TrackerController.prototype);
-var TrackerCollectionsController = new Lang.Class({
- Name: 'TrackerCollectionsController',
- Extends: TrackerController,
-
- _init: function() {
- this.parent(WindowMode.WindowMode.COLLECTIONS);
+var TrackerCollectionsController = class TrackerCollectionsController extends TrackerController {
+ constructor() {
+ super(WindowMode.WindowMode.COLLECTIONS);
Application.documentManager.connect('active-collection-changed', Lang.bind(this,
function() {
@@ -314,13 +307,13 @@ var TrackerCollectionsController = new Lang.Class({
if (windowMode == WindowMode.WindowMode.COLLECTIONS)
this.refreshForObject();
}));
- },
+ }
- getOffsetController: function() {
+ getOffsetController() {
return Application.offsetCollectionsController;
- },
+ }
- getQuery: function() {
+ getQuery() {
let flags;
let activeCollection = Application.documentManager.getActiveCollection();
@@ -332,34 +325,28 @@ var TrackerCollectionsController = new Lang.Class({
return Application.queryBuilder.buildGlobalQuery(flags,
Application.offsetCollectionsController,
this.sortBy);
- },
-});
-
-var TrackerDocumentsController = new Lang.Class({
- Name: 'TrackerDocumentsController',
- Extends: TrackerController,
+ }
+}
- _init: function() {
- this.parent(WindowMode.WindowMode.DOCUMENTS);
- },
+var TrackerDocumentsController = class TrackerDocumentsController extends TrackerController {
+ constructor() {
+ super(WindowMode.WindowMode.DOCUMENTS);
+ }
- getOffsetController: function() {
+ getOffsetController() {
return Application.offsetDocumentsController;
- },
+ }
- getQuery: function() {
+ getQuery() {
return Application.queryBuilder.buildGlobalQuery(Query.QueryFlags.DOCUMENTS,
Application.offsetDocumentsController,
this.sortBy);
- },
-});
-
-var TrackerSearchController = new Lang.Class({
- Name: 'TrackerSearchController',
- Extends: TrackerController,
+ }
+}
- _init: function() {
- this.parent(WindowMode.WindowMode.SEARCH);
+var TrackerSearchController = class TrackerSearchController extends TrackerController {
+ constructor() {
+ super(WindowMode.WindowMode.SEARCH);
Application.documentManager.connect('active-collection-changed', Lang.bind(this,
function() {
@@ -373,22 +360,22 @@ var TrackerSearchController = new Lang.Class({
Application.searchTypeManager.connect('active-changed', Lang.bind(this, this.refreshForObject));
Application.searchMatchManager.connect('active-changed', Lang.bind(this,
this._onSearchMatchChanged));
- },
+ }
- _onSearchMatchChanged: function() {
+ _onSearchMatchChanged() {
// when the "match" search setting changes, refresh only if
// the search string is not empty
if (Application.searchController.getString() != '')
this.refreshForObject();
- },
+ }
- getOffsetController: function() {
+ getOffsetController() {
return Application.offsetSearchController;
- },
+ }
- getQuery: function() {
+ getQuery() {
return Application.queryBuilder.buildGlobalQuery(Query.QueryFlags.SEARCH,
Application.offsetSearchController,
this.sortBy);
- },
-});
+ }
+}
diff --git a/src/trackerUtils.js b/src/trackerUtils.js
index a1653fed..d5c84613 100644
--- a/src/trackerUtils.js
+++ b/src/trackerUtils.js
@@ -40,16 +40,14 @@ function setEditedName(newTitle, docId, callback) {
}
-var SingleItemJob = new Lang.Class({
- Name: 'SingleItemJob',
-
- _init: function(urn, queryBuilder) {
+var SingleItemJob = class SingleItemJob {
+ constructor(urn, queryBuilder) {
this._urn = urn;
this._cursor = null;
this._builder = queryBuilder;
- },
+ }
- run: function(flags, callback) {
+ run(flags, callback) {
this._callback = callback;
let query = this._builder.buildSingleQuery(flags, this._urn);
@@ -63,9 +61,9 @@ var SingleItemJob = new Lang.Class({
this._emitCallback();
}
}));
- },
+ }
- _onCursorNext: function(cursor, res) {
+ _onCursorNext(cursor, res) {
let valid = false;
try {
@@ -84,9 +82,9 @@ var SingleItemJob = new Lang.Class({
this._cursor = cursor;
this._emitCallback();
cursor.close();
- },
+ }
- _emitCallback: function() {
+ _emitCallback() {
this._callback(this._cursor);
}
-});
+}
diff --git a/src/windowMode.js b/src/windowMode.js
index 9797528f..274244e7 100644
--- a/src/windowMode.js
+++ b/src/windowMode.js
@@ -19,7 +19,6 @@
*
*/
-const Lang = imports.lang;
const Signals = imports.signals;
var WindowMode = {
@@ -32,15 +31,13 @@ var WindowMode = {
SEARCH: 6,
};
-var ModeController = new Lang.Class({
- Name: 'ModeController',
-
- _init: function() {
+var ModeController = class ModeController {
+ constructor() {
this._mode = WindowMode.NONE;
this._history = [];
- },
+ }
- goBack: function(steps) {
+ goBack(steps) {
if (!steps)
steps = 1;
@@ -67,9 +64,9 @@ var ModeController = new Lang.Class({
this._mode = tmp;
this.emit('window-mode-changed', this._mode, oldMode);
- },
+ }
- setWindowMode: function(mode) {
+ setWindowMode(mode) {
let oldMode = this._mode;
if (oldMode == mode)
@@ -79,10 +76,10 @@ var ModeController = new Lang.Class({
this._mode = mode;
this.emit('window-mode-changed', this._mode, oldMode);
- },
+ }
- getWindowMode: function() {
+ getWindowMode() {
return this._mode;
}
-});
+}
Signals.addSignalMethods(ModeController.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]