[gnome-documents/wip/provider-v2] search-provider: implement org.gnome.Shell.SearchProvider2



commit 80d923057a847eefd9724d9624e399918e457534
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Dec 9 14:29:16 2012 -0500

    search-provider: implement org.gnome.Shell.SearchProvider2

 data/gnome-documents-search-provider.ini |    1 +
 src/application.js                       |   12 +++++++++++-
 src/preview.js                           |    6 +++---
 src/searchbar.js                         |   29 +++++++++++++++++++++++------
 src/shellSearchProvider.js               |   15 ++++++++++++---
 5 files changed, 50 insertions(+), 13 deletions(-)
---
diff --git a/data/gnome-documents-search-provider.ini b/data/gnome-documents-search-provider.ini
index 95c3b9f..cc80866 100644
--- a/data/gnome-documents-search-provider.ini
+++ b/data/gnome-documents-search-provider.ini
@@ -2,3 +2,4 @@
 DesktopId=gnome-documents.desktop
 BusName=org.gnome.Documents.SearchProvider
 ObjectPath=/org/gnome/Documents/SearchProvider
+Version=2
\ No newline at end of file
diff --git a/src/application.js b/src/application.js
index 4a716e4..7f3253b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -315,6 +315,7 @@ const Application = new Lang.Class({
         connectionQueue = new TrackerController.TrackerConnectionQueue();
         this._searchProvider = new ShellSearchProvider.ShellSearchProvider();
         this._searchProvider.connect('activate-result', Lang.bind(this, this._onActivateResult));
+        this._searchProvider.connect('launch-search', Lang.bind(this, this._onLaunchSearch));
 
         // now init application components
         Search.initSearch(imports.application);
@@ -431,7 +432,7 @@ const Application = new Lang.Class({
         notificationManager = null;
     },
 
-    _onActivateResult: function(provider, urn) {
+    _onActivateResult: function(provider, urn, terms) {
         this._createWindow();
         modeController.setWindowMode(WindowMode.WindowMode.PREVIEW);
         this.activate();
@@ -450,6 +451,15 @@ const Application = new Lang.Class({
                     documentManager.setActiveItem(doc);
                 }));
         }
+    },
+
+    _onLaunchSearch: function(provider, terms) {
+        this._createWindow();
+        modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
+        searchController.setString(terms.join(' '));
+        this.change_action_state('search', GLib.Variant.new('b', true));
+
+        this.activate();
     }
 });
 Utils.addJSSignalMethods(Application.prototype);
diff --git a/src/preview.js b/src/preview.js
index eaa8860..ffe817a 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -443,10 +443,10 @@ const PreviewSearchbar = new Lang.Class({
     Extends: Searchbar.Searchbar,
 
     _init: function(previewView) {
-        this.parent();
-
-        this._lastText = '';
         this._previewView = previewView;
+        this._lastText = '';
+
+        this.parent();
     },
 
     createSearchWidgets: function() {
diff --git a/src/searchbar.js b/src/searchbar.js
index 47d524d..3d8e772 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -90,15 +90,20 @@ const Searchbar = new Lang.Class({
             }));
 
         // connect to the search action state for visibility
-        let searchStateId = Application.application.connect('action-state-changed::search', Lang.bind(this,
-            function(source, actionName, state) {
-                if (state.get_boolean())
-                    this.show();
-                else
-                    this.hide();
+        let searchStateId = Application.application.connect('action-state-changed::search',
+            Lang.bind(this, this._onActionStateChanged));
+        this._onActionStateChanged(Application.application, 'search', Application.application.get_action_state('search'));
+
+        // connect to search string changes in the controller
+        this._searchEntry.text = Application.searchController.getString();
+        let searchChangedId = Application.searchController.connect('search-string-changed', Lang.bind(this,
+            function(controller, string) {
+                this._searchEntry.text = string;
             }));
+
         this.widget.connect('destroy', Lang.bind(this,
             function() {
+                Application.searchController.disconnect(searchChangedId);
                 Application.application.disconnect(searchStateId);
                 Application.application.change_action_state('search', GLib.Variant.new('b', false));
             }));
@@ -106,6 +111,13 @@ const Searchbar = new Lang.Class({
         this.widget.show_all();
     },
 
+    _onActionStateChanged: function(source, actionName, state) {
+        if (state.get_boolean())
+            this.show();
+        else
+            this.hide();
+    },
+
     createSearchWidgets: function() {
         log('Error: Searchbar implementations must override createSearchWidgets');
     },
@@ -192,6 +204,11 @@ const Searchbar = new Lang.Class({
 
     show: function() {
         let eventDevice = Gtk.get_current_event_device();
+        if (!eventDevice) {
+            let manager = this.widget.get_display().get_device_manager();
+            eventDevice = manager.get_client_pointer();
+        }
+
         this._searchEntry.show();
 
         Tweener.addTween(this.actor, { height: this.widget.get_preferred_height()[1],
diff --git a/src/shellSearchProvider.js b/src/shellSearchProvider.js
index 070939e..473c348 100644
--- a/src/shellSearchProvider.js
+++ b/src/shellSearchProvider.js
@@ -47,7 +47,7 @@ let searchTypeManager = null;
 let searchController = null;
 let sourceManager = null;
 
-const SEARCH_PROVIDER_IFACE = 'org.gnome.Shell.SearchProvider';
+const SEARCH_PROVIDER_IFACE = 'org.gnome.Shell.SearchProvider2';
 const SEARCH_PROVIDER_NAME  = 'org.gnome.Documents.SearchProvider';
 const SEARCH_PROVIDER_PATH  = '/org/gnome/Documents/SearchProvider';
 
@@ -69,6 +69,11 @@ const SearchProviderIface = <interface name={SEARCH_PROVIDER_IFACE}>
 </method>
 <method name = "ActivateResult">
   <arg type="s" direction="in" />
+  <arg type="as" direction="in" />
+  <arg type="u" direction="in" />
+</method>
+<method name = "LaunchSearch">
+  <arg type="as" direction="in" />
 </method>
 </interface>;
 
@@ -454,8 +459,12 @@ const ShellSearchProvider = new Lang.Class({
         }
     },
 
-    ActivateResult: function(id) {
-        this.emit('activate-result', id);
+    ActivateResult: function(id, timestamp, terms) {
+        this.emit('activate-result', id, terms);
+    },
+
+    LaunchSearch: function(terms) {
+        this.emit('launch-search', terms);
     }
 });
 Signals.addSignalMethods(ShellSearchProvider.prototype);



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