[gnome-documents] Hide & restore search when moving to preview or collection view & back



commit 3a06e8a1e24ace588fa80fddc3b3c992e93bfd29
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Mar 17 20:26:51 2015 +0100

    Hide & restore search when moving to preview or collection view & back
    
    We should hide the search bar when viewing a search result (ie. the
    contents of a collection or previewing an item), and restore it when we
    come back.
    
    It is not clear whether the user is supposed to be able to search while
    viewing a collection, so we ignore that case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=746367

 src/embed.js       |   31 +++++++++++++++++++++++++++++++
 src/mainToolbar.js |    1 -
 src/search.js      |   13 ++++++++++++-
 3 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index a61668b..f65927b 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -80,6 +80,7 @@ const Embed = new Lang.Class({
     _init: function() {
         this._noResultsChangeId = 0;
         this._loadShowId = 0;
+        this._searchState = null;
 
         this.widget = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
                                     visible: true });
@@ -308,7 +309,37 @@ const Embed = new Lang.Class({
         }
     },
 
+    _restoreSearch: function() {
+        if (!this._searchState)
+            return;
+
+        Application.searchMatchManager.setActiveItem(this._searchState.searchMatch);
+        Application.searchTypeManager.setActiveItem(this._searchState.searchType);
+        Application.sourceManager.setActiveItem(this._searchState.source);
+        Application.searchController.setString(this._searchState.str);
+        this._searchState = null;
+    },
+
+    _saveSearch: function() {
+        if (this._searchState)
+            return;
+
+        this._searchState = new Search.SearchState(Application.searchMatchManager.getActiveItem(),
+                                                   Application.searchTypeManager.getActiveItem(),
+                                                   Application.sourceManager.getActiveItem(),
+                                                   Application.searchController.getString());
+    },
+
     _onActiveItemChanged: function(manager, doc) {
+        let windowMode = Application.modeController.getWindowMode();
+        let showSearch = (windowMode == WindowMode.WindowMode.PREVIEW && !doc
+                          || windowMode == WindowMode.WindowMode.SEARCH && !doc);
+        if (showSearch)
+            this._restoreSearch();
+        else
+            this._saveSearch();
+
+        Application.application.change_action_state('search', GLib.Variant.new('b', showSearch));
     },
 
     _clearLoadTimer: function() {
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 5b11481..295603f 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -243,7 +243,6 @@ const OverviewToolbar = new Lang.Class({
     _onActiveCollectionChanged: function() {
         this._checkCollectionWidgets();
         this._setToolbarTitle();
-        Application.application.change_action_state('search', GLib.Variant.new('b', false));
     },
 
     _populateForOverview: function() {
diff --git a/src/search.js b/src/search.js
index 190f185..cb23c00 100644
--- a/src/search.js
+++ b/src/search.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, 2014 Red Hat, Inc.
+ * Copyright (c) 2011, 2012, 2014, 2015 Red Hat, Inc.
  *
  * Gnome Documents is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by the
@@ -44,6 +44,17 @@ function initSearch(context) {
     context.queryBuilder = new Query.QueryBuilder(context);
 };
 
+const SearchState = new Lang.Class({
+    Name: 'SearchState',
+
+    _init: function(searchMatch, searchType, source, str) {
+        this.searchMatch = searchMatch;
+        this.searchType = searchType;
+        this.source = source;
+        this.str = str;
+    }
+});
+
 const SearchController = new Lang.Class({
     Name: 'SearchController',
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]