[gnome-documents] window: switch back to the current query when going back from preview



commit 56365ded81201f78cb9bbaf6b4bb4da074358b76
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Jul 26 18:27:48 2011 +0200

    window: switch back to the current query when going back from preview

 src/mainToolbar.js  |   49 +++++++++++++++++++++++----------
 src/mainWindow.js   |   76 +++++++++++++++++++++++----------------------------
 src/trackerModel.js |    6 +++-
 3 files changed, 72 insertions(+), 59 deletions(-)
---
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index ac94d47..abadf93 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -25,14 +25,18 @@ const Gtk = imports.gi.Gtk;
 const _ = imports.gettext.gettext;
 
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
+const _SEARCH_ENTRY_TIMEOUT = 200;
+
 function MainToolbar() {
     this._init();
 }
 
 MainToolbar.prototype = {
     _init: function() {
+        this._searchEntryTimeout = 0;
         this._initGtkToolbar();
     },
 
@@ -47,7 +51,7 @@ MainToolbar.prototype = {
         }));
     },
 
-    _populateForOverview: function() {
+    _populateForOverview: function(filter) {
         let iconView = new Gtk.ToggleButton({ child: new Gtk.Image({ icon_name: 'view-grid-symbolic',
                                                                      pixel_size: 16 }) });
         iconView.get_style_context().add_class('linked');
@@ -75,34 +79,49 @@ MainToolbar.prototype = {
         item.set_expand(true);
         item.add(box);
 
-        this.searchEntry = new Gtk.Entry({ width_request: 260,
+        this._searchEntry = new Gtk.Entry({ width_request: 260,
                                            secondary_icon_name: 'edit-find-symbolic',
                                            secondary_icon_sensitive: false,
                                            secondary_icon_activatable: false });
         let item2 = new Gtk.ToolItem();
-        item2.add(this.searchEntry);
+        item2.add(this._searchEntry);
 
-        this.searchEntry.connect('changed', Lang.bind(this, function() {
-            let text = this.searchEntry.get_text();
+        this._searchEntry.connect('changed', Lang.bind(this, function() {
+            let text = this._searchEntry.get_text();
             if (text && text != '') {
-                this.searchEntry.secondary_icon_name = 'edit-clear-symbolic';
-                this.searchEntry.secondary_icon_sensitive = true;
-                this.searchEntry.secondary_icon_activatable = true;
+                this._searchEntry.secondary_icon_name = 'edit-clear-symbolic';
+                this._searchEntry.secondary_icon_sensitive = true;
+                this._searchEntry.secondary_icon_activatable = true;
             } else {
-                this.searchEntry.secondary_icon_name = 'edit-find-symbolic';
-                this.searchEntry.secondary_icon_sensitive = false;
-                this.searchEntry.secondary_icon_activatable = false;
+                this._searchEntry.secondary_icon_name = 'edit-find-symbolic';
+                this._searchEntry.secondary_icon_sensitive = false;
+                this._searchEntry.secondary_icon_activatable = false;
+            }
+
+            if (this._searchEntryTimeout != 0) {
+                Mainloop.source_remove(this._searchEntryTimeout);
+                this._searchEntryTimeout = 0;
             }
+
+            this._searchEntryTimeout = Mainloop.timeout_add(_SEARCH_ENTRY_TIMEOUT, Lang.bind(this, function() {
+                this._searchEntryTimeout = 0;
+
+                let currentText = this._searchEntry.get_text();
+                this.emit('search-text-changed', currentText);
+            }));
         }));
 
-        this.searchEntry.connect('icon-release', Lang.bind(this, function() {
-            this.searchEntry.set_text('');
+        this._searchEntry.connect('icon-release', Lang.bind(this, function() {
+            this._searchEntry.set_text('');
         }));
 
         this.widget.insert(item, 0);
         this.widget.insert(item2, 1);
 
         this.widget.show_all();
+
+        if (filter)
+            this._searchEntry.set_text(filter);
     },
 
     _populateForPreview: function(model, document) {
@@ -147,9 +166,9 @@ MainToolbar.prototype = {
         label.set_text(_("page %d of %d").format(curPage + 1, totPages));
     },
 
-    setOverview: function() {
+    setOverview: function(filter) {
         this._clearToolbar();
-        this._populateForOverview();
+        this._populateForOverview(filter);
     },
 
     setPreview: function(model, document) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index b332b85..d30052d 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -42,7 +42,6 @@ const _ = imports.gettext.gettext;
 const _WINDOW_DEFAULT_WIDTH = 768;
 const _WINDOW_DEFAULT_HEIGHT = 600;
 
-const _SEARCH_ENTRY_TIMEOUT = 200;
 const _PDF_LOADER_TIMEOUT = 300;
 
 function MainWindow() {
@@ -51,9 +50,9 @@ function MainWindow() {
 
 MainWindow.prototype = {
     _init: function() {
-        this._searchTimeout = 0;
         this._loaderTimeout = 0;
         this._loaderSignal = 0;
+        this._lastFilter = '';
 
         //TODO save this in GSettings?
         this._currentSourceId = 'all';
@@ -75,9 +74,8 @@ MainWindow.prototype = {
         this.window.add(this._grid);
 
         this._toolbar = new MainToolbar.MainToolbar();
-        this._toolbar.setOverview();
-        this._toolbar.searchEntry.connect('changed',
-                                          Lang.bind(this, this._onSearchEntryChanged));
+        this._toolbar.connect('search-text-changed',
+                              Lang.bind(this, this._onToolbarSearchChanged));
         this._toolbar.connect('back-clicked',
                               Lang.bind(this, this._onToolbarBackClicked));
 
@@ -94,7 +92,6 @@ MainWindow.prototype = {
                                                      vexpand: true});
         this._viewContainer.add(this._scrolledWin);
 
-        this._initView();
         this._grid.show_all();
 
         this._model = new TrackerModel.TrackerModel(Lang.bind(this, this._onModelCreated));
@@ -162,9 +159,35 @@ MainWindow.prototype = {
         this._toolbar.setPreview(model, document);
     },
 
+    _prepareForOverview: function() {
+        if (this._loaderSignal) {
+            this._pdfLoader.disconnect(this._loaderSignal);
+            this._loaderSignal = 0;
+        }
+
+        if (this._pdfLodaer) {
+            this._pdfLoader.cleanup_document();
+            this._pdfLoader = null;
+        }
+
+        if (this._preview) {
+            this._preview.destroy();
+            this._preview = null;
+        }
+
+        this._refreshViewSettings();
+
+        // needs to be called after _refreshViewSettings(), as that
+        // recreates the button
+        this._refreshLoadMoreButton(this._model.itemCount, this._model.offset);
+
+        this._sidebar.widget.show();
+        this._toolbar.setOverview(this._lastFilter);
+        this._model.populateForOverview(this._currentSourceId, this._lastFilter);
+    },
+
     _onModelCreated: function() {
-        this.view.setModel(this._model.model);
-        this._model.populateForOverview(this._currentSourceId);
+        this._prepareForOverview();
     },
 
     _onDeleteEvent: function() {
@@ -218,42 +241,11 @@ MainWindow.prototype = {
     },
 
     _onToolbarBackClicked: function() {
-        if (this._loaderSignal) {
-            this._pdfLoader.disconnect(this._loaderSignal);
-            this._loaderSignal = 0;
-        }
-
-        this._pdfLoader.cleanup_document();
-        this._pdfLoader = null;
-
-        if (this._preview) {
-            this._preview.destroy();
-            this._preview = null;
-        }
-
-        this._sidebar.widget.show();
-        this._toolbar.setOverview();
-
-        this._refreshViewSettings();
-        // needs to be called after _refreshViewSettings(), as that
-        // recreates the button
-        this._refreshLoadMoreButton(this._model.itemCount, this._model.offset);
+        this._prepareForOverview();
     },
 
-    _onSearchEntryChanged: function() {
-        if (this._searchTimeout != 0) {
-            Mainloop.source_remove(this._searchTimeout);
-            this._searchTimeout = 0;
-        }
-
-        this._searchTimeout = Mainloop.timeout_add(_SEARCH_ENTRY_TIMEOUT,
-                                                   Lang.bind(this, this._onSearchEntryTimeout));
-    },
-
-    _onSearchEntryTimeout: function() {
-        this._searchTimeout = 0;
-
-        let text = this._toolbar.searchEntry.get_text();
+    _onToolbarSearchChanged: function(toolbar, text) {
+        this._lastFilter = text;
         this._model.setFilter(text);
     },
 
diff --git a/src/trackerModel.js b/src/trackerModel.js
index 48d5749..5d19bd7 100644
--- a/src/trackerModel.js
+++ b/src/trackerModel.js
@@ -498,10 +498,12 @@ TrackerModel.prototype = {
                 }));
     },
 
-    populateForOverview: function(resourceUrn) {
+    populateForOverview: function(resourceUrn, filter) {
+        this.model.clear();
+
         this._resourceUrn = resourceUrn;
         this.offset = 0;
-        this._filter = '';
+        this._filter = filter;
 
         this._performCurrentQuery();
     },



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