[gnome-documents/wip/split-view: 4/15] windowMode: Add goBack
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/split-view: 4/15] windowMode: Add goBack
- Date: Fri, 17 Oct 2014 13:30:10 +0000 (UTC)
commit b47b10ee69f4113c922a7d6f0b90c9d1d37ffe38
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 | 33 +++++++++++++++++++++++++--------
2 files changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/src/edit.js b/src/edit.js
index b4b47f4..e361fb4 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -85,7 +85,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 3f90364..a8b5a02 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);
@@ -74,8 +92,7 @@ const ModeController = new Lang.Class({
},
setFullscreen: function(fullscreen) {
- if (this._mode != WindowMode.PREVIEW
- && this._mode != WindowMode.EDIT)
+ if (!this._canFullscreenPolicy(this._mode))
return;
if (this._fullscreen == fullscreen)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]