[gnome-documents/wip/lokdocview-rebase: 18/27] Add ViewTypes for different backends
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/lokdocview-rebase: 18/27] Add ViewTypes for different backends
- Date: Mon, 4 Jan 2016 12:24:36 +0000 (UTC)
commit 8a8bba0d606fb6ec6f8505675ce249b228577f9c
Author: Bastien Nocera <hadess hadess net>
Date: Sun Dec 6 21:58:17 2015 +0100
Add ViewTypes for different backends
This should simplify adding subsequent backends, later on. This will
still require major cleanups to make sure that all backend-specific code
is moved into the backend though.
src/documents.js | 18 ++++++++++++++++++
src/embed.js | 39 ++++++++++++++++++++++++---------------
src/lokview.js | 9 ++++-----
src/preview.js | 7 ++++++-
4 files changed, 52 insertions(+), 21 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 3378de2..6713b00 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 = '';
@@ -1380,6 +1396,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));
},
@@ -1438,6 +1455,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 dca45f1..a7486f8 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;
@@ -352,25 +355,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 d133bd5..ae18dac 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -136,8 +136,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() {
@@ -147,6 +145,8 @@ const LOKView = new Lang.Class({
},
_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;
@@ -155,6 +155,8 @@ const LOKView = new Lang.Class({
},
_onLoadError: function(manager, doc, message, exception) {
+ if (doc.viewType != Documents.ViewType.LOK)
+ return;
//FIXME we should hide controls
this._setError(message, exception.message);
},
@@ -175,9 +177,6 @@ const LOKView = new Lang.Class({
this.view.set_edit(false);
},
- _onLoadFinished: function(manager, doc, docModel) {
- },
-
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]