[gnome-documents/wip/rishi/split-view: 4/15] windowMode: Add goBack



commit 13c6e74fd396ae5fdc4167a7d124573eda46089f
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Sep 25 18:05:14 2014 +0200

    windowMode: Add goBack
    
    In the new split view designs we have to track the previous or old mode
    in a number of places. Either to implement the back button or escape
    key or to figure out which view to switch to when the search
    constraints are removed. This helps with that.
    
    Secondly, we need to use a stack instead of a single variable for this.
    A single variable is not enough to track transitions like:
     - launch application in overview
     - search for something (ie. overview -> search)
     - preview a search result (ie. search -> preview)
     - go back to search results (ie. preview -> search)
     - remove search constraints (ie. search -> ???)
    
    At this point, with a single variable, preview is the "old mode", not
    the overview. This is where having the whole history in a stack is
    useful.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686461

 src/edit.js       |    2 +-
 src/windowMode.js |   30 ++++++++++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/src/edit.js b/src/edit.js
index 684f590..0a061f7 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -79,7 +79,7 @@ const EditView = new Lang.Class({
         this._viewAction.enabled = false;
         this._viewAction.connect('activate', Lang.bind(this,
             function() {
-                Application.modeController.setWindowMode(WindowMode.WindowMode.PREVIEW);
+                Application.modeController.goBack();
             }));
 
         Application.documentManager.connect('load-started',
diff --git a/src/windowMode.js b/src/windowMode.js
index 50ecd16..f07488c 100644
--- a/src/windowMode.js
+++ b/src/windowMode.js
@@ -40,6 +40,27 @@ const ModeController = new Lang.Class({
         this._mode = WindowMode.NONE;
         this._fullscreen = false;
         this._canFullscreen = false;
+        this._history = [];
+    },
+
+    _canFullscreenPolicy: function(mode) {
+        return (mode == WindowMode.PREVIEW || mode == WindowMode.EDIT);
+    },
+
+    goBack: function() {
+        let oldMode = this._history.pop();
+        if (!oldMode || oldMode == WindowMode.NONE)
+            return;
+
+        let policy = this._canFullscreenPolicy(oldMode);
+        this.setCanFullscreen(policy);
+
+        // Swap the old and current modes.
+        let tmp = oldMode;
+        oldMode = this._mode;
+        this._mode = tmp;
+
+        this.emit('window-mode-changed', this._mode, oldMode);
     },
 
     setWindowMode: function(mode) {
@@ -48,13 +69,10 @@ const ModeController = new Lang.Class({
         if (oldMode == mode)
             return;
 
-        if (mode == WindowMode.PREVIEW
-            || mode == WindowMode.EDIT) {
-            this.setCanFullscreen(true);
-        } else {
-            this.setCanFullscreen(false);
-        }
+        let policy = this._canFullscreenPolicy(mode);
+        this.setCanFullscreen(policy);
 
+        this._history.push(oldMode);
         this._mode = mode;
 
         this.emit('window-mode-changed', this._mode, oldMode);


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