2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-11-29 17:45:30 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, Gio, GLib, GObject, Shell, St } = imports.gi;
|
2009-11-29 17:45:30 -05:00
|
|
|
const Signals = imports.signals;
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2013-10-30 12:38:46 -04:00
|
|
|
const AppDisplay = imports.ui.appDisplay;
|
2013-10-29 15:49:05 -04:00
|
|
|
const IconGrid = imports.ui.iconGrid;
|
|
|
|
const Main = imports.ui.main;
|
2013-10-30 12:38:46 -04:00
|
|
|
const RemoteSearch = imports.ui.remoteSearch;
|
2013-10-29 15:49:05 -04:00
|
|
|
const Util = imports.misc.util;
|
2011-01-17 16:38:47 -05:00
|
|
|
|
2012-11-01 10:33:40 -04:00
|
|
|
const SEARCH_PROVIDERS_SCHEMA = 'org.gnome.desktop.search-providers';
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var MAX_LIST_SEARCH_RESULTS_ROWS = 5;
|
|
|
|
var MAX_GRID_SEARCH_RESULTS_ROWS = 1;
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2018-11-24 16:33:05 -05:00
|
|
|
var MaxWidthBox = GObject.registerClass(
|
|
|
|
class MaxWidthBox extends St.BoxLayout {
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_allocate(box, flags) {
|
2013-10-29 15:49:05 -04:00
|
|
|
let themeNode = this.get_theme_node();
|
|
|
|
let maxWidth = themeNode.get_max_width();
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let adjustedBox = box;
|
|
|
|
|
|
|
|
if (availWidth > maxWidth) {
|
|
|
|
let excessWidth = availWidth - maxWidth;
|
|
|
|
adjustedBox.x1 += Math.floor(excessWidth / 2);
|
|
|
|
adjustedBox.x2 -= Math.floor(excessWidth / 2);
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
super.vfunc_allocate(adjustedBox, flags);
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var SearchResult = class {
|
|
|
|
constructor(provider, metaInfo, resultsView) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.provider = provider;
|
|
|
|
this.metaInfo = metaInfo;
|
2017-06-27 17:58:07 -04:00
|
|
|
this._resultsView = resultsView;
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this.actor = new St.Button({ reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
track_hover: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_fill: true });
|
|
|
|
|
|
|
|
this.actor._delegate = this;
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('clicked', this.activate.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activate() {
|
2013-02-08 19:04:24 -05:00
|
|
|
this.emit('activate', this.metaInfo.id);
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-02-08 19:04:24 -05:00
|
|
|
Signals.addSignalMethods(SearchResult.prototype);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var ListSearchResult = class extends SearchResult {
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
constructor(provider, metaInfo, resultsView) {
|
|
|
|
super(provider, metaInfo, resultsView);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this.actor.style_class = 'list-search-result';
|
|
|
|
this.actor.x_fill = true;
|
|
|
|
|
|
|
|
let content = new St.BoxLayout({ style_class: 'list-search-result-content',
|
|
|
|
vertical: false });
|
|
|
|
this.actor.set_child(content);
|
|
|
|
|
2017-06-27 18:01:13 -04:00
|
|
|
this._termsChangedId = 0;
|
|
|
|
|
2017-06-20 15:13:48 -04:00
|
|
|
let titleBox = new St.BoxLayout({ style_class: 'list-search-result-title' });
|
|
|
|
|
|
|
|
content.add(titleBox, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
// An icon for, or thumbnail of, content
|
|
|
|
let icon = this.metaInfo['createIcon'](this.ICON_SIZE);
|
|
|
|
if (icon) {
|
2017-06-20 15:13:48 -04:00
|
|
|
titleBox.add(icon);
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
|
|
|
|
2017-06-20 15:13:48 -04:00
|
|
|
let title = new St.Label({ text: this.metaInfo['name'] });
|
|
|
|
titleBox.add(title, { x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2017-07-12 19:51:59 -04:00
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
this.actor.label_actor = title;
|
|
|
|
|
|
|
|
if (this.metaInfo['description']) {
|
2017-06-27 18:01:13 -04:00
|
|
|
this._descriptionLabel = new St.Label({ style_class: 'list-search-result-description' });
|
|
|
|
content.add(this._descriptionLabel, { x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2017-06-20 15:13:48 -04:00
|
|
|
|
2017-06-27 18:01:13 -04:00
|
|
|
this._termsChangedId =
|
|
|
|
this._resultsView.connect('terms-changed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._highlightTerms.bind(this));
|
2017-06-27 18:01:13 -04:00
|
|
|
|
|
|
|
this._highlightTerms();
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
2017-06-27 18:01:13 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get ICON_SIZE() {
|
|
|
|
return 24;
|
|
|
|
}
|
2017-06-27 18:01:13 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_highlightTerms() {
|
2017-07-09 12:25:49 -04:00
|
|
|
let markup = this._resultsView.highlightTerms(this.metaInfo['description'].split('\n')[0]);
|
2017-06-27 18:01:13 -04:00
|
|
|
this._descriptionLabel.clutter_text.set_markup(markup);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-06-27 18:01:13 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy() {
|
2017-06-27 18:01:13 -04:00
|
|
|
if (this._termsChangedId)
|
|
|
|
this._resultsView.disconnect(this._termsChangedId);
|
|
|
|
this._termsChangedId = 0;
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var GridSearchResult = class extends SearchResult {
|
|
|
|
constructor(provider, metaInfo, resultsView) {
|
|
|
|
super(provider, metaInfo, resultsView);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this.actor.style_class = 'grid-search-result';
|
|
|
|
|
2014-08-20 12:39:02 -04:00
|
|
|
this.icon = new IconGrid.BaseIcon(this.metaInfo['name'],
|
|
|
|
{ createIcon: this.metaInfo['createIcon'] });
|
2018-06-30 14:00:08 -04:00
|
|
|
let content = new St.Bin({ child: this.icon });
|
2014-08-20 12:39:02 -04:00
|
|
|
this.actor.set_child(content);
|
|
|
|
this.actor.label_actor = this.icon.label;
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var SearchResultsBase = class {
|
|
|
|
constructor(provider, resultsView) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.provider = provider;
|
2017-06-27 17:58:07 -04:00
|
|
|
this._resultsView = resultsView;
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this._terms = [];
|
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'search-section',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
this._resultDisplayBin = new St.Bin({ x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
this.actor.add(this._resultDisplayBin, { expand: true });
|
|
|
|
|
2017-07-13 14:34:47 -04:00
|
|
|
let separator = new St.Widget({ style_class: 'search-section-separator' });
|
|
|
|
this.actor.add(separator);
|
2013-02-08 18:59:15 -05:00
|
|
|
|
|
|
|
this._resultDisplays = {};
|
search: Make the internal search interface callback-based
Long ago, the search system worked in a synchronous manner: providers
were given a query, and results were collected in a single array of
[provider, results] pairs, and then the search display was updated
from that.
We introduced an asynchronous search system when we wanted to potentially
add a Zeitgeist search provider to the Shell in 3.2. For a while, search
providers were either async or sync, which worked by storing a dummy array
in the results, and adding a method for search providers to add results
later.
Later, we removed the search system entirely and ported the remaining
search providers to simply use the API to modify the empty array, but the
remains of the synchronous search system with its silly array still
lingered.
Finally, it's time to modernize. Promises^WCallbacks are the future.
Port the one remaining in-shell search engine (app search) to the new
callback based system, and simplify the remote search system in the
process.
2013-11-02 19:45:35 -04:00
|
|
|
|
2017-05-03 04:28:31 -04:00
|
|
|
this._clipboard = St.Clipboard.get_default();
|
|
|
|
|
search: Make the internal search interface callback-based
Long ago, the search system worked in a synchronous manner: providers
were given a query, and results were collected in a single array of
[provider, results] pairs, and then the search display was updated
from that.
We introduced an asynchronous search system when we wanted to potentially
add a Zeitgeist search provider to the Shell in 3.2. For a while, search
providers were either async or sync, which worked by storing a dummy array
in the results, and adding a method for search providers to add results
later.
Later, we removed the search system entirely and ported the remaining
search providers to simply use the API to modify the empty array, but the
remains of the synchronous search system with its silly array still
lingered.
Finally, it's time to modernize. Promises^WCallbacks are the future.
Port the one remaining in-shell search engine (app search) to the new
callback based system, and simplify the remote search system in the
process.
2013-11-02 19:45:35 -04:00
|
|
|
this._cancellable = new Gio.Cancellable();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
destroy() {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.actor.destroy();
|
|
|
|
this._terms = [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createResultDisplay(meta) {
|
2014-08-20 12:39:02 -04:00
|
|
|
if (this.provider.createResultObject)
|
2017-06-27 17:58:07 -04:00
|
|
|
return this.provider.createResultObject(meta, this._resultsView);
|
2014-08-20 12:39:02 -04:00
|
|
|
|
|
|
|
return null;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
clear() {
|
2018-08-23 12:14:38 -04:00
|
|
|
this._cancellable.cancel();
|
2014-02-23 10:18:46 -05:00
|
|
|
for (let resultId in this._resultDisplays)
|
|
|
|
this._resultDisplays[resultId].actor.destroy();
|
2013-02-08 18:59:15 -05:00
|
|
|
this._resultDisplays = {};
|
2013-10-29 15:49:05 -04:00
|
|
|
this._clearResultDisplay();
|
|
|
|
this.actor.hide();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_keyFocusIn(actor) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.emit('key-focus-in', actor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_activateResult(result, id) {
|
2013-10-31 11:59:23 -04:00
|
|
|
this.provider.activateResult(id, this._terms);
|
2017-05-03 04:28:31 -04:00
|
|
|
if (result.metaInfo.clipboardText)
|
|
|
|
this._clipboard.set_text(St.ClipboardType.CLIPBOARD, result.metaInfo.clipboardText);
|
2013-10-31 11:59:23 -04:00
|
|
|
Main.overview.toggle();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-08 19:04:24 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setMoreCount(count) {
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ensureResultActors(results, callback) {
|
2017-10-30 20:38:18 -04:00
|
|
|
let metasNeeded = results.filter(
|
|
|
|
resultId => this._resultDisplays[resultId] === undefined
|
|
|
|
);
|
2013-02-08 18:59:15 -05:00
|
|
|
|
|
|
|
if (metasNeeded.length === 0) {
|
2014-02-24 11:24:42 -05:00
|
|
|
callback(true);
|
2013-02-08 18:59:15 -05:00
|
|
|
} else {
|
search: Make the internal search interface callback-based
Long ago, the search system worked in a synchronous manner: providers
were given a query, and results were collected in a single array of
[provider, results] pairs, and then the search display was updated
from that.
We introduced an asynchronous search system when we wanted to potentially
add a Zeitgeist search provider to the Shell in 3.2. For a while, search
providers were either async or sync, which worked by storing a dummy array
in the results, and adding a method for search providers to add results
later.
Later, we removed the search system entirely and ported the remaining
search providers to simply use the API to modify the empty array, but the
remains of the synchronous search system with its silly array still
lingered.
Finally, it's time to modernize. Promises^WCallbacks are the future.
Port the one remaining in-shell search engine (app search) to the new
callback based system, and simplify the remote search system in the
process.
2013-11-02 19:45:35 -04:00
|
|
|
this._cancellable.cancel();
|
|
|
|
this._cancellable.reset();
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this.provider.getResultMetas(metasNeeded, metas => {
|
2018-08-30 01:11:24 -04:00
|
|
|
if (this._cancellable.is_cancelled()) {
|
|
|
|
if (metas.length > 0)
|
|
|
|
log(`Search provider ${this.provider.id} returned results after the request was canceled`);
|
|
|
|
callback(false);
|
|
|
|
return;
|
|
|
|
}
|
2014-02-24 11:24:42 -05:00
|
|
|
if (metas.length != metasNeeded.length) {
|
2019-01-29 19:18:24 -05:00
|
|
|
log(`Wrong number of result metas returned by search provider ${this.provider.id}: ` +
|
|
|
|
`expected ${metasNeeded.length} but got ${metas.length}`);
|
2014-02-24 11:24:42 -05:00
|
|
|
callback(false);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
if (metas.some(meta => !meta.name || !meta.id)) {
|
2019-01-29 19:18:24 -05:00
|
|
|
log(`Invalid result meta returned from search provider ${this.provider.id}`);
|
2015-03-08 19:20:10 -04:00
|
|
|
callback(false);
|
|
|
|
return;
|
|
|
|
}
|
2014-02-24 11:24:42 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
metasNeeded.forEach((resultId, i) => {
|
2013-02-08 18:59:15 -05:00
|
|
|
let meta = metas[i];
|
|
|
|
let display = this._createResultDisplay(meta);
|
2017-12-01 19:27:35 -05:00
|
|
|
display.connect('activate', this._activateResult.bind(this));
|
|
|
|
display.actor.connect('key-focus-in', this._keyFocusIn.bind(this));
|
2013-02-08 18:59:15 -05:00
|
|
|
this._resultDisplays[resultId] = display;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-02-24 11:24:42 -05:00
|
|
|
callback(true);
|
2017-10-30 20:38:18 -04:00
|
|
|
}, this._cancellable);
|
2013-02-08 18:59:15 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-08 18:59:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
updateSearch(providerResults, terms, callback) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this._terms = terms;
|
|
|
|
if (providerResults.length == 0) {
|
|
|
|
this._clearResultDisplay();
|
|
|
|
this.actor.hide();
|
|
|
|
callback();
|
|
|
|
} else {
|
|
|
|
let maxResults = this._getMaxDisplayedResults();
|
|
|
|
let results = this.provider.filterResults(providerResults, maxResults);
|
2017-07-12 19:51:59 -04:00
|
|
|
let moreCount = Math.max(providerResults.length - results.length, 0);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._ensureResultActors(results, successful => {
|
2014-09-11 17:36:40 -04:00
|
|
|
if (!successful) {
|
|
|
|
this._clearResultDisplay();
|
2015-01-07 04:53:30 -05:00
|
|
|
callback();
|
2014-02-24 11:24:42 -05:00
|
|
|
return;
|
2014-09-11 17:36:40 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
// To avoid CSS transitions causing flickering when
|
|
|
|
// the first search result stays the same, we hide the
|
|
|
|
// content while filling in the results.
|
|
|
|
this.actor.hide();
|
|
|
|
this._clearResultDisplay();
|
2017-10-30 20:38:18 -04:00
|
|
|
results.forEach(resultId => {
|
2013-02-08 18:59:15 -05:00
|
|
|
this._addItem(this._resultDisplays[resultId]);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-07-12 19:51:59 -04:00
|
|
|
this._setMoreCount(this.provider.canLaunchSearch ? moreCount : 0);
|
2013-10-29 15:49:05 -04:00
|
|
|
this.actor.show();
|
|
|
|
callback();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var ListSearchResults = class extends SearchResultsBase {
|
|
|
|
constructor(provider, resultsView) {
|
|
|
|
super(provider, resultsView);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this._container = new St.BoxLayout({ style_class: 'search-section-content' });
|
2017-07-12 19:51:59 -04:00
|
|
|
this.providerInfo = new ProviderInfo(provider);
|
2017-12-01 19:27:35 -05:00
|
|
|
this.providerInfo.connect('key-focus-in', this._keyFocusIn.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
this.providerInfo.connect('clicked', () => {
|
|
|
|
this.providerInfo.animateLaunch();
|
|
|
|
provider.launchSearch(this._terms);
|
|
|
|
Main.overview.toggle();
|
|
|
|
});
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-07-12 19:51:59 -04:00
|
|
|
this._container.add(this.providerInfo, { x_fill: false,
|
2013-10-29 15:49:05 -04:00
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
this._content = new St.BoxLayout({ style_class: 'list-search-results',
|
|
|
|
vertical: true });
|
|
|
|
this._container.add(this._content, { expand: true });
|
|
|
|
|
|
|
|
this._resultDisplayBin.set_child(this._container);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setMoreCount(count) {
|
2017-07-12 19:51:59 -04:00
|
|
|
this.providerInfo.setMoreCount(count);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getMaxDisplayedResults() {
|
2013-10-29 15:49:05 -04:00
|
|
|
return MAX_LIST_SEARCH_RESULTS_ROWS;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearResultDisplay() {
|
2013-02-08 18:59:15 -05:00
|
|
|
this._content.remove_all_children();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createResultDisplay(meta) {
|
2019-07-09 11:17:06 -04:00
|
|
|
return super._createResultDisplay(meta) ||
|
2017-06-27 17:58:07 -04:00
|
|
|
new ListSearchResult(this.provider, meta, this._resultsView);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-08 18:59:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_addItem(display) {
|
2013-02-08 18:59:15 -05:00
|
|
|
this._content.add_actor(display.actor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getFirstResult() {
|
2013-10-29 15:49:05 -04:00
|
|
|
if (this._content.get_n_children() > 0)
|
|
|
|
return this._content.get_child_at_index(0)._delegate;
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-10-29 15:49:05 -04:00
|
|
|
Signals.addSignalMethods(ListSearchResults.prototype);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var GridSearchResults = class extends SearchResultsBase {
|
|
|
|
constructor(provider, resultsView) {
|
|
|
|
super(provider, resultsView);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this._grid = new IconGrid.IconGrid({ rowLimit: MAX_GRID_SEARCH_RESULTS_ROWS,
|
|
|
|
xAlign: St.Align.START });
|
2018-07-02 10:03:07 -04:00
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
this._bin = new St.Bin({ x_align: St.Align.MIDDLE });
|
2018-07-02 10:03:07 -04:00
|
|
|
this._bin.set_child(this._grid);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this._resultDisplayBin.set_child(this._bin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2018-11-24 18:57:00 -05:00
|
|
|
updateSearch(...args) {
|
|
|
|
if (this._notifyAllocationId)
|
|
|
|
this.actor.disconnect(this._notifyAllocationId);
|
|
|
|
|
|
|
|
// Make sure the maximum number of results calculated by
|
|
|
|
// _getMaxDisplayedResults() is updated after width changes.
|
|
|
|
this._notifyAllocationId = this.actor.connect('notify::allocation', () => {
|
|
|
|
super.updateSearch(...args);
|
|
|
|
});
|
|
|
|
|
|
|
|
super.updateSearch(...args);
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getMaxDisplayedResults() {
|
2018-11-24 18:57:00 -05:00
|
|
|
let allocation = this.actor.allocation;
|
|
|
|
let nCols = this._grid.columnsForWidth(allocation.x2 - allocation.x1);
|
|
|
|
return nCols * this._grid.getRowLimit();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearResultDisplay() {
|
2013-10-29 15:49:05 -04:00
|
|
|
this._grid.removeAll();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createResultDisplay(meta) {
|
2019-07-09 11:17:06 -04:00
|
|
|
return super._createResultDisplay(meta) ||
|
2017-06-27 17:58:07 -04:00
|
|
|
new GridSearchResult(this.provider, meta, this._resultsView);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-08 18:59:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_addItem(display) {
|
2013-10-30 13:06:56 -04:00
|
|
|
this._grid.addItem(display);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-08 18:59:15 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getFirstResult() {
|
2013-10-29 15:49:05 -04:00
|
|
|
if (this._grid.visibleItemsCount() > 0)
|
|
|
|
return this._grid.getItemAtIndex(0)._delegate;
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-10-29 15:49:05 -04:00
|
|
|
Signals.addSignalMethods(GridSearchResults.prototype);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var SearchResults = class {
|
|
|
|
constructor() {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.actor = new St.BoxLayout({ name: 'searchResults',
|
|
|
|
vertical: true });
|
|
|
|
|
2018-11-24 16:33:05 -05:00
|
|
|
this._content = new MaxWidthBox({ name: 'searchResultsContent',
|
|
|
|
vertical: true });
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this._scrollView = new St.ScrollView({ x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
overlay_scrollbars: true,
|
|
|
|
style_class: 'search-display vfade' });
|
2018-11-27 07:45:36 -05:00
|
|
|
this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
|
2018-11-24 16:33:05 -05:00
|
|
|
this._scrollView.add_actor(this._content);
|
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
let action = new Clutter.PanAction({ interpolate: true });
|
2017-12-01 19:27:35 -05:00
|
|
|
action.connect('pan', this._onPan.bind(this));
|
2013-10-29 15:49:05 -04:00
|
|
|
this._scrollView.add_action(action);
|
|
|
|
|
|
|
|
this.actor.add(this._scrollView, { x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
expand: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
this._statusText = new St.Label({ style_class: 'search-statustext' });
|
|
|
|
this._statusBin = new St.Bin({ x_align: St.Align.MIDDLE,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2014-09-11 17:47:49 -04:00
|
|
|
this.actor.add(this._statusBin, { expand: true });
|
2013-10-29 15:49:05 -04:00
|
|
|
this._statusBin.add_actor(this._statusText);
|
|
|
|
|
|
|
|
this._highlightDefault = false;
|
|
|
|
this._defaultResult = null;
|
2014-09-11 17:15:50 -04:00
|
|
|
this._startingSearch = false;
|
|
|
|
|
|
|
|
this._terms = [];
|
|
|
|
this._results = {};
|
2013-10-30 12:38:46 -04:00
|
|
|
|
2014-09-11 15:45:51 -04:00
|
|
|
this._providers = [];
|
|
|
|
|
2017-06-27 18:01:13 -04:00
|
|
|
this._highlightRegex = null;
|
|
|
|
|
2014-09-12 17:20:47 -04:00
|
|
|
this._searchSettings = new Gio.Settings({ schema_id: SEARCH_PROVIDERS_SCHEMA });
|
2017-12-01 19:27:35 -05:00
|
|
|
this._searchSettings.connect('changed::disabled', this._reloadRemoteProviders.bind(this));
|
|
|
|
this._searchSettings.connect('changed::enabled', this._reloadRemoteProviders.bind(this));
|
|
|
|
this._searchSettings.connect('changed::disable-external', this._reloadRemoteProviders.bind(this));
|
|
|
|
this._searchSettings.connect('changed::sort-order', this._reloadRemoteProviders.bind(this));
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2014-09-11 17:15:50 -04:00
|
|
|
this._searchTimeoutId = 0;
|
2014-09-11 15:45:51 -04:00
|
|
|
this._cancellable = new Gio.Cancellable();
|
2014-09-11 17:15:50 -04:00
|
|
|
|
|
|
|
this._registerProvider(new AppDisplay.AppSearchProvider());
|
2017-11-30 15:36:31 -05:00
|
|
|
|
|
|
|
let appSystem = Shell.AppSystem.get_default();
|
|
|
|
appSystem.connect('installed-changed', this._reloadRemoteProviders.bind(this));
|
2014-09-11 17:15:50 -04:00
|
|
|
this._reloadRemoteProviders();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadRemoteProviders() {
|
2017-10-30 20:38:18 -04:00
|
|
|
let remoteProviders = this._providers.filter(p => p.isRemoteProvider);
|
|
|
|
remoteProviders.forEach(provider => {
|
2014-09-11 15:45:51 -04:00
|
|
|
this._unregisterProvider(provider);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
RemoteSearch.loadRemoteSearchProviders(this._searchSettings, providers => {
|
2017-12-01 19:27:35 -05:00
|
|
|
providers.forEach(this._registerProvider.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_registerProvider(provider) {
|
2019-01-18 08:17:21 -05:00
|
|
|
provider.searchInProgress = false;
|
2014-09-11 15:45:51 -04:00
|
|
|
this._providers.push(provider);
|
|
|
|
this._ensureProviderDisplay(provider);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_unregisterProvider(provider) {
|
2014-09-11 15:45:51 -04:00
|
|
|
let index = this._providers.indexOf(provider);
|
|
|
|
this._providers.splice(index, 1);
|
|
|
|
|
|
|
|
if (provider.display)
|
|
|
|
provider.display.destroy();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_gotResults(results, provider) {
|
2014-09-11 15:45:51 -04:00
|
|
|
this._results[provider.id] = results;
|
|
|
|
this._updateResults(provider, results);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 15:45:51 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearSearchTimeout() {
|
2014-09-30 02:19:28 -04:00
|
|
|
if (this._searchTimeoutId > 0) {
|
|
|
|
GLib.source_remove(this._searchTimeoutId);
|
|
|
|
this._searchTimeoutId = 0;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-30 02:19:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reset() {
|
2014-09-30 02:22:14 -04:00
|
|
|
this._terms = [];
|
|
|
|
this._results = {};
|
|
|
|
this._clearDisplay();
|
|
|
|
this._clearSearchTimeout();
|
|
|
|
this._defaultResult = null;
|
|
|
|
this._startingSearch = false;
|
|
|
|
|
|
|
|
this._updateSearchProgress();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-30 02:22:14 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doSearch() {
|
2014-09-11 17:47:49 -04:00
|
|
|
this._startingSearch = false;
|
|
|
|
|
2014-09-11 17:15:50 -04:00
|
|
|
let previousResults = this._results;
|
|
|
|
this._results = {};
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._providers.forEach(provider => {
|
2014-09-11 17:15:50 -04:00
|
|
|
provider.searchInProgress = true;
|
|
|
|
|
|
|
|
let previousProviderResults = previousResults[provider.id];
|
|
|
|
if (this._isSubSearch && previousProviderResults)
|
2017-12-01 19:27:35 -05:00
|
|
|
provider.getSubsearchResultSet(previousProviderResults,
|
|
|
|
this._terms,
|
|
|
|
results => {
|
|
|
|
this._gotResults(results, provider);
|
|
|
|
},
|
|
|
|
this._cancellable);
|
2014-09-11 17:15:50 -04:00
|
|
|
else
|
2017-12-01 19:27:35 -05:00
|
|
|
provider.getInitialResultSet(this._terms,
|
|
|
|
results => {
|
|
|
|
this._gotResults(results, provider);
|
|
|
|
},
|
|
|
|
this._cancellable);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-09-11 17:15:50 -04:00
|
|
|
|
|
|
|
this._updateSearchProgress();
|
|
|
|
|
2014-09-30 02:19:28 -04:00
|
|
|
this._clearSearchTimeout();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 19:51:12 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onSearchTimeout() {
|
2014-09-11 17:15:50 -04:00
|
|
|
this._searchTimeoutId = 0;
|
2014-09-11 19:51:12 -04:00
|
|
|
this._doSearch();
|
2014-09-11 17:15:50 -04:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 17:15:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setTerms(terms) {
|
2014-09-30 20:47:07 -04:00
|
|
|
// Check for the case of making a duplicate previous search before
|
|
|
|
// setting state of the current search or cancelling the search.
|
|
|
|
// This will prevent incorrect state being as a result of a duplicate
|
|
|
|
// search while the previous search is still active.
|
|
|
|
let searchString = terms.join(' ');
|
|
|
|
let previousSearchString = this._terms.join(' ');
|
|
|
|
if (searchString == previousSearchString)
|
|
|
|
return;
|
|
|
|
|
2014-09-11 17:15:50 -04:00
|
|
|
this._startingSearch = true;
|
|
|
|
|
2014-09-11 15:45:51 -04:00
|
|
|
this._cancellable.cancel();
|
|
|
|
this._cancellable.reset();
|
|
|
|
|
2014-09-30 02:19:55 -04:00
|
|
|
if (terms.length == 0) {
|
2014-09-30 02:22:14 -04:00
|
|
|
this._reset();
|
2014-09-11 15:45:51 -04:00
|
|
|
return;
|
2014-09-11 17:15:50 -04:00
|
|
|
}
|
2014-09-11 15:45:51 -04:00
|
|
|
|
|
|
|
let isSubSearch = false;
|
|
|
|
if (this._terms.length > 0)
|
|
|
|
isSubSearch = searchString.indexOf(previousSearchString) == 0;
|
|
|
|
|
|
|
|
this._terms = terms;
|
2014-09-11 17:15:50 -04:00
|
|
|
this._isSubSearch = isSubSearch;
|
2014-09-11 17:47:49 -04:00
|
|
|
this._updateSearchProgress();
|
2014-09-11 17:15:50 -04:00
|
|
|
|
|
|
|
if (this._searchTimeoutId == 0)
|
2017-12-01 19:27:35 -05:00
|
|
|
this._searchTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 150, this._onSearchTimeout.bind(this));
|
2017-06-27 18:01:13 -04:00
|
|
|
|
|
|
|
let escapedTerms = this._terms.map(term => Shell.util_regex_escape(term));
|
|
|
|
this._highlightRegex = new RegExp(`(${escapedTerms.join('|')})`, 'gi');
|
|
|
|
|
|
|
|
this.emit('terms-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPan(action) {
|
2013-10-29 15:49:05 -04:00
|
|
|
let [dist, dx, dy] = action.get_motion_delta(0);
|
|
|
|
let adjustment = this._scrollView.vscroll.adjustment;
|
|
|
|
adjustment.value -= (dy / this.actor.height) * adjustment.page_size;
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_keyFocusIn(provider, actor) {
|
2013-10-29 15:49:05 -04:00
|
|
|
Util.ensureActorVisibleInScrollView(this._scrollView, actor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ensureProviderDisplay(provider) {
|
2013-10-30 12:38:46 -04:00
|
|
|
if (provider.display)
|
|
|
|
return;
|
|
|
|
|
2013-10-29 16:13:32 -04:00
|
|
|
let providerDisplay;
|
|
|
|
if (provider.appInfo)
|
2017-06-27 17:58:07 -04:00
|
|
|
providerDisplay = new ListSearchResults(provider, this);
|
2013-10-29 16:13:32 -04:00
|
|
|
else
|
2017-06-27 17:58:07 -04:00
|
|
|
providerDisplay = new GridSearchResults(provider, this);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
providerDisplay.connect('key-focus-in', this._keyFocusIn.bind(this));
|
2014-09-29 21:51:24 -04:00
|
|
|
providerDisplay.actor.hide();
|
2013-10-29 15:49:05 -04:00
|
|
|
this._content.add(providerDisplay.actor);
|
2013-10-29 16:13:32 -04:00
|
|
|
provider.display = providerDisplay;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_clearDisplay() {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._providers.forEach(provider => {
|
2013-10-29 16:13:32 -04:00
|
|
|
provider.display.clear();
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_maybeSetInitialSelection() {
|
2013-10-29 15:49:05 -04:00
|
|
|
let newDefaultResult = null;
|
|
|
|
|
2014-09-11 15:45:51 -04:00
|
|
|
let providers = this._providers;
|
2013-10-29 16:13:32 -04:00
|
|
|
for (let i = 0; i < providers.length; i++) {
|
|
|
|
let provider = providers[i];
|
|
|
|
let display = provider.display;
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
if (!display.actor.visible)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let firstResult = display.getFirstResult();
|
|
|
|
if (firstResult) {
|
|
|
|
newDefaultResult = firstResult;
|
|
|
|
break; // select this one!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newDefaultResult != this._defaultResult) {
|
2014-08-20 12:39:02 -04:00
|
|
|
this._setSelected(this._defaultResult, false);
|
|
|
|
this._setSelected(newDefaultResult, this._highlightDefault);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
|
|
|
this._defaultResult = newDefaultResult;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2014-09-11 17:47:49 -04:00
|
|
|
get searchInProgress() {
|
|
|
|
if (this._startingSearch)
|
|
|
|
return true;
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
return this._providers.some(p => p.searchInProgress);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-11 17:47:49 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSearchProgress() {
|
2017-10-30 20:38:18 -04:00
|
|
|
let haveResults = this._providers.some(provider => {
|
2013-10-29 16:13:32 -04:00
|
|
|
let display = provider.display;
|
|
|
|
return (display.getFirstResult() != null);
|
|
|
|
});
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2014-09-11 17:47:49 -04:00
|
|
|
this._scrollView.visible = haveResults;
|
|
|
|
this._statusBin.visible = !haveResults;
|
|
|
|
|
2014-09-11 19:14:54 -04:00
|
|
|
if (!haveResults) {
|
2014-09-11 17:47:49 -04:00
|
|
|
if (this.searchInProgress) {
|
|
|
|
this._statusText.set_text(_("Searching…"));
|
|
|
|
} else {
|
|
|
|
this._statusText.set_text(_("No results."));
|
|
|
|
}
|
2014-09-11 19:14:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateResults(provider, results) {
|
2014-09-11 15:45:51 -04:00
|
|
|
let terms = this._terms;
|
2013-10-29 16:13:32 -04:00
|
|
|
let display = provider.display;
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
display.updateSearch(results, terms, () => {
|
2014-09-11 17:47:49 -04:00
|
|
|
provider.searchInProgress = false;
|
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
this._maybeSetInitialSelection();
|
2014-09-11 17:47:49 -04:00
|
|
|
this._updateSearchProgress();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateDefault() {
|
2014-09-11 20:01:08 -04:00
|
|
|
// If we have a search queued up, force the search now.
|
|
|
|
if (this._searchTimeoutId > 0)
|
|
|
|
this._doSearch();
|
2014-09-11 17:15:50 -04:00
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
if (this._defaultResult)
|
|
|
|
this._defaultResult.activate();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
highlightDefault(highlight) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this._highlightDefault = highlight;
|
2014-08-20 12:39:02 -04:00
|
|
|
this._setSelected(this._defaultResult, highlight);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popupMenuDefault() {
|
2017-08-15 19:25:15 -04:00
|
|
|
// If we have a search queued up, force the search now.
|
|
|
|
if (this._searchTimeoutId > 0)
|
|
|
|
this._doSearch();
|
|
|
|
|
|
|
|
if (this._defaultResult)
|
|
|
|
this._defaultResult.actor.popup_menu();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-08-15 19:25:15 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
navigateFocus(direction) {
|
2013-10-29 15:49:05 -04:00
|
|
|
let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
|
2018-11-27 07:58:25 -05:00
|
|
|
if (direction == St.DirectionType.TAB_BACKWARD ||
|
|
|
|
direction == (rtl ? St.DirectionType.RIGHT
|
|
|
|
: St.DirectionType.LEFT) ||
|
|
|
|
direction == St.DirectionType.UP) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.actor.navigate_focus(null, direction, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let from = this._defaultResult ? this._defaultResult.actor : null;
|
|
|
|
this.actor.navigate_focus(from, direction, false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-08-20 12:39:02 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setSelected(result, selected) {
|
2014-08-20 12:39:02 -04:00
|
|
|
if (!result)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
result.actor.add_style_pseudo_class('selected');
|
|
|
|
Util.ensureActorVisibleInScrollView(this._scrollView, result.actor);
|
|
|
|
} else {
|
|
|
|
result.actor.remove_style_pseudo_class('selected');
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-06-27 18:01:13 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
highlightTerms(description) {
|
2017-06-27 18:01:13 -04:00
|
|
|
if (!description)
|
|
|
|
return '';
|
|
|
|
|
|
|
|
if (!this._highlightRegex)
|
|
|
|
return description;
|
|
|
|
|
|
|
|
return description.replace(this._highlightRegex, '<b>$1</b>');
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2017-06-27 18:01:13 -04:00
|
|
|
Signals.addSignalMethods(SearchResults.prototype);
|
2013-10-29 15:49:05 -04:00
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var ProviderInfo = GObject.registerClass(
|
|
|
|
class ProviderInfo extends St.Button {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(provider) {
|
2013-10-29 15:49:05 -04:00
|
|
|
this.provider = provider;
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init({ style_class: 'search-provider-icon',
|
2013-10-29 15:49:05 -04:00
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
accessible_name: provider.appInfo.get_name(),
|
|
|
|
track_hover: true });
|
|
|
|
|
2017-07-12 19:51:59 -04:00
|
|
|
this._content = new St.BoxLayout({ vertical: false,
|
|
|
|
style_class: 'list-search-provider-content' });
|
2013-10-29 15:49:05 -04:00
|
|
|
this.set_child(this._content);
|
|
|
|
|
|
|
|
let icon = new St.Icon({ icon_size: this.PROVIDER_ICON_SIZE,
|
|
|
|
gicon: provider.appInfo.get_icon() });
|
2017-07-12 19:51:59 -04:00
|
|
|
|
|
|
|
let detailsBox = new St.BoxLayout({ style_class: 'list-search-provider-details',
|
|
|
|
vertical: true,
|
|
|
|
x_expand: true });
|
|
|
|
|
|
|
|
let nameLabel = new St.Label({ text: provider.appInfo.get_name(),
|
|
|
|
x_align: Clutter.ActorAlign.START });
|
|
|
|
|
|
|
|
this._moreLabel = new St.Label({ x_align: Clutter.ActorAlign.START });
|
|
|
|
|
|
|
|
detailsBox.add_actor(nameLabel);
|
|
|
|
detailsBox.add_actor(this._moreLabel);
|
|
|
|
|
|
|
|
|
2013-10-29 15:49:05 -04:00
|
|
|
this._content.add_actor(icon);
|
2017-07-12 19:51:59 -04:00
|
|
|
this._content.add_actor(detailsBox);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get PROVIDER_ICON_SIZE() {
|
|
|
|
return 32;
|
|
|
|
}
|
2014-06-17 15:31:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
animateLaunch() {
|
2014-06-17 15:31:53 -04:00
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
let app = appSys.lookup_app(this.provider.appInfo.get_id());
|
|
|
|
if (app.state == Shell.AppState.STOPPED)
|
|
|
|
IconGrid.zoomOutActor(this._content);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-12 19:51:59 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setMoreCount(count) {
|
2017-08-10 21:06:10 -04:00
|
|
|
this._moreLabel.text = ngettext("%d more", "%d more", count).format(count);
|
2017-07-12 19:51:59 -04:00
|
|
|
this._moreLabel.visible = count > 0;
|
2013-10-29 15:49:05 -04:00
|
|
|
}
|
|
|
|
});
|