[gnome-documents/wip/rishi/split-view: 11/11] foo
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/rishi/split-view: 11/11] foo
- Date: Thu, 19 Feb 2015 18:10:56 +0000 (UTC)
commit ff98abbed3fe035c8fc4bc9d3d4c461e6cad6dbb
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Sep 26 09:06:41 2014 +0200
foo
src/application.js | 31 ++++++++---
src/documents.js | 1 +
src/embed.js | 154 +++++++++++++++++++++++++++++++++++++++++++++-------
src/mainWindow.js | 8 ++-
src/view.js | 90 ++++++++++++++++++++++++-------
src/windowMode.js | 6 ++-
6 files changed, 237 insertions(+), 53 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 5e4d8da..98ef009 100644
--- a/src/application.js
+++ b/src/application.js
@@ -527,7 +527,9 @@ const Application = new Lang.Class({
create_hook: this._viewAsCreateHook,
parameter_type: 's',
state: settings.get_value('view-as'),
- window_mode: WindowMode.WindowMode.OVERVIEW },
+ window_modes: [WindowMode.WindowMode.COLLECTIONS,
+ WindowMode.WindowMode.DOCUMENTS,
+ WindowMode.WindowMode.SEARCH] },
{ name: 'open-current',
callback: this._onActionOpenCurrent,
window_mode: WindowMode.WindowMode.PREVIEW },
@@ -559,9 +561,13 @@ const Application = new Lang.Class({
{ name: 'rotate-right', accel: '<Primary>Right',
window_mode: WindowMode.WindowMode.PREVIEW },
{ name: 'select-all', accel: '<Primary>a',
- window_mode: WindowMode.WindowMode.OVERVIEW },
+ window_modes: [WindowMode.WindowMode.COLLECTIONS,
+ WindowMode.WindowMode.DOCUMENTS,
+ WindowMode.WindowMode.SEARCH] },
{ name: 'select-none',
- window_mode: WindowMode.WindowMode.OVERVIEW },
+ window_modes: [WindowMode.WindowMode.COLLECTIONS,
+ WindowMode.WindowMode.DOCUMENTS,
+ WindowMode.WindowMode.SEARCH] },
{ name: 'properties',
callback: this._onActionProperties,
window_mode: WindowMode.WindowMode.PREVIEW },
@@ -579,15 +585,21 @@ const Application = new Lang.Class({
{ name: 'search-source',
parameter_type: 's',
state: GLib.Variant.new('s', Search.SearchSourceStock.ALL),
- window_mode: WindowMode.WindowMode.OVERVIEW },
+ window_modes: [WindowMode.WindowMode.COLLECTIONS,
+ WindowMode.WindowMode.DOCUMENTS,
+ WindowMode.WindowMode.SEARCH] },
{ name: 'search-type',
parameter_type: 's',
state: GLib.Variant.new('s', Search.SearchTypeStock.ALL),
- window_mode: WindowMode.WindowMode.OVERVIEW },
+ window_modes: [WindowMode.WindowMode.COLLECTIONS,
+ WindowMode.WindowMode.DOCUMENTS,
+ WindowMode.WindowMode.SEARCH] },
{ name: 'search-match',
parameter_type: 's',
state: GLib.Variant.new('s', Search.SearchMatchStock.ALL),
- window_mode: WindowMode.WindowMode.OVERVIEW }
+ window_modes: [WindowMode.WindowMode.COLLECTIONS,
+ WindowMode.WindowMode.DOCUMENTS,
+ WindowMode.WindowMode.SEARCH] }
];
this.gdataMiner = new Miners.GDataMiner();
@@ -637,7 +649,7 @@ const Application = new Lang.Class({
vfunc_activate: function() {
if (!this._mainWindow) {
this._createWindow();
- modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
+ modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
}
this._mainWindow.window.present_with_time(this._activationTimestamp);
@@ -706,7 +718,8 @@ const Application = new Lang.Class({
// forward the search terms next time we enter the overview
let modeChangeId = modeController.connect('window-mode-changed', Lang.bind(this,
function(object, newMode) {
- if (newMode != WindowMode.WindowMode.OVERVIEW)
+ if (newMode == WindowMode.WindowMode.EDIT
+ || newMode == WindowMode.WindowMode.PREVIEW)
return;
modeController.disconnect(modeChangeId);
@@ -719,7 +732,7 @@ const Application = new Lang.Class({
_onLaunchSearch: function(provider, terms, timestamp) {
this._createWindow();
- modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
+ modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
searchController.setString(terms.join(' '));
this.change_action_state('search', GLib.Variant.new('b', true));
diff --git a/src/documents.js b/src/documents.js
index 4d39b79..a25098f 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -241,6 +241,7 @@ const DocCommon = new Lang.Class({
this.typeDescription = null;
this.sourceName = null;
+ this.rowRefs = {};
this.shared = false;
this.collection = false;
diff --git a/src/embed.js b/src/embed.js
index 1a56c79..4433359 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -28,6 +28,7 @@ const Notifications = imports.notifications;
const Password = imports.password;
const Preview = imports.preview;
const Edit = imports.edit;
+const Search = imports.search;
const Selections = imports.selections;
const View = imports.view;
const WindowMode = imports.windowMode;
@@ -104,8 +105,14 @@ const Embed = new Lang.Class({
this._stackOverlay.add_overlay(Application.notificationManager.widget);
// now create the actual content widgets
- this._view = new View.ViewContainer();
- this._stack.add_named(this._view.widget, 'view');
+ this._documents = new View.ViewContainer(WindowMode.WindowMode.DOCUMENTS);
+ this._stack.add_titled(this._documents.widget, 'documents', _("Recent"));
+
+ this._collections = new View.ViewContainer(WindowMode.WindowMode.COLLECTIONS);
+ this._stack.add_titled(this._collections.widget, 'collections', _("Collections"));
+
+ this._search = new View.ViewContainer(WindowMode.WindowMode.SEARCH);
+ this._stack.add_named(this._search.widget, 'search');
this._preview = new Preview.PreviewView(this._stackOverlay);
this._stack.add_named(this._preview.widget, 'preview');
@@ -135,6 +142,14 @@ const Embed = new Lang.Class({
Application.documentManager.connect('password-needed',
Lang.bind(this, this._onPasswordNeeded));
+ Application.searchTypeManager.connect('active-changed',
+ Lang.bind(this, this._onSearchChanged));
+ Application.sourceManager.connect('active-changed',
+ Lang.bind(this, this._onSearchChanged));
+
+ Application.searchController.connect('search-string-changed',
+ Lang.bind(this, this._onSearchChanged));
+
this._onQueryStatusChanged();
let windowMode = Application.modeController.getWindowMode();
@@ -142,20 +157,62 @@ const Embed = new Lang.Class({
this._onWindowModeChanged(Application.modeController, windowMode, WindowMode.WindowMode.NONE);
},
+ _getViewFromMode: function(windowMode) {
+ let view;
+
+ switch (windowMode) {
+ case WindowMode.WindowMode.COLLECTIONS:
+ view = this._collections;
+ break;
+ case WindowMode.WindowMode.DOCUMENTS:
+ view = this._documents;
+ break;
+ case WindowMode.WindowMode.PREVIEW:
+ view = this._preview;
+ break;
+ case WindowMode.WindowMode.SEARCH:
+ view = this._search;
+ break;
+ default:
+ throw(new Error('Not handled'));
+ break;
+ }
+
+ return view;
+ },
+
_onActivateResult: function() {
let windowMode = Application.modeController.getWindowMode();
-
- if (windowMode == WindowMode.WindowMode.OVERVIEW)
- this._view.activateResult();
- else if (windowMode == WindowMode.WindowMode.PREVIEW)
- this._preview.activateResult();
+ let view = this._getViewFromMode(mode);
+ view.activateResult();
},
- _onQueryStatusChanged: function() {
+ _restoreLastPage: function() {
+ let page;
let windowMode = Application.modeController.getWindowMode();
- if (windowMode != WindowMode.WindowMode.OVERVIEW)
- return;
+ switch (windowMode) {
+ case WindowMode.WindowMode.COLLECTIONS:
+ page = 'collections';
+ break;
+ case WindowMode.WindowMode.DOCUMENTS:
+ page = 'documents';
+ break;
+ case WindowMode.WindowMode.PREVIEW:
+ page = 'preview';
+ break;
+ case WindowMode.WindowMode.SEARCH:
+ page = 'search';
+ break;
+ default:
+ throw(new Error('Not handled'));
+ break;
+ }
+
+ this._stack.set_visible_child_name(page);
+ },
+
+ _onQueryStatusChanged: function() {
let queryStatus = Application.trackerDocumentsController.getQueryStatus();
if (queryStatus) {
@@ -163,7 +220,7 @@ const Embed = new Lang.Class({
this._stack.set_visible_child_name('spinner');
} else {
this._spinnerBox.stop();
- this._stack.set_visible_child_name('view');
+ this._restoreLastPage();
}
},
@@ -172,10 +229,43 @@ const Embed = new Lang.Class({
this._toolbar.widget.sensitive = !fullscreen;
},
+ _onSearchChanged: function() {
+ // Whenever a search constraint is specified we want to switch to
+ // the search mode, and when all constraints have been lifted we
+ // want to go back to the previous mode which can be either
+ // collections or documents.
+ //
+ // However there are some exceptions, which are taken care of
+ // elsewhere:
+ // - when moving from search to preview or collection view
+ // - when in preview or coming out of it
+
+ let doc = Application.documentManager.getActiveItem();
+ let windowMode = Application.modeController.getWindowMode();
+ if (windowMode == WindowMode.WindowMode.SEARCH && doc)
+ return;
+ if (windowMode == WindowMode.WindowMode.PREVIEW)
+ return;
+
+ let searchType = Application.searchTypeManager.getActiveItem();
+ let source = Application.sourceManager.getActiveItem();
+ let str = Application.searchController.getString();
+
+ if (searchType.id == Search.SearchTypeStock.ALL &&
+ source.id == Search.SearchSourceStock.ALL &&
+ (!str || str == '')) {
+ Application.modeController.goBack();
+ } else {
+ Application.modeController.setWindowMode(WindowMode.WindowMode.SEARCH);
+ }
+ },
+
_onWindowModeChanged: function(object, newMode, oldMode) {
switch (newMode) {
- case WindowMode.WindowMode.OVERVIEW:
- this._prepareForOverview();
+ case WindowMode.WindowMode.COLLECTIONS:
+ case WindowMode.WindowMode.DOCUMENTS:
+ case WindowMode.WindowMode.SEARCH:
+ this._prepareForOverview(newMode, oldMode);
break;
case WindowMode.WindowMode.PREVIEW:
if (oldMode == WindowMode.WindowMode.EDIT)
@@ -255,20 +345,44 @@ const Embed = new Lang.Class({
}));
},
- _prepareForOverview: function() {
+ _prepareForOverview: function(newMode, oldMode) {
+ let createToolbar = (oldMode != WindowMode.WindowMode.COLLECTIONS &&
+ oldMode != WindowMode.WindowMode.DOCUMENTS &&
+ oldMode != WindowMode.WindowMode.SEARCH);
+
+ let visibleChildName;
+
+ switch (newMode) {
+ case WindowMode.WindowMode.COLLECTIONS:
+ visibleChildName = 'collections';
+ break;
+ case WindowMode.WindowMode.DOCUMENTS:
+ visibleChildName = 'documents';
+ break;
+ case WindowMode.WindowMode.SEARCH:
+ visibleChildName = 'search';
+ break;
+ default:
+ throw(new Error('Not handled'));
+ break;
+ }
+
if (this._preview)
this._preview.reset();
if (this._edit)
this._edit.setUri(null);
- if (this._toolbar)
- this._toolbar.widget.destroy();
- // pack the toolbar
- this._toolbar = new MainToolbar.OverviewToolbar(this._stackOverlay, this._stack);
- this._titlebar.add(this._toolbar.widget);
+ if (createToolbar) {
+ if (this._toolbar)
+ this._toolbar.widget.destroy();
+
+ // pack the toolbar
+ this._toolbar = new MainToolbar.OverviewToolbar(this._stackOverlay, this._stack);
+ this._titlebar.add(this._toolbar.widget);
+ }
this._spinnerBox.stop();
- this._stack.set_visible_child_name('view');
+ this._stack.set_visible_child_name(visibleChildName);
},
_prepareForPreview: function() {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index e1ac236..1c4f80e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -154,6 +154,7 @@ const MainWindow = new Lang.Class({
switch (windowMode) {
case WindowMode.WindowMode.NONE:
+ case WindowMode.WindowMode.DOCUMENTS:
handled = false;
break;
case WindowMode.WindowMode.EDIT:
@@ -161,7 +162,8 @@ const MainWindow = new Lang.Class({
Application.documentManager.setActiveItem(null);
Application.modeController.goBack();
break;
- case WindowMode.WindowMode.OVERVIEW:
+ case WindowMode.WindowMode.COLLECTIONS:
+ case WindowMode.WindowMode.SEARCH:
if (activeCollection)
Application.documentManager.activatePreviousCollection();
break;
@@ -200,7 +202,9 @@ const MainWindow = new Lang.Class({
return false;
case WindowMode.WindowMode.PREVIEW:
return this._handleKeyPreview(event);
- case WindowMode.WindowMode.OVERVIEW:
+ case WindowMode.WindowMode.COLLECTIONS:
+ case WindowMode.WindowMode.DOCUMENTS:
+ case WindowMode.WindowMode.SEARCH:
return this._handleKeyOverview(event);
case WindowMode.WindowMode.EDIT:
return false;
diff --git a/src/view.js b/src/view.js
index fd418ec..a39414c 100644
--- a/src/view.js
+++ b/src/view.js
@@ -82,31 +82,34 @@ const ViewModel = new Lang.Class({
this._resetCountId = 0;
+ this._mode = windowMode;
+ this._rowRefKey = "row-ref-" + this._mode;
+
Application.documentManager.connect('item-added',
Lang.bind(this, this._onItemAdded));
Application.documentManager.connect('item-removed',
Lang.bind(this, this._onItemRemoved));
- [ this._offsetController, this._trackerController ] = getController(windowMode);
+ [ this._offsetController, this._trackerController ] = getController(this._mode);
this._trackerController.connect('query-status-changed', Lang.bind(this,
function(o, status) {
if (!status)
return;
this._clear();
}));
+ },
- // populate with the intial items
+ _clear: function() {
let items = Application.documentManager.getItems();
for (let idx in items) {
- this._onItemAdded(null, items[idx]);
+ let doc = items[idx];
+ doc.rowRefs[this._rowRefKey] = null;
}
- },
- _clear: function() {
this.model.clear();
},
- _onItemAdded: function(source, doc) {
+ _addItem: function(doc) {
// Update the count so that OffsetController has the correct
// values. Otherwise things like loading more items and "No
// Results" page will not work correctly.
@@ -120,23 +123,12 @@ const ViewModel = new Lang.Class({
let treePath = this.model.get_path(iter);
let treeRowRef = Gtk.TreeRowReference.new(this.model, treePath);
+ doc.rowRefs[this._rowRefKey] = treeRowRef;
- doc.connect('info-updated', Lang.bind(this,
- function() {
- let objectPath = treeRowRef.get_path();
- if (!objectPath)
- return;
-
- let objectIter = this.model.get_iter(objectPath)[1];
- if (objectIter)
- this.model.set(objectIter,
- [ 0, 1, 2, 3, 4, 5 ],
- [ doc.id, doc.uri, doc.name,
- doc.author, doc.surface, doc.mtime ]);
- }));
+ doc.connect('info-updated', Lang.bind(this, this._onInfoUpdated));
},
- _onItemRemoved: function(source, doc) {
+ _removeItem: function(doc) {
// Update the count so that OffsetController has the correct
// values. Otherwise things like loading more items and "No
// Results" page will not work correctly.
@@ -153,6 +145,64 @@ const ViewModel = new Lang.Class({
return false;
}));
+
+ doc.rowRefs[this._rowRefKey] = null;
+ },
+
+ _onInfoUpdated: function(doc) {
+ let activeCollection = Application.documentManager.getActiveCollection();
+ let treeRowRef = doc.rowRefs[this._rowRefKey];
+
+ if (this._mode == WindowMode.WindowMode.COLLECTIONS) {
+ if (!doc.collection && treeRowRef && !activeCollection) {
+ ;
+ } else if (doc.collection && !treeRowRef && !activeCollection) {
+ this._addItem(doc);
+ }
+ } else if (this._mode == WindowMode.WindowMode.DOCUMENTS) {
+ if (doc.collection && treeRowRef) {
+ ;
+ } else if (!doc.collection && !treeRowRef) {
+ this._addItem(doc);
+ }
+ }
+
+ treeRowRef = doc.rowRefs[this._rowRefKey];
+ if (treeRowRef) {
+ let objectPath = treeRowRef.get_path();
+ if (!objectPath)
+ return;
+
+ let objectIter = this.model.get_iter(objectPath)[1];
+ if (objectIter)
+ this.model.set(objectIter,
+ [ 0, 1, 2, 3, 4, 5 ],
+ [ doc.id, doc.uri, doc.name,
+ doc.author, doc.surface, doc.mtime ]);
+ }
+ },
+
+ _onItemAdded: function(source, doc) {
+ if (doc.rowRefs[this._rowRefKey])
+ return;
+
+ let activeCollection = Application.documentManager.getActiveCollection();
+ let windowMode = Application.modeController.getWindowMode();
+
+ if (!activeCollection || this._mode != windowMode) {
+ if (this._mode == WindowMode.WindowMode.COLLECTIONS && !doc.collection
+ || this._mode == WindowMode.WindowMode.DOCUMENTS && doc.collection) {
+ doc.connect('info-updated', Lang.bind(this, this._onInfoUpdated));
+ return;
+ }
+ }
+
+ this._addItem(doc);
+ doc.connect('info-updated', Lang.bind(this, this._onInfoUpdated));
+ },
+
+ _onItemRemoved: function(source, doc) {
+ this._removeItem(doc);
},
_resetCount: function() {
diff --git a/src/windowMode.js b/src/windowMode.js
index 6959386..4dfa9aa 100644
--- a/src/windowMode.js
+++ b/src/windowMode.js
@@ -28,9 +28,11 @@ const Application = imports.application;
const WindowMode = {
NONE: 0,
- OVERVIEW: 1,
+ DOCUMENTS: 1,
PREVIEW: 2,
- EDIT: 3
+ EDIT: 3,
+ COLLECTIONS: 4,
+ SEARCH: 5
};
const ModeController = new Lang.Class({
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]