[gnome-characters] search-provider: Implement LaunchSearch
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters] search-provider: Implement LaunchSearch
- Date: Mon, 23 Feb 2015 08:17:39 +0000 (UTC)
commit fdc1ef7c3a16f74004eaa15c18c8c1495475ad4b
Author: Daiki Ueno <dueno src gnome org>
Date: Mon Feb 23 16:42:21 2015 +0900
search-provider: Implement LaunchSearch
src/main.js | 11 ++++++++++-
src/searchProvider.js | 39 +++++++++++++++++++++++++++++++++------
src/window.js | 5 +++++
3 files changed, 48 insertions(+), 7 deletions(-)
---
diff --git a/src/main.js b/src/main.js
index 53838d7..b10e67a 100644
--- a/src/main.js
+++ b/src/main.js
@@ -62,6 +62,12 @@ const MyApplication = new Lang.Class({
this.quit();
},
+ _onSearch: function(action, parameter) {
+ let window = new Window.MainWindow({ application: this });
+ window.setSearchKeywords(parameter.get_strv());
+ window.show();
+ },
+
_initAppMenu: function() {
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Characters/app-menu.ui');
@@ -77,7 +83,10 @@ const MyApplication = new Lang.Class({
Util.initActions(this,
[{ name: 'quit',
- activate: this._onQuit }]);
+ activate: this._onQuit },
+ { name: 'search',
+ activate: this._onSearch,
+ parameter_type: new GLib.VariantType('as') }]);
this._initAppMenu();
settings = Util.getSettings('org.gnome.Characters',
diff --git a/src/searchProvider.js b/src/searchProvider.js
index 76bc4b4..7f3df75 100644
--- a/src/searchProvider.js
+++ b/src/searchProvider.js
@@ -106,10 +106,6 @@ const SearchProvider = new Lang.Class({
return ret;
},
- _getPlatformData: function(timestamp) {
- return {'desktop-startup-id': new GLib.Variant('s', '_TIME' + timestamp) };
- },
-
ActivateResult: function(id, terms, timestamp) {
let clipboard = Gc.gtk_clipboard_get();
// FIXME: GLib.unichar_to_utf8() has missing (nullable)
@@ -119,7 +115,38 @@ const SearchProvider = new Lang.Class({
clipboard.set_text(id, length);
},
- LaunchSearch: function(terms, timestamp) {
- // not implemented
+ _getPlatformData: function(timestamp) {
+ return {'desktop-startup-id': new GLib.Variant('s', '_TIME' + timestamp) };
+ },
+
+ _activateAction: function(action, parameter, timestamp) {
+ let wrappedParam;
+ if (parameter)
+ wrappedParam = [parameter];
+ else
+ wrappedParam = [];
+
+ Gio.DBus.session.call('org.gnome.Characters',
+ '/org/gnome/Characters',
+ 'org.freedesktop.Application',
+ 'ActivateAction',
+ new GLib.Variant('(sava{sv})', [action, wrappedParam,
+ this._getPlatformData(timestamp)]),
+ null,
+ Gio.DBusCallFlags.NONE,
+ -1, null, Lang.bind(this, function(connection, result) {
+ try {
+ connection.call_finish(result);
+ } catch(e) {
+ log('Failed to launch application: ' + e);
+ }
+
+ this._app.release();
+ }));
},
+
+ LaunchSearch: function(terms, timestamp) {
+ this._activateAction('search', new GLib.Variant('as', terms),
+ timestamp);
+ }
});
diff --git a/src/window.js b/src/window.js
index 9870354..9b2bb02 100644
--- a/src/window.js
+++ b/src/window.js
@@ -215,6 +215,11 @@ const MainWindow = new Lang.Class({
this._filterFontFamily = family;
this._updateTitle(this._mainView.visible_child.title);
},
+
+ setSearchKeywords: function(keywords) {
+ this.search_active = keywords.length > 0;
+ this._search_entry.set_text(keywords.join(' '));
+ }
});
const MainView = new Lang.Class({
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]