[gnome-documents] windowMode: Add goBack
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] windowMode: Add goBack
- Date: Thu, 19 Feb 2015 09:28:33 +0000 (UTC)
commit cf1a4173a75fafd73933a48b23cd64c8040cd8b4
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/embed.js | 4 ----
src/mainWindow.js | 7 +++++--
src/preview.js | 1 +
src/windowMode.js | 30 ++++++++++++++++++++++++------
5 files changed, 31 insertions(+), 13 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/embed.js b/src/embed.js
index 0b6546e..f3c1773 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -374,10 +374,6 @@ const Embed = new Lang.Class({
},
_onActiveItemChanged: function(manager, doc) {
- if (doc && !doc.collection)
- return;
-
- Application.modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
},
_clearLoadTimer: function() {
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]