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



commit 46b21e64451228f3791c437362c1799ae00e1be2
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/mainWindow.js |    7 +++++--
 src/preview.js    |    1 +
 src/windowMode.js |   30 ++++++++++++++++++++++++------
 4 files changed, 31 insertions(+), 9 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/mainWindow.js b/src/mainWindow.js
index 2a3798c..2a404c2 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -155,6 +155,7 @@ const MainWindow = new Lang.Class({
         if (windowMode == WindowMode.WindowMode.PREVIEW ||
             windowMode == WindowMode.WindowMode.EDIT) {
             Application.documentManager.setActiveItem(null);
+            Application.modeController.goBack();
         } else if (windowMode == WindowMode.WindowMode.OVERVIEW && activeCollection) {
             Application.documentManager.activatePreviousCollection();
         } else {
@@ -234,10 +235,12 @@ const MainWindow = new Lang.Class({
         if (keyval == Gdk.KEY_Escape) {
             let model = preview.getModel();
 
-            if (preview.controlsVisible && (model != null))
+            if (preview.controlsVisible && (model != null)) {
                 preview.controlsVisible = false;
-            else if (fullscreen)
+            } else if (fullscreen) {
                 Application.documentManager.setActiveItem(null);
+                Application.modeController.goBack();
+            }
 
             return false;
         }
diff --git a/src/preview.js b/src/preview.js
index cf21cf4..78b1d8b 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -792,6 +792,7 @@ const PreviewToolbar = new Lang.Class({
         backButton.connect('clicked', Lang.bind(this,
             function() {
                 Application.documentManager.setActiveItem(null);
+                Application.modeController.goBack();
                 this._searchAction.enabled = true;
             }));
 
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]