[gnome-documents/wip/split-view: 13/14] foo



commit 77c8afe9920779856a03c775297544fa426140ca
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Sep 26 09:06:41 2014 +0200

    foo

 src/embed.js      |   94 ++++++++++++++++++++++++++++++++++++++++++++++------
 src/view.js       |    2 +-
 src/windowMode.js |    6 ++-
 3 files changed, 88 insertions(+), 14 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 2056065..3fdc759 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;
@@ -231,8 +232,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');
@@ -273,6 +280,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();
@@ -341,10 +356,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)
@@ -426,20 +474,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/view.js b/src/view.js
index c84424b..929ff98 100644
--- a/src/view.js
+++ b/src/view.js
@@ -187,7 +187,7 @@ const ViewModel = new Lang.Class({
 const ViewContainer = new Lang.Class({
     Name: 'ViewContainer',
 
-    _init: function() {
+    _init: function(mode) {
         this._adjustmentValueId = 0;
         this._adjustmentChangedId = 0;
         this._scrollbarVisibleId = 0;
diff --git a/src/windowMode.js b/src/windowMode.js
index 76b3e9b..77ea4c6 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]