[gnome-documents] application: don't immediately forward search terms on item launch



commit bba711368dd672877fad080749291feaf740f5de
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Apr 1 17:23:54 2013 -0400

    application: don't immediately forward search terms on item launch
    
    When an item is launched from a shell search, we also set the search
    string to the terms that were used.
    Instead of doing so immediately, wait until the next overview state
    change, since setString() will clear DocumentManager, and we have no
    guarantees on the order clear and load will happen.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697034

 src/application.js |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 4e6b209..f05341a 100644
--- a/src/application.js
+++ b/src/application.js
@@ -529,23 +529,37 @@ const Application = new Lang.Class({
     _onActivateResult: function(provider, urn, terms, timestamp) {
         this._createWindow();
         modeController.setWindowMode(WindowMode.WindowMode.PREVIEW);
-        this._activationTimestamp = timestamp;
-        this.activate();
-
-        searchController.setString(terms.join(' '));
 
         let doc = documentManager.getItemById(urn);
         if (doc) {
-            documentManager.setActiveItem(doc);
+            doActivate.apply(this, [doc]);
         } else {
             let job = new TrackerUtils.SingleItemJob(urn, queryBuilder);
             job.run(Query.QueryFlags.UNFILTERED, Lang.bind(this,
                 function(cursor) {
-                    if (!cursor)
+                    if (cursor)
+                        doc = documentManager.addDocumentFromCursor(cursor);
+
+                    doActivate.apply(this, [doc]);
+                }));
+        }
+
+        function doActivate(doc) {
+            documentManager.setActiveItem(doc);
+
+            this._activationTimestamp = timestamp;
+            this.activate();
+
+            // 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)
                         return;
 
-                    let doc = documentManager.addDocumentFromCursor(cursor);
-                    documentManager.setActiveItem(doc);
+                    modeController.disconnect(modeChangeId);
+
+                    searchController.setString(terms.join(' '));
+                    this.change_action_state('search', GLib.Variant.new('b', true));
                 }));
         }
     },


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