[gnome-documents/wip/cosimoc/view-rework: 19/28] embed: remove _getViewFromMode()



commit ebd74b5dc33e7516da9943711f5230dd9e593960
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Aug 6 18:51:18 2016 -0700

    embed: remove _getViewFromMode()
    
    We can more easily keep track of the current view in a variable, and
    call it directly.

 src/embed.js |   35 ++++++-----------------------------
 1 files changed, 6 insertions(+), 29 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index f653e58..5ffcc18 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -48,6 +48,7 @@ const Embed = new Lang.Class({
     Extends: Gtk.Box,
 
     _init: function(mainWindow) {
+        this._currentView = null;
         this._loadShowId = 0;
         this._searchState = null;
         this._window = mainWindow;
@@ -131,36 +132,9 @@ const Embed = new Lang.Class({
             this._onWindowModeChanged(Application.modeController, windowMode, WindowMode.WindowMode.NONE);
     },
 
-    _getViewFromMode: function(windowMode) {
-        let view;
-
-        switch (windowMode) {
-        case WindowMode.WindowMode.COLLECTIONS:
-            view = this._collections;
-            break;
-        case WindowMode.WindowMode.DOCUMENTS:
-            view = this._documents;
-            break;
-        case WindowMode.WindowMode.PREVIEW_EV:
-        case WindowMode.WindowMode.PREVIEW_LOK:
-        case WindowMode.WindowMode.PREVIEW_EPUB:
-            view = this._preview;
-            break;
-        case WindowMode.WindowMode.SEARCH:
-            view = this._search;
-            break;
-        default:
-            throw(new Error('Not handled'));
-            break;
-        }
-
-        return view;
-    },
-
     _onActivateResult: function() {
-        let windowMode = Application.modeController.getWindowMode();
-        let view = this._getViewFromMode(windowMode);
-        view.activateResult();
+        if (this._currentView)
+            this._currentView.activateResult();
     },
 
     _restoreLastPage: function() {
@@ -422,6 +396,7 @@ const Embed = new Lang.Class({
 
         this._spinner.stop();
         this._stack.set_visible_child(visibleChild);
+        this._currentView = visibleChild;
     },
 
     _prepareForPreview: function(constructor) {
@@ -438,6 +413,7 @@ const Embed = new Lang.Class({
         this._titlebar.add(this._toolbar);
 
         this._stack.set_visible_child_name('preview');
+        this._currentView = this._preview;
     },
 
     _prepareForEdit: function() {
@@ -453,6 +429,7 @@ const Embed = new Lang.Class({
         this._titlebar.add(this._toolbar);
 
         this._stack.set_visible_child_name('edit');
+        this._currentView = this._edit;
     },
 
     getMainToolbar: function() {


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