[gnome-documents/wip/cosimoc/view-rework: 24/28] embed: move setting preview window type to DocumentsManager



commit eb9ef25229c0429dbaba0adeb70536a3ea046a22
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Aug 7 16:24:19 2016 -0700

    embed: move setting preview window type to DocumentsManager
    
    This way, all the preview views will always get a load-started signal.

 src/documents.js  |   37 ++++++++++++++++---------------------
 src/embed.js      |    7 -------
 src/epubview.js   |    3 ---
 src/evinceview.js |    6 ------
 src/lokview.js    |    2 --
 5 files changed, 16 insertions(+), 39 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 60fa918..eb3cc56 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -45,14 +45,7 @@ const Query = imports.query;
 const Search = imports.search;
 const TrackerUtils = imports.trackerUtils;
 const Utils = imports.utils;
-
-// Those are the per-document-type views
-const ViewType = {
-    NONE: 0,
-    EV: 1,
-    LOK: 2,
-    EPUB: 3
-};
+const WindowMode = imports.windowMode;
 
 const DeleteItemJob = new Lang.Class({
     Name: 'DeleteItemJob',
@@ -243,7 +236,6 @@ const DocCommon = new Lang.Class({
         this.origPixbuf = null;
         this.defaultApp = null;
         this.defaultAppName = null;
-        this.viewType = ViewType.NONE;
 
         this.mimeType = null;
         this.rdfType = null;
@@ -707,16 +699,6 @@ 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 if (EPUBView.isEpub(this.mimeType) && Application.application.isBooks) {
-            this.viewType = ViewType.EPUB;
-        } else {
-            this.viewType = ViewType.EV;
-        }
-    },
-
     getWhere: function() {
         let retval = '';
 
@@ -1396,6 +1378,19 @@ const DocumentManager = new Lang.Class({
         this.emit('load-finished', doc, docModel);
     },
 
+    _requestPreview: function(doc) {
+        let windowMode;
+        if (LOKView.isOpenDocumentFormat(doc.mimeType) && !Application.application.isBooks) {
+            windowMode = WindowMode.WindowMode.PREVIEW_LOK;
+        } else if (EPUBView.isEpub(doc.mimeType) && Application.application.isBooks) {
+            windowMode = WindowMode.WindowMode.PREVIEW_EPUB;
+        } else {
+            windowMode = WindowMode.WindowMode.PREVIEW_EV;
+        }
+
+        Application.modeController.setWindowMode(windowMode);
+    },
+
     reloadActiveItem: function(passwd) {
         let doc = this.getActiveItem();
 
@@ -1409,7 +1404,7 @@ const DocumentManager = new Lang.Class({
         this._clearActiveDocModel();
 
         this._loaderCancellable = new Gio.Cancellable();
-        doc.updateViewType();
+        this._requestPreview(doc);
         this.emit('load-started', doc);
         doc.load(passwd, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
     },
@@ -1468,7 +1463,7 @@ const DocumentManager = new Lang.Class({
             recentManager.add_item(doc.uri);
 
             this._loaderCancellable = new Gio.Cancellable();
-            doc.updateViewType();
+            this._requestPreview(doc);
             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 f2be0d9..284bc64 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -292,13 +292,6 @@ const Embed = new Lang.Class({
     },
 
     _onLoadStarted: function(manager, doc) {
-        if (LOKView.isOpenDocumentFormat(doc.mimeType))
-            Application.modeController.setWindowMode(WindowMode.WindowMode.PREVIEW_LOK);
-        else if (EPUBView.isEpub(doc.mimeType))
-            Application.modeController.setWindowMode(WindowMode.WindowMode.PREVIEW_EPUB);
-        else
-            Application.modeController.setWindowMode(WindowMode.WindowMode.PREVIEW_EV);
-
         this._clearLoadTimer();
         this._loadShowId = Mainloop.timeout_add(_PDF_LOADER_TIMEOUT, Lang.bind(this,
             function() {
diff --git a/src/epubview.js b/src/epubview.js
index 2a637a7..923b0aa 100644
--- a/src/epubview.js
+++ b/src/epubview.js
@@ -65,9 +65,6 @@ const EPUBView = new Lang.Class({
     onLoadFinished: function(manager, doc) {
         this.parent(manager, doc);
 
-        if (doc.viewType != Documents.ViewType.EPUB)
-            return;
-
         let f = Gio.File.new_for_uri(doc.uri);
         this._epubdoc = new Gepub.Doc({ path: f.get_path() });
         this._epubdoc.init(null);
diff --git a/src/evinceview.js b/src/evinceview.js
index 2dad441..d4ea883 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -234,9 +234,6 @@ const EvinceView = new Lang.Class({
     onLoadStarted: function(manager, doc) {
         this.parent(manager, doc);
 
-        if (doc.viewType != Documents.ViewType.EV)
-            return;
-
         this.getAction('bookmark-page').enabled = false;
         this.getAction('places').enabled = false;
     },
@@ -244,9 +241,6 @@ const EvinceView = new Lang.Class({
     onLoadFinished: function(manager, doc, docModel) {
         this.parent(manager, doc, docModel);
 
-        if (doc.viewType != Documents.ViewType.EV)
-            return;
-
         this.controlsVisible = false;
         this._lastSearch = '';
         this._model = docModel;
diff --git a/src/lokview.js b/src/lokview.js
index 3aa8c7e..b23f855 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -141,8 +141,6 @@ const LOKView = new Lang.Class({
     onLoadFinished: function(manager, doc) {
         this.parent(manager, doc);
 
-        if (doc.viewType != Documents.ViewType.LOK)
-            return;
         if (!isAvailable())
             return;
         this._doc = doc;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]