[gnome-documents/wip/split-view: 4/5] windowMode: Add goBack
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/split-view: 4/5] windowMode: Add goBack
- Date: Fri, 26 Sep 2014 07:09:12 +0000 (UTC)
commit bf97a33aa48b70b439f60754637af7e640e67d5d
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 | 43 +++++++++++++++++++++++++++++++++++--------
2 files changed, 36 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..87bdab7 100644
--- a/src/windowMode.js
+++ b/src/windowMode.js
@@ -40,6 +40,37 @@ const ModeController = new Lang.Class({
this._mode = WindowMode.NONE;
this._fullscreen = false;
this._canFullscreen = false;
+ this._history = [];
+ },
+
+ _canFullscreenPolicy: function(mode) {
+ let retval = false;
+
+ if (mode == WindowMode.PREVIEW
+ || mode == WindowMode.EDIT) {
+ retval = true;
+ }
+
+ return retval;
+ },
+
+ goBack: function() {
+ if (this._history.length == 0)
+ return;
+
+ let oldMode = this._history.pop();
+ if (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 +79,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 +102,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]