[gnome-documents/wip/gepub] embed: overhaul how document views are created



commit 22c52c3cafb269e07422bf7a36c6877d266b49c5
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jun 21 15:20:00 2016 -0700

    embed: overhaul how document views are created
    
    Instead of creating all the document views upfront, create them
    just-in-time when needed. This allows for a lot of code cleanups, as
    well as a better encapsulation of the views into the view embed.

 src/embed.js      |  125 +++++++++++++----------------------------------------
 src/epubview.js   |   33 ++------------
 src/evinceview.js |   89 +++++++++++++++++---------------------
 src/lokview.js    |   63 ++++++++++++---------------
 src/mainWindow.js |   28 ++++++++----
 src/preview.js    |   71 ++++++++++++++++++++++++++----
 6 files changed, 181 insertions(+), 228 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 338d86b..acf40e1 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -84,15 +84,6 @@ const Embed = new Lang.Class({
         this._search = new View.ViewContainer(WindowMode.WindowMode.SEARCH);
         this._stack.add_named(this._search, 'search');
 
-        this._previewEv = new EvinceView.EvinceView(this._stackOverlay);
-        this._stack.add_named(this._previewEv, 'preview-ev');
-
-        this._previewEPUB = new EPUBView.EPUBView(this._stackOverlay);
-        this._stack.add_named(this._previewEPUB, 'preview-epub');
-
-        this._previewLok = new LOKView.LOKView(this._stackOverlay);
-        this._stack.add_named(this._previewLok, 'preview-lok');
-
         this._edit = new Edit.EditView();
         this._stack.add_named(this._edit, 'edit');
 
@@ -151,13 +142,9 @@ const Embed = new Lang.Class({
             view = this._documents;
             break;
         case WindowMode.WindowMode.PREVIEW_EV:
-            view = this._previewEv;
-            break;
         case WindowMode.WindowMode.PREVIEW_LOK:
-            view = this._previewLok;
-            break;
         case WindowMode.WindowMode.PREVIEW_EPUB:
-            view = this._previewEPUB;
+            view = this._preview;
             break;
         case WindowMode.WindowMode.SEARCH:
             view = this._search;
@@ -190,17 +177,13 @@ const Embed = new Lang.Class({
         case WindowMode.WindowMode.DOCUMENTS:
             page = 'documents';
             break;
-        case WindowMode.WindowMode.PREVIEW_EV:
-            page = 'preview-ev';
-            break;
         case WindowMode.WindowMode.SEARCH:
             page = 'search';
             break;
+        case WindowMode.WindowMode.PREVIEW_EV:
         case WindowMode.WindowMode.PREVIEW_LOK:
-            page = 'preview-lok';
-            break;
         case WindowMode.WindowMode.PREVIEW_EPUB:
-            page = 'preview-epub';
+            page = 'preview';
             break;
         default:
             throw(new Error('Not handled'));
@@ -283,15 +266,15 @@ const Embed = new Lang.Class({
         case WindowMode.WindowMode.PREVIEW_EV:
             if (oldMode == WindowMode.WindowMode.EDIT)
                 Application.documentManager.reloadActiveItem();
-            this._prepareForEvinceView();
+            this._prepareForPreview(EvinceView.EvinceView);
             break;
         case WindowMode.WindowMode.PREVIEW_LOK:
             if (oldMode == WindowMode.WindowMode.EDIT)
                 Application.documentManager.reloadActiveItem();
-            this._prepareForLOKView();
+            this._prepareForPreview(LOKView.LOKView);
             break;
         case WindowMode.WindowMode.PREVIEW_EPUB:
-            this._prepareForEPUBView();
+            this._prepareForPreview(EPUBView.EPUBView);
             break;
         case WindowMode.WindowMode.EDIT:
             this._prepareForEdit();
@@ -371,31 +354,7 @@ const Embed = new Lang.Class({
         this._clearLoadTimer();
         this._spinner.stop();
 
-        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._previewEv.setModel(docModel);
-                this._toolbar.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.EPUB:
-            this._stack.set_visible_child_name('preview-epub');
-            break;
-        case Documents.ViewType.NONE:
-        default:
-            log('Something bad happened and the document type is unset');
-            break;
-        }
+        this._stack.set_visible_child_name('preview');
     },
 
     _onLoadError: function(manager, doc, message, exception) {
@@ -438,10 +397,11 @@ const Embed = new Lang.Class({
             break;
         }
 
-        if (this._previewEv)
-            this._previewEv.reset();
-        if (this._previewLok)
-            this._previewLok.reset();
+        if (this._preview) {
+            this._preview.destroy();
+            this._preview = null;
+        }
+
         if (this._edit)
             this._edit.setUri(null);
 
@@ -458,77 +418,52 @@ const Embed = new Lang.Class({
         this._stack.set_visible_child_name(visibleChildName);
     },
 
-    _prepareForEvinceView: function() {
+    _prepareForPreview: function(constructor) {
+        if (this._preview) {
+            this._preview.destroy();
+            this._preview = null;
+        }
         if (this._edit)
             this._edit.setUri(null);
         if (this._toolbar)
             this._toolbar.destroy();
 
+        this._preview = new constructor(this._stackOverlay);
+        this._stack.add_named(this._preview, 'preview');
+
         // pack the toolbar
-        this._toolbar = new EvinceView.EvinceViewToolbar(this._previewEv);
+        this._toolbar = this._preview.createToolbar();
         this._titlebar.add(this._toolbar);
 
-        this._stack.set_visible_child_name('preview-ev');
+        this._stack.set_visible_child_name('preview');
     },
 
     _prepareForEdit: function() {
-        if (this._previewEv)
-            this._previewEv.setModel(null);
+        if (this._preview) {
+            this._preview.destroy();
+            this._preview = null;
+        }
         if (this._toolbar)
             this._toolbar.destroy();
 
         // pack the toolbar
-        this._toolbar = new Edit.EditToolbar(this._previewEv);
+        this._toolbar = new Edit.EditToolbar(this._preview);
         this._titlebar.add(this._toolbar);
 
         this._stack.set_visible_child_name('edit');
     },
 
-    _prepareForLOKView: function() {
-        if (this._previewEv)
-            this._previewEv.setModel(null);
-        if (this._edit)
-            this._edit.setUri(null);
-        if (this._toolbar)
-            this._toolbar.destroy();
-
-        // pack the toolbar
-        this._toolbar = new LOKView.LOKViewToolbar(this._previewLok);
-        this._titlebar.add(this._toolbar);
-
-        this._stack.set_visible_child_name('preview-lok');
-    },
-
-    _prepareForEPUBView: function() {
-        if (this._previewEv)
-            this._previewEv.setModel(null);
-        if (this._edit)
-            this._edit.setUri(null);
-        if (this._toolbar)
-            this._toolbar.destroy();
-
-        this._previewEPUB.reset();
-
-        // pack the toolbar
-        this._toolbar = new EPUBView.EPUBViewToolbar(this._previewEPUB);
-        this._titlebar.add(this._toolbar);
-
-        this._stack.set_visible_child_name('preview-epub');
-    },
-
     getMainToolbar: function() {
         let windowMode = Application.modeController.getWindowMode();
         let fullscreen = Application.modeController.getFullscreen();
 
         if (fullscreen && (windowMode == WindowMode.WindowMode.PREVIEW_EV))
-            return this._previewEv.getFullscreenToolbar();
+            return this._preview.getFullscreenToolbar();
         else
             return this._toolbar;
     },
 
-    getEvinceView: function() {
-        //FIXME When we can pass clicks and key presses
-        //to the view, we'll need to grab the real current view
-        return this._previewEv;
+    getPreview: function() {
+        return this._preview;
     }
 });
diff --git a/src/epubview.js b/src/epubview.js
index 0de25a6..0417d41 100644
--- a/src/epubview.js
+++ b/src/epubview.js
@@ -32,7 +32,6 @@ const Documents = imports.documents;
 const MainToolbar = imports.mainToolbar;
 const Preview = imports.preview;
 const Searchbar = imports.searchbar;
-const WindowMode = imports.windowMode;
 
 const Lang = imports.lang;
 const Signals = imports.signals;
@@ -45,28 +44,17 @@ const EPUBView = new Lang.Class({
     Name: 'EPUBView',
     Extends: Preview.Preview,
 
-    _init: function(overlay) {
-        this.parent(overlay);
-
-        Application.documentManager.connect('load-started',
-                                            Lang.bind(this, this._onLoadStarted));
-        Application.documentManager.connect('load-error',
-                                            Lang.bind(this, this._onLoadError));
-        Application.modeController.connect('window-mode-changed',
-                                           Lang.bind(this, this._onWindowModeChanged));
+    createToolbar: function() {
+        return new EPUBViewToolbar(this);
     },
 
     createView: function() {
         return new Gepub.Widget();
     },
 
-    _onWindowModeChanged: function() {
-        let windowMode = Application.modeController.getWindowMode();
-        if (windowMode != WindowMode.WindowMode.PREVIEW_EPUB)
-            this.navControls.hide();
-    },
+    onLoadFinished: function(manager, doc) {
+        this.parent(manager, doc);
 
-    _onLoadStarted: function(manager, doc) {
         if (doc.viewType != Documents.ViewType.EPUB)
             return;
 
@@ -74,22 +62,9 @@ const EPUBView = new Lang.Class({
         this._epubdoc = new Gepub.Doc({ path: f.get_path() });
         this._epubdoc.init(null);
         this.view.doc = this._epubdoc;
-
         this.set_visible_child_name('view');
     },
 
-    _onLoadError: function(manager, doc, message, exception) {
-        if (doc.viewType != Documents.ViewType.EPUB)
-            return;
-
-        this.setError(message, exception.message);
-    },
-
-    reset: function () {
-        this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
-        this.navControls.show();
-    },
-
     goPrev: function() {
         this._epubdoc.go_prev();
     },
diff --git a/src/evinceview.js b/src/evinceview.js
index 717d45a..c922e18 100644
--- a/src/evinceview.js
+++ b/src/evinceview.js
@@ -119,11 +119,6 @@ const EvinceView = new Lang.Class({
                 Lang.bind(this, this._onPresentStateChanged));
         }
 
-        Application.documentManager.connect('load-started',
-                                            Lang.bind(this, this._onLoadStarted));
-        Application.documentManager.connect('load-error',
-                                            Lang.bind(this, this._onLoadError));
-
         this.connect('destroy', Lang.bind(this,
             function() {
                 this._zoomIn.disconnect(zoomInId);
@@ -144,6 +139,11 @@ const EvinceView = new Lang.Class({
         return new EvinceViewNavControls(this, this.overlay);
     },
 
+    createToolbar: function() {
+        this._toolbar = new EvinceViewToolbar(this);
+        return this._toolbar;
+    },
+
     createView: function() {
         let sw = new Gtk.ScrolledWindow({ hexpand: true,
                                           vexpand: true });
@@ -173,7 +173,7 @@ const EvinceView = new Lang.Class({
         return sw;
     },
 
-    _onLoadStarted: function(manager, doc) {
+    onLoadStarted: function(manager, doc) {
         if (doc.viewType != Documents.ViewType.EV)
             return;
         this._bookmarkPage.enabled = false;
@@ -181,12 +181,26 @@ const EvinceView = new Lang.Class({
         this._copy.enabled = false;
     },
 
-    _onLoadError: function(manager, doc, message, exception) {
+    onLoadFinished: function(manager, doc, docModel) {
+        this.parent(manager, doc, docModel);
+
         if (doc.viewType != Documents.ViewType.EV)
             return;
+
+        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._setModel(docModel);
+        this.grab_focus();
+    },
+
+    onLoadError: function(manager, doc, message, exception) {
         this._controlsVisible = true;
         this._syncControlsVisible();
-        this.setError(message, exception.message);
+
+        this.parent(manager, doc, message, exception);
     },
 
     _onActionStateChanged: function(source, actionName, state) {
@@ -368,7 +382,6 @@ const EvinceView = new Lang.Class({
         if (windowMode != WindowMode.WindowMode.PREVIEW_EV) {
             this.controlsVisible = false;
             this._hidePresentation();
-            this.navControls.hide();
         }
     },
 
@@ -478,10 +491,6 @@ const EvinceView = new Lang.Class({
         this._syncControlsVisible();
     },
 
-    activateResult: function() {
-        this.findNext();
-    },
-
     search: function(str) {
         if (!this._model)
             return;
@@ -514,34 +523,19 @@ const EvinceView = new Lang.Class({
         this.emitJS('search-changed', job.has_results());
     },
 
-    reset: function() {
-        this.setModel(null);
-        this.view.destroy();
-        this.navControls.destroy();
-
-        this.view = this.createView();
-        this.add_named(this.view, 'view');
-        this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
-
-        this.navControls = this.createNavControls();
-        this.show_all();
-    },
-
-    setModel: function(model) {
+    _setModel: function(model) {
         if (this._model == model)
             return;
 
-        if (this._evView) {
-            this.controlsVisible = false;
-            this._lastSearch = '';
-        }
-
+        this.controlsVisible = false;
+        this._lastSearch = '';
         this._model = model;
 
+        this._evView.set_model(this._model);
+        this.navControls.setModel(this._model);
+        this._toolbar.setModel(this._model);
+
         if (this._model) {
-            this._evView.set_model(this._model);
-            this.navControls.setModel(model);
-            this.navControls.show();
             if (this._togglePresentation)
                 this._togglePresentation.enabled = true;
 
@@ -610,6 +604,10 @@ const EvinceView = new Lang.Class({
         this._evView.find_next();
     },
 
+    scroll: function(direction) {
+        this._evView.scroll(direction, false);
+    },
+
     get evView() {
         return this._evView;
     }
@@ -681,7 +679,6 @@ const EvinceViewToolbar = new Lang.Class({
         this.toolbar.set_show_close_button(true);
 
         this._handleEvent = false;
-        this._model = null;
 
         this._searchAction = Application.application.lookup_action('search');
         this._searchAction.enabled = false;
@@ -722,24 +719,22 @@ const EvinceViewToolbar = new Lang.Class({
     },
 
     _enableSearch: function() {
-        if (!this._model)
-            return;
-
-        let isFind = true;
+        let hasPages = this._previewView.hasPages;
+        let canFind = true;
 
         try {
             // This is a hack to find out if evDoc implements the
             // EvDocument.DocumentFind interface or not. We don't expect
             // the following invocation to work.
-            let evDoc = this._model.get_document();
+            let evDoc = this.preview.getModel().get_document();
             evDoc.find_text();
         } catch (e if e instanceof TypeError) {
-            isFind = false;
+            canFind = false;
         } catch (e) {
         }
 
-        this._handleEvent = (this._previewView.hasPages && isFind);
-        this._searchAction.enabled = (this._previewView.hasPages && isFind);
+        this._handleEvent = (hasPages && canFind);
+        this._searchAction.enabled = (hasPages && canFind);
     },
 
     _getEvinceViewMenu: function() {
@@ -771,11 +766,7 @@ const EvinceViewToolbar = new Lang.Class({
         this.toolbar.set_title(primary);
     },
 
-    setModel: function(model) {
-        if (!model)
-            return;
-
-        this._model = model;
+    setModel: function() {
         this._gearMenu.enabled = true;
         this._enableSearch();
         this._setToolbarTitle();
diff --git a/src/lokview.js b/src/lokview.js
index 547b146..41f0d15 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -112,7 +112,7 @@ const LOKView = new Lang.Class({
         this._previewContextMenu.attach_to_widget(this.view, null);
 
         this._zoomIn = Application.application.lookup_action('zoom-in');
-        let zoomInId = this._zoomIn.connect('activate', Lang.bind(this,
+        this._zoomInId = this._zoomIn.connect('activate', Lang.bind(this,
             function() {
                 // FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97301
                 if (!this._doc)
@@ -122,7 +122,7 @@ const LOKView = new Lang.Class({
             }));
 
         this._zoomOut = Application.application.lookup_action('zoom-out');
-        let zoomOutId = this._zoomOut.connect('activate', Lang.bind(this,
+        this._zoomOutId = this._zoomOut.connect('activate', Lang.bind(this,
             function() {
                 // FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97301
                 if (!this._doc)
@@ -132,19 +132,28 @@ const LOKView = new Lang.Class({
             }));
 
         this._copy = Application.application.lookup_action('copy');
-        let copyId = this._copy.connect('activate', Lang.bind(this, this._onCopyActivated));
-
-        Application.documentManager.connect('load-started',
-                                            Lang.bind(this, this._onLoadStarted));
-        Application.documentManager.connect('load-error',
-                                            Lang.bind(this, this._onLoadError));
-
-        this.connect('destroy', Lang.bind(this,
-           function() {
-               this._zoomIn.disconnect(zoomInId);
-               this._zoomOut.disconnect(zoomOutId);
-               this._copy.disconnect(copyId);
-           }));
+        this._copyId = this._copy.connect('activate', Lang.bind(this, this._onCopyActivated));
+    },
+
+    vfunc_destroy: function() {
+        if (this._zoomInId > 0) {
+            this._zoomIn.disconnect(this._zoomInId);
+            this._zoomInId = 0;
+        }
+        if (this._zoomOutId > 0) {
+            this._zoomOut.disconnect(this._zoomOutId);
+            this._zoomOutId = 0;
+        }
+        if (this._copyId > 0) {
+            this._copy.disconnect(this._copyId);
+            this._copyId = 0;
+        }
+
+        this.parent();
+    },
+
+    createToolbar: function() {
+        return new LOKViewToolbar(this);
     },
 
     createView: function() {
@@ -183,7 +192,9 @@ const LOKView = new Lang.Class({
         clipboard.set_text(selectedText, selectedText.length);
     },
 
-    _onLoadStarted: function(manager, doc) {
+    onLoadFinished: function(manager, doc) {
+        this.parent(manager, doc);
+
         if (doc.viewType != Documents.ViewType.LOK)
             return;
         if (!isAvailable())
@@ -194,13 +205,6 @@ const LOKView = new Lang.Class({
         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);
-    },
-
     open_document_cb: function(res, doc) {
         // TODO: Call _finish and check failure
         this._progressBar.hide();
@@ -208,17 +212,6 @@ const LOKView = new Lang.Class({
         this._lokview.set_edit(false);
     },
 
-    reset: function () {
-        if (!this._lokview)
-            return;
-
-        // FIXME: https://bugs.documentfoundation.org/show_bug.cgi?id=97235
-        if (this._doc)
-            this._lokview.reset_view();
-        this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
-        this._copy.enabled = false;
-    },
-
     _getPreviewContextMenu: function() {
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/Documents/ui/preview-context-menu.ui');
@@ -267,7 +260,7 @@ const LOKView = new Lang.Class({
     },
 
     get hasPages() {
-        return isOpenDocumentPartDocument(this._doc.mimeType);
+        return this._doc ? isOpenDocumentPartDocument(this._doc.mimeType) : false;
     },
 
     get page() {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 0eeaf07..d1656ef 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -194,14 +194,14 @@ const MainWindow = new Lang.Class({
         case WindowMode.WindowMode.NONE:
             return false;
         case WindowMode.WindowMode.PREVIEW_EV:
+        case WindowMode.WindowMode.PREVIEW_EPUB:
+        case WindowMode.WindowMode.PREVIEW_LOK:
             return this._handleKeyPreview(event);
         case WindowMode.WindowMode.COLLECTIONS:
         case WindowMode.WindowMode.DOCUMENTS:
         case WindowMode.WindowMode.SEARCH:
             return this._handleKeyOverview(event);
         case WindowMode.WindowMode.EDIT:
-        case WindowMode.WindowMode.PREVIEW_EPUB:
-        case WindowMode.WindowMode.PREVIEW_LOK: //FIXME should be same as preview
             return false;
         default:
             throw(new Error('Not handled'));
@@ -236,10 +236,12 @@ const MainWindow = new Lang.Class({
         let keyval = event.get_keyval()[1];
         let fullscreen = Application.modeController.getFullscreen();
         let def_mod_mask = Gtk.accelerator_get_default_mod_mask();
-        let preview = this._embed.getEvinceView();
+        let preview = this._embed.getPreview();
         let state = event.get_state()[1];
+        let windowMode = Application.modeController.getWindowMode();
 
-        if (keyval == Gdk.KEY_Escape) {
+        if (keyval == Gdk.KEY_Escape &&
+            windowMode == WindowMode.WindowMode.PREVIEW_EV) {
             let model = preview.getModel();
 
             if (preview.controlsVisible && (model != null)) {
@@ -255,26 +257,32 @@ const MainWindow = new Lang.Class({
         if (((keyval == Gdk.KEY_Page_Up) &&
             ((state & Gdk.ModifierType.CONTROL_MASK) != 0)) ||
             ((keyval == Gdk.KEY_Left) && ((state & def_mod_mask) == 0))) {
-            preview.view.previous_page();
+            preview.goPrev();
             return true;
         }
 
         if (((keyval == Gdk.KEY_Page_Down) &&
             ((state & Gdk.ModifierType.CONTROL_MASK) != 0)) ||
             ((keyval == Gdk.KEY_Right) && ((state & def_mod_mask) == 0))) {
-            preview.view.next_page();
+            preview.goNext();
             return true;
         }
 
         if (keyval == Gdk.KEY_Page_Up) {
-            preview.view.scroll(Gtk.ScrollType.PAGE_BACKWARD, false);
-            return true;
+            try {
+                preview.scroll(Gtk.ScrollType.PAGE_BACKWARD);
+                return true;
+            } catch (e) {
+            }
         }
 
         if (keyval == Gdk.KEY_space ||
             keyval == Gdk.KEY_Page_Down) {
-            preview.view.scroll(Gtk.ScrollType.PAGE_FORWARD, false);
-            return true;
+            try {
+                preview.scroll(Gtk.ScrollType.PAGE_FORWARD);
+                return true;
+            } catch (e) {
+            }
         }
 
         return false;
diff --git a/src/preview.js b/src/preview.js
index 9e781af..5f66844 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -21,38 +21,81 @@ const Preview = new Lang.Class({
         this.parent({ homogeneous: true,
                       transition_type: Gtk.StackTransitionType.CROSSFADE });
 
-        let findPrev = Application.application.lookup_action('find-prev');
-        let findPrevId = findPrev.connect('activate', Lang.bind(this, this.findPrev));
+        this._findPrev = Application.application.lookup_action('find-prev');
+        this._findPrevId = this._findPrev.connect('activate', Lang.bind(this, this.findPrev));
 
-        let findNext = Application.application.lookup_action('find-next');
-        let findNextId = findNext.connect('activate', Lang.bind(this, this.findNext));
+        this._findNext = Application.application.lookup_action('find-next');
+        this._findNextId = this._findNext.connect('activate', Lang.bind(this, this.findNext));
 
         this._errorBox = new ErrorBox.ErrorBox();
         this.add_named(this._errorBox, 'error');
 
         this.view = this.createView();
         this.add_named(this.view, 'view');
+        this.view.show();
         this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
 
         this.navControls = this.createNavControls();
+        this.navControls.show();
         this.show_all();
 
-        this.connect('destroy', Lang.bind(this, function() {
-            findPrev.disconnect(findPrevId);
-            findNext.disconnect(findNextId);
-        }));
+        this._loadStartedId = Application.documentManager.connect('load-started',
+                                                                  Lang.bind(this, this.onLoadStarted));
+        this._loadFinishedId = Application.documentManager.connect('load-finished',
+                                                                   Lang.bind(this, this.onLoadFinished));
+        this._loadErrorId = Application.documentManager.connect('load-error',
+                                                                Lang.bind(this, this.onLoadError));
+    },
+
+    vfunc_destroy: function() {
+        if (this._findPrevId > 0) {
+            this._findPrev.disconnect(this._findPrevId);
+            this._findPrevId = 0;
+        }
+        if (this._findNextId > 0) {
+            this._findNext.disconnect(this._findNextId);
+            this._findNextId = 0;
+        }
+        if (this._loadStartedId > 0) {
+            Application.documentManager.disconnect(this._loadStartedId);
+            this._loadStartedId = 0;
+        }
+        if (this._loadFinishedId > 0) {
+            Application.documentManager.disconnect(this._loadFinishedId);
+            this._loadFinishedId = 0;
+        }
+        if (this._loadErrorId > 0) {
+            Application.documentManager.disconnect(this._loadErrorId);
+            this._loadErrorId = 0;
+        }
+        if (this.navControls) {
+            this.navControls.destroy();
+            this.navControls = null;
+        }
+
+        this.parent();
     },
 
     createNavControls: function() {
         return new PreviewNavControls(this, this.overlay);
     },
 
+    createToolbar: function() {
+        throw(new Error('Not implemented'));
+    },
+
     createView: function() {
         throw(new Error('Not implemented'));
     },
 
-    setError: function(primary, secondary) {
-        this._errorBox.update(primary, secondary);
+    onLoadStarted: function(manager, doc) {
+    },
+
+    onLoadFinished: function(manager, doc, docModel) {
+    },
+
+    onLoadError: function(manager, doc, message, exception) {
+        this._errorBox.update(message, exception.message);
         this.set_visible_child_name('error');
     },
 
@@ -90,6 +133,14 @@ const Preview = new Lang.Class({
 
     findNext: function() {
         throw (new Error('Not implemented'));
+    },
+
+    scroll: function(direction) {
+        throw (new Error('Not implemented'));
+    },
+
+    activateResult: function() {
+        this.findNext();
     }
 });
 


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