[gnome-documents/wip/lokdocview-rebase: 5/9] Start loading LO documents when load-started is emitted
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/lokdocview-rebase: 5/9] Start loading LO documents when load-started is emitted
- Date: Fri, 8 Jan 2016 13:03:02 +0000 (UTC)
commit 1ef8511d9b6378af81890b38b141176b081e0bb7
Author: Bastien Nocera <hadess hadess net>
Date: Sun Dec 6 15:36:06 2015 +0100
Start loading LO documents when load-started is emitted
... and make sure that each view only reacts to signals for documents
that they are meant to handle.
https://bugzilla.gnome.org/show_bug.cgi?id=753686
src/documents.js | 18 ++++++++++++++++++
src/embed.js | 39 ++++++++++++++++++++++++---------------
src/lokview.js | 23 ++++++++++-------------
src/preview.js | 7 ++++++-
4 files changed, 58 insertions(+), 29 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 235ce92..db41eb2 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -45,6 +45,13 @@ const Search = imports.search;
const TrackerUtils = imports.trackerUtils;
const Utils = imports.utils;
+// Those are the per-document-type views
+const ViewType = {
+ UNSET: 0,
+ EV: 1,
+ LOK: 2
+};
+
const DeleteItemJob = new Lang.Class({
Name: 'DeleteItemJob',
// deletes the given resource
@@ -234,6 +241,7 @@ const DocCommon = new Lang.Class({
this.origPixbuf = null;
this.defaultApp = null;
this.defaultAppName = null;
+ this.viewType = ViewType.UNSET;
this.mimeType = null;
this.rdfType = null;
@@ -693,6 +701,14 @@ const DocCommon = new Lang.Class({
log('Error: DocCommon implementations must override getSourceLink');
},
+ updateViewType: function() {
+ if (LOKView.isOpenDocumentFormat(this.mimeType) && !Application.application.isBooks) {
+ this.viewType = ViewType.LOK;
+ } else {
+ this.viewType = ViewType.EV;
+ }
+ },
+
getWhere: function() {
let retval = '';
@@ -1392,6 +1408,7 @@ const DocumentManager = new Lang.Class({
this._clearActiveDocModel();
this._loaderCancellable = new Gio.Cancellable();
+ doc.updateViewType();
this.emit('load-started', doc);
doc.load(passwd, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
},
@@ -1450,6 +1467,7 @@ const DocumentManager = new Lang.Class({
recentManager.add_item(doc.uri);
this._loaderCancellable = new Gio.Cancellable();
+ doc.updateViewType();
this.emit('load-started', doc);
doc.load(null, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
}
diff --git a/src/embed.js b/src/embed.js
index 62f12bb..75a4da6 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -153,6 +153,9 @@ const Embed = new Lang.Class({
case WindowMode.WindowMode.PREVIEW:
view = this._previewEv;
break;
+ case WindowMode.WindowMode.PREVIEW_LOK:
+ view = this._previewLok;
+ break;
case WindowMode.WindowMode.SEARCH:
view = this._search;
break;
@@ -355,25 +358,31 @@ const Embed = new Lang.Class({
},
_onLoadFinished: function(manager, doc, docModel) {
- if (doc && docModel) {
- if (Application.application.isBooks)
- docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
- else
- docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
- docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
- this._toolbar.setModel(docModel);
- this._previewEv.setModel(docModel);
- this._previewEv.grab_focus();
- }
-
this._clearLoadTimer();
this._spinner.stop();
- //FIXME we need to select the preview widget better
- if (doc != null && docModel == null)
- this._stack.set_visible_child_name('preview-lok');
- else
+ switch (doc.viewType) {
+ case Documents.ViewType.EV:
+ if (docModel) {
+ if (Application.application.isBooks)
+ docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
+ else
+ docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
+ docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
+ this._toolbar.setModel(docModel);
+ this._previewEv.setModel(docModel);
+ this._previewEv.grab_focus();
+ }
this._stack.set_visible_child_name('preview-ev');
+ break;
+ case Documents.ViewType.LOK:
+ this._stack.set_visible_child_name('preview-lok');
+ break;
+ case Documents.ViewType.UNSET:
+ default:
+ log('Something bad happened and the document type is unset');
+ break;
+ }
},
_onLoadError: function(manager, doc, message, exception) {
diff --git a/src/lokview.js b/src/lokview.js
index 7f02909..4c4baef 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -133,8 +133,6 @@ const LOKView = new Lang.Class({
Lang.bind(this, this._onLoadStarted));
Application.documentManager.connect('load-error',
Lang.bind(this, this._onLoadError));
- Application.documentManager.connect('load-finished',
- Lang.bind(this, this._onLoadFinished));
this.connect('destroy', Lang.bind(this,
function() {
@@ -143,10 +141,19 @@ const LOKView = new Lang.Class({
}));
},
- _onLoadStarted: function() {
+ _onLoadStarted: function(manager, doc) {
+ if (doc.viewType != Documents.ViewType.LOK)
+ return;
+ let file = Gio.File.new_for_uri (doc.uri);
+ let location = file.get_path();
+ this._doc = doc;
+ this.view.open_document(location, "{}", null, Lang.bind(this, this.open_document_cb));
+ this._progressBar.show();
},
_onLoadError: function(manager, doc, message, exception) {
+ if (doc.viewType != Documents.ViewType.LOK)
+ return;
//FIXME we should hide controls
this._setError(message, exception.message);
},
@@ -166,16 +173,6 @@ const LOKView = new Lang.Class({
this.view.set_edit(false);
},
- _onLoadFinished: function(manager, doc, docModel) {
- if (docModel == null && doc != null) {
- let file = Gio.File.new_for_uri (doc.uri);
- let location = file.get_path();
- this._doc = doc;
- this.view.open_document(location, "{}", null, Lang.bind(this, this.open_document_cb));
- this._progressBar.show();
- }
- },
-
reset: function () {
if (!this.view)
return;
diff --git a/src/preview.js b/src/preview.js
index 12ebecb..c7804bc 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -43,6 +43,7 @@ const Utils = imports.utils;
const View = imports.view;
const WindowMode = imports.windowMode;
const Presentation = imports.presentation;
+const Documents = imports.documents;
const _FULLSCREEN_TOOLBAR_TIMEOUT = 2; // seconds
@@ -172,13 +173,17 @@ const PreviewView = new Lang.Class({
}));
},
- _onLoadStarted: function() {
+ _onLoadStarted: function(manager, doc) {
+ if (doc.viewType != Documents.ViewType.EV)
+ return;
this._bookmarkPage.enabled = false;
this._places.enabled = false;
this._copy.enabled = false;
},
_onLoadError: function(manager, doc, message, exception) {
+ if (doc.viewType != Documents.ViewType.EV)
+ return;
this._controlsVisible = true;
this._syncControlsVisible();
this._setError(message, exception.message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]