2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Lang = imports.lang;
|
2010-10-14 12:27:28 +00:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2011-03-21 22:53:07 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
2010-10-14 12:27:28 +00:00
|
|
|
const St = imports.gi.St;
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
const DND = imports.ui.dnd;
|
2010-10-14 12:27:28 +00:00
|
|
|
const IconGrid = imports.ui.iconGrid;
|
2010-11-18 09:23:44 +00:00
|
|
|
const Main = imports.ui.main;
|
2011-01-21 22:49:03 +00:00
|
|
|
const Overview = imports.ui.overview;
|
2010-11-18 09:23:44 +00:00
|
|
|
const Search = imports.ui.search;
|
|
|
|
|
2011-02-25 21:53:53 +00:00
|
|
|
const MAX_SEARCH_RESULTS_ROWS = 1;
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const SearchResult = new Lang.Class({
|
|
|
|
Name: 'SearchResult',
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
_init: function(provider, metaInfo, terms) {
|
|
|
|
this.provider = provider;
|
|
|
|
this.metaInfo = metaInfo;
|
2011-01-25 21:22:00 +00:00
|
|
|
this.actor = new St.Button({ style_class: 'search-result',
|
|
|
|
reactive: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_fill: true });
|
2010-11-18 09:23:44 +00:00
|
|
|
this.actor._delegate = this;
|
2011-05-20 11:57:38 +00:00
|
|
|
this._dragActorSource = null;
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
let content = provider.createResultActor(metaInfo, terms);
|
|
|
|
if (content == null) {
|
2010-10-14 12:27:28 +00:00
|
|
|
content = new St.Bin({ style_class: 'search-result-content',
|
|
|
|
reactive: true,
|
|
|
|
track_hover: true });
|
|
|
|
let icon = new IconGrid.BaseIcon(this.metaInfo['name'],
|
2011-02-28 19:36:52 +00:00
|
|
|
{ createIcon: this.metaInfo['createIcon'] });
|
2010-10-14 12:27:28 +00:00
|
|
|
content.set_child(icon.actor);
|
2011-05-20 11:57:38 +00:00
|
|
|
this._dragActorSource = icon.icon;
|
2011-03-08 18:33:57 +00:00
|
|
|
this.actor.label_actor = icon.label;
|
2011-05-20 11:57:38 +00:00
|
|
|
} else {
|
|
|
|
if (content._delegate && content._delegate.getDragActorSource)
|
|
|
|
this._dragActorSource = content._delegate.getDragActorSource();
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
|
|
|
this._content = content;
|
|
|
|
this.actor.set_child(content);
|
|
|
|
|
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onResultClicked));
|
|
|
|
|
|
|
|
let draggable = DND.makeDraggable(this.actor);
|
|
|
|
draggable.connect('drag-begin',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Main.overview.beginItemDrag(this);
|
|
|
|
}));
|
2011-03-09 15:40:48 +00:00
|
|
|
draggable.connect('drag-cancelled',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Main.overview.cancelledItemDrag(this);
|
|
|
|
}));
|
2010-11-18 09:23:44 +00:00
|
|
|
draggable.connect('drag-end',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Main.overview.endItemDrag(this);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
setSelected: function(selected) {
|
|
|
|
if (selected)
|
|
|
|
this._content.add_style_pseudo_class('selected');
|
|
|
|
else
|
|
|
|
this._content.remove_style_pseudo_class('selected');
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
this.provider.activateResult(this.metaInfo.id);
|
|
|
|
Main.overview.toggle();
|
|
|
|
},
|
|
|
|
|
2011-01-25 21:22:00 +00:00
|
|
|
_onResultClicked: function(actor) {
|
2010-11-18 09:23:44 +00:00
|
|
|
this.activate();
|
|
|
|
},
|
|
|
|
|
|
|
|
getDragActorSource: function() {
|
2011-05-20 11:57:38 +00:00
|
|
|
if (this._dragActorSource)
|
|
|
|
return this._dragActorSource;
|
2011-03-29 11:32:53 +00:00
|
|
|
// not exactly right, but alignment problems are hard to notice
|
|
|
|
return this._content;
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getDragActor: function(stageX, stageY) {
|
2011-08-28 13:35:13 +00:00
|
|
|
return this.metaInfo['createIcon'](Main.overview.dashIconSize);
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
2011-01-30 21:09:58 +00:00
|
|
|
shellWorkspaceLaunch: function(params) {
|
2010-11-18 09:23:44 +00:00
|
|
|
if (this.provider.dragActivateResult)
|
2011-01-30 21:09:58 +00:00
|
|
|
this.provider.dragActivateResult(this.metaInfo.id, params);
|
2010-11-18 09:23:44 +00:00
|
|
|
else
|
2011-01-30 21:09:58 +00:00
|
|
|
this.provider.activateResult(this.metaInfo.id, params);
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2010-10-14 12:27:28 +00:00
|
|
|
|
2011-11-20 16:07:14 +00:00
|
|
|
const GridSearchResults = new Lang.Class({
|
|
|
|
Name: 'GridSearchResults',
|
|
|
|
Extends: Search.SearchResultDisplay,
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2011-08-28 20:14:15 +00:00
|
|
|
_init: function(provider, grid) {
|
2011-11-20 16:07:14 +00:00
|
|
|
this.parent(provider);
|
|
|
|
|
2011-08-28 20:14:15 +00:00
|
|
|
this._grid = grid || new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS,
|
|
|
|
xAlign: St.Align.START });
|
2010-10-14 12:27:28 +00:00
|
|
|
this.actor = new St.Bin({ x_align: St.Align.START });
|
2011-03-21 22:53:07 +00:00
|
|
|
|
2010-10-14 12:27:28 +00:00
|
|
|
this.actor.set_child(this._grid.actor);
|
|
|
|
this.selectionIndex = -1;
|
2011-03-21 22:53:07 +00:00
|
|
|
this._width = 0;
|
|
|
|
this.actor.connect('notify::width', Lang.bind(this, function() {
|
|
|
|
this._width = this.actor.width;
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
|
2012-02-17 18:39:25 +00:00
|
|
|
let results = this.getResultsForDisplay();
|
|
|
|
if (results.length == 0)
|
|
|
|
return;
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
if (provider.async) {
|
|
|
|
provider.getResultMetasAsync(results,
|
|
|
|
Lang.bind(this, this.renderResults));
|
|
|
|
} else {
|
|
|
|
let metas = provider.getResultMetas(results);
|
|
|
|
this.renderResults(metas);
|
|
|
|
}
|
2011-03-21 22:53:07 +00:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
this._notDisplayedResult = [];
|
|
|
|
this._terms = [];
|
2012-02-21 18:53:25 +00:00
|
|
|
this._pendingClear = false;
|
2011-03-21 22:53:07 +00:00
|
|
|
},
|
|
|
|
|
2012-02-17 18:39:25 +00:00
|
|
|
getResultsForDisplay: function() {
|
2012-02-21 18:53:25 +00:00
|
|
|
let alreadyVisible = this._pendingClear ? 0 : this._grid.visibleItemsCount();
|
2011-03-21 22:53:07 +00:00
|
|
|
let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
|
2012-02-21 18:53:25 +00:00
|
|
|
- alreadyVisible;
|
2011-03-21 22:53:07 +00:00
|
|
|
|
2012-02-17 15:39:27 +00:00
|
|
|
let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
|
2012-02-17 18:39:25 +00:00
|
|
|
|
|
|
|
return this._notDisplayedResult.splice(0, numResults);
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getVisibleResultCount: function() {
|
2010-10-14 12:27:28 +00:00
|
|
|
return this._grid.visibleItemsCount();
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
2012-02-17 18:39:25 +00:00
|
|
|
setResults: function(results, terms) {
|
2011-03-21 22:53:07 +00:00
|
|
|
// copy the lists
|
|
|
|
this._notDisplayedResult = results.slice(0);
|
|
|
|
this._terms = terms.slice(0);
|
2012-02-21 18:53:25 +00:00
|
|
|
this._pendingClear = true;
|
2012-02-17 18:39:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
renderResults: function(metas) {
|
|
|
|
for (let i = 0; i < metas.length; i++) {
|
|
|
|
let display = new SearchResult(this.provider, metas[i], this._terms);
|
|
|
|
this._grid.addItem(display.actor);
|
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
2010-10-14 12:27:28 +00:00
|
|
|
clear: function () {
|
|
|
|
this._grid.removeAll();
|
|
|
|
this.selectionIndex = -1;
|
2012-02-21 18:53:25 +00:00
|
|
|
this._pendingClear = false;
|
2010-10-14 12:27:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
selectIndex: function (index) {
|
|
|
|
let nVisible = this.getVisibleResultCount();
|
2010-11-18 09:23:44 +00:00
|
|
|
if (this.selectionIndex >= 0) {
|
2010-10-14 12:27:28 +00:00
|
|
|
let prevActor = this._grid.getItemAtIndex(this.selectionIndex);
|
2010-11-18 09:23:44 +00:00
|
|
|
prevActor._delegate.setSelected(false);
|
|
|
|
}
|
|
|
|
this.selectionIndex = -1;
|
|
|
|
if (index >= nVisible)
|
|
|
|
return false;
|
|
|
|
else if (index < 0)
|
|
|
|
return false;
|
2010-10-14 12:27:28 +00:00
|
|
|
let targetActor = this._grid.getItemAtIndex(index);
|
2010-11-18 09:23:44 +00:00
|
|
|
targetActor._delegate.setSelected(true);
|
|
|
|
this.selectionIndex = index;
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
activateSelected: function() {
|
2010-10-14 12:27:28 +00:00
|
|
|
if (this.selectionIndex < 0)
|
|
|
|
return;
|
|
|
|
let targetActor = this._grid.getItemAtIndex(this.selectionIndex);
|
2010-11-18 09:23:44 +00:00
|
|
|
targetActor._delegate.activate();
|
|
|
|
}
|
2011-11-20 16:07:14 +00:00
|
|
|
});
|
2010-10-14 12:27:28 +00:00
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const SearchResults = new Lang.Class({
|
|
|
|
Name: 'SearchResults',
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2011-01-17 21:38:47 +00:00
|
|
|
_init: function(searchSystem, openSearchSystem) {
|
2010-11-18 09:23:44 +00:00
|
|
|
this._searchSystem = searchSystem;
|
2011-07-24 10:29:36 +00:00
|
|
|
this._searchSystem.connect('search-updated', Lang.bind(this, this._updateCurrentResults));
|
|
|
|
this._searchSystem.connect('search-completed', Lang.bind(this, this._updateResults));
|
2011-01-17 21:38:47 +00:00
|
|
|
this._openSearchSystem = openSearchSystem;
|
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ name: 'searchResults',
|
|
|
|
vertical: true });
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2010-10-14 12:27:28 +00:00
|
|
|
this._content = new St.BoxLayout({ name: 'searchResultsContent',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
let scrollView = new St.ScrollView({ x_fill: true,
|
|
|
|
y_fill: false,
|
2011-06-03 21:44:57 +00:00
|
|
|
style_class: 'vfade' });
|
2010-10-14 12:27:28 +00:00
|
|
|
scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
|
|
|
scrollView.add_actor(this._content);
|
|
|
|
|
2011-01-17 21:38:47 +00:00
|
|
|
this.actor.add(scrollView, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
expand: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
2011-01-21 22:49:03 +00:00
|
|
|
this.actor.connect('notify::mapped', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
if (!this.actor.mapped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let adjustment = scrollView.vscroll.adjustment;
|
|
|
|
let direction = Overview.SwipeScrollDirection.VERTICAL;
|
|
|
|
Main.overview.setScrollAdjustment(adjustment, direction);
|
|
|
|
}));
|
2010-10-14 12:27:28 +00:00
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
this._statusText = new St.Label({ style_class: 'search-statustext' });
|
2010-10-14 12:27:28 +00:00
|
|
|
this._content.add(this._statusText);
|
2010-11-18 09:23:44 +00:00
|
|
|
this._selectedProvider = -1;
|
|
|
|
this._providers = this._searchSystem.getProviders();
|
|
|
|
this._providerMeta = [];
|
2011-07-24 10:29:36 +00:00
|
|
|
this._providerMetaResults = {};
|
|
|
|
for (let i = 0; i < this._providers.length; i++) {
|
2010-11-18 09:23:44 +00:00
|
|
|
this.createProviderMeta(this._providers[i]);
|
2011-07-24 10:29:36 +00:00
|
|
|
this._providerMetaResults[this.providers[i].title] = [];
|
|
|
|
}
|
2011-01-17 21:38:47 +00:00
|
|
|
this._searchProvidersBox = new St.BoxLayout({ style_class: 'search-providers-box' });
|
|
|
|
this.actor.add(this._searchProvidersBox);
|
|
|
|
|
|
|
|
this._openSearchProviders = [];
|
|
|
|
this._openSearchSystem.connect('changed', Lang.bind(this, this._updateOpenSearchProviderButtons));
|
|
|
|
this._updateOpenSearchProviderButtons();
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateOpenSearchProviderButtons: function() {
|
|
|
|
this._selectedOpenSearchButton = -1;
|
|
|
|
for (let i = 0; i < this._openSearchProviders.length; i++)
|
|
|
|
this._openSearchProviders[i].actor.destroy();
|
|
|
|
this._openSearchProviders = this._openSearchSystem.getProviders();
|
|
|
|
for (let i = 0; i < this._openSearchProviders.length; i++)
|
|
|
|
this._createOpenSearchProviderButton(this._openSearchProviders[i]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateOpenSearchButtonState: function() {
|
|
|
|
for (let i = 0; i < this._openSearchProviders.length; i++) {
|
|
|
|
if (i == this._selectedOpenSearchButton)
|
|
|
|
this._openSearchProviders[i].actor.add_style_pseudo_class('selected');
|
|
|
|
else
|
|
|
|
this._openSearchProviders[i].actor.remove_style_pseudo_class('selected');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_createOpenSearchProviderButton: function(provider) {
|
2011-01-25 21:22:00 +00:00
|
|
|
let button = new St.Button({ style_class: 'dash-search-button',
|
|
|
|
reactive: true,
|
|
|
|
x_fill: true,
|
|
|
|
y_align: St.Align.MIDDLE });
|
2011-01-17 21:38:47 +00:00
|
|
|
let bin = new St.Bin({ x_fill: false,
|
|
|
|
x_align:St.Align.MIDDLE });
|
2011-01-25 21:22:00 +00:00
|
|
|
button.connect('clicked', Lang.bind(this, function() {
|
2011-01-17 21:38:47 +00:00
|
|
|
this._openSearchSystem.activateResult(provider.id);
|
|
|
|
}));
|
|
|
|
let title = new St.Label({ text: provider.name,
|
|
|
|
style_class: 'dash-search-button-label' });
|
|
|
|
|
2011-03-08 18:33:57 +00:00
|
|
|
button.label_actor = title;
|
2011-01-17 21:38:47 +00:00
|
|
|
bin.set_child(title);
|
2011-01-25 21:22:00 +00:00
|
|
|
button.set_child(bin);
|
|
|
|
provider.actor = button;
|
2011-01-17 21:38:47 +00:00
|
|
|
|
2011-01-25 21:22:00 +00:00
|
|
|
this._searchProvidersBox.add(button);
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createProviderMeta: function(provider) {
|
|
|
|
let providerBox = new St.BoxLayout({ style_class: 'search-section',
|
|
|
|
vertical: true });
|
2011-03-01 23:15:17 +00:00
|
|
|
let title = new St.Label({ style_class: 'search-section-header',
|
|
|
|
text: provider.title });
|
|
|
|
providerBox.add(title);
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
let resultDisplayBin = new St.Bin({ style_class: 'search-section-results',
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
providerBox.add(resultDisplayBin, { expand: true });
|
|
|
|
let resultDisplay = provider.createResultContainerActor();
|
|
|
|
if (resultDisplay == null) {
|
2010-10-14 12:27:28 +00:00
|
|
|
resultDisplay = new GridSearchResults(provider);
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
|
|
|
resultDisplayBin.set_child(resultDisplay.actor);
|
|
|
|
|
2011-08-28 11:20:37 +00:00
|
|
|
this._providerMeta.push({ provider: provider,
|
|
|
|
actor: providerBox,
|
2012-02-21 18:53:25 +00:00
|
|
|
resultDisplay: resultDisplay,
|
|
|
|
hasPendingResults: false });
|
2010-10-14 12:27:28 +00:00
|
|
|
this._content.add(providerBox);
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
2011-08-28 11:20:37 +00:00
|
|
|
destroyProviderMeta: function(provider) {
|
|
|
|
for (let i=0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
if (meta.provider == provider) {
|
|
|
|
meta.actor.destroy();
|
|
|
|
this._providerMeta.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
_clearDisplay: function() {
|
|
|
|
this._selectedProvider = -1;
|
|
|
|
this._visibleResultsCount = 0;
|
|
|
|
for (let i = 0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
meta.resultDisplay.clear();
|
|
|
|
meta.actor.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
_clearDisplayForProvider: function(provider) {
|
|
|
|
let meta = this._metaForProvider(provider);
|
2011-07-24 10:29:36 +00:00
|
|
|
meta.resultDisplay.clear();
|
|
|
|
meta.actor.hide();
|
|
|
|
},
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
reset: function() {
|
|
|
|
this._searchSystem.reset();
|
|
|
|
this._statusText.hide();
|
|
|
|
this._clearDisplay();
|
2011-01-17 21:38:47 +00:00
|
|
|
this._selectedOpenSearchButton = -1;
|
|
|
|
this._updateOpenSearchButtonState();
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
startingSearch: function() {
|
|
|
|
this.reset();
|
|
|
|
this._statusText.set_text(_("Searching..."));
|
|
|
|
this._statusText.show();
|
|
|
|
},
|
|
|
|
|
2011-07-24 10:29:36 +00:00
|
|
|
doSearch: function (searchString) {
|
|
|
|
this._searchSystem.updateSearch(searchString);
|
|
|
|
},
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
_metaForProvider: function(provider) {
|
|
|
|
return this._providerMeta[this._providers.indexOf(provider)];
|
|
|
|
},
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
_maybeSetInitialSelection: function() {
|
|
|
|
if (this._selectedOpenSearchButton > -1 || this._selectedProvider > -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
if (meta.hasPendingResults)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (meta.actor.visible)
|
|
|
|
break; // select this one!
|
|
|
|
}
|
|
|
|
|
|
|
|
this.selectDown(false);
|
|
|
|
this._initialSelectionSet = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateCurrentResults: function(searchSystem, results) {
|
2011-07-24 10:29:36 +00:00
|
|
|
let terms = searchSystem.getTerms();
|
2012-02-21 18:53:25 +00:00
|
|
|
let [provider, providerResults] = results;
|
2011-07-24 10:29:36 +00:00
|
|
|
let meta = this._metaForProvider(provider);
|
2012-02-21 18:53:25 +00:00
|
|
|
meta.hasPendingResults = false;
|
|
|
|
this._updateProviderResults(provider, providerResults, terms);
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateProviderResults: function(provider, providerResults, terms) {
|
|
|
|
let meta = this._metaForProvider(provider);
|
|
|
|
if (providerResults.length == 0) {
|
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.resultDisplay.setResults([], []);
|
|
|
|
} else {
|
|
|
|
this._providerMetaResults[provider.title] = providerResults;
|
|
|
|
meta.resultDisplay.setResults(providerResults, terms);
|
|
|
|
let results = meta.resultDisplay.getResultsForDisplay();
|
|
|
|
|
|
|
|
if (provider.async) {
|
|
|
|
provider.getResultMetasAsync(results, Lang.bind(this,
|
|
|
|
function(metas) {
|
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.actor.show();
|
|
|
|
this._content.hide();
|
|
|
|
meta.resultDisplay.renderResults(metas);
|
|
|
|
this._maybeSetInitialSelection();
|
|
|
|
this._content.show();
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
let metas = provider.getResultMetas(results);
|
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.actor.show();
|
|
|
|
meta.resultDisplay.renderResults(metas);
|
|
|
|
}
|
|
|
|
}
|
2011-07-24 10:29:36 +00:00
|
|
|
},
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2011-07-24 10:29:36 +00:00
|
|
|
_updateResults: function(searchSystem, results) {
|
2010-11-18 09:23:44 +00:00
|
|
|
if (results.length == 0) {
|
|
|
|
this._statusText.set_text(_("No matching results."));
|
|
|
|
this._statusText.show();
|
|
|
|
} else {
|
2011-01-24 23:38:16 +00:00
|
|
|
this._selectedOpenSearchButton = -1;
|
|
|
|
this._updateOpenSearchButtonState();
|
2012-02-21 18:53:25 +00:00
|
|
|
this._selectedProvider = -1;
|
2010-11-18 09:23:44 +00:00
|
|
|
this._statusText.hide();
|
|
|
|
}
|
|
|
|
|
2011-07-24 10:29:36 +00:00
|
|
|
let terms = searchSystem.getTerms();
|
2011-01-17 21:38:47 +00:00
|
|
|
this._openSearchSystem.setSearchTerms(terms);
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2011-04-08 14:48:33 +00:00
|
|
|
// To avoid CSS transitions causing flickering
|
|
|
|
// of the selection when the first search result
|
|
|
|
// stays the same, we hide the content while
|
|
|
|
// filling in the results and setting the initial
|
|
|
|
// selection.
|
|
|
|
this._content.hide();
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
|
|
let [provider, providerResults] = results[i];
|
2012-02-21 18:53:25 +00:00
|
|
|
let meta = this._metaForProvider(provider);
|
|
|
|
meta.hasPendingResults = provider.async;
|
|
|
|
if (!meta.hasPendingResults)
|
|
|
|
this._updateProviderResults(provider, providerResults, terms);
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
this._maybeSetInitialSelection();
|
2011-04-08 14:48:33 +00:00
|
|
|
this._content.show();
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_modifyActorSelection: function(resultDisplay, up) {
|
|
|
|
let success;
|
|
|
|
let index = resultDisplay.getSelectionIndex();
|
|
|
|
if (up && index == -1)
|
|
|
|
index = resultDisplay.getVisibleResultCount() - 1;
|
|
|
|
else if (up)
|
|
|
|
index = index - 1;
|
|
|
|
else
|
|
|
|
index = index + 1;
|
|
|
|
return resultDisplay.selectIndex(index);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectUp: function(recursing) {
|
2011-01-17 21:38:47 +00:00
|
|
|
if (this._selectedOpenSearchButton == -1) {
|
|
|
|
for (let i = this._selectedProvider; i >= 0; i--) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
if (!meta.actor.visible)
|
|
|
|
continue;
|
|
|
|
let success = this._modifyActorSelection(meta.resultDisplay, true);
|
|
|
|
if (success) {
|
|
|
|
this._selectedProvider = i;
|
|
|
|
return;
|
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-17 21:38:47 +00:00
|
|
|
|
|
|
|
if (this._selectedOpenSearchButton == -1)
|
|
|
|
this._selectedOpenSearchButton = this._openSearchProviders.length;
|
|
|
|
this._selectedOpenSearchButton--;
|
|
|
|
this._updateOpenSearchButtonState();
|
|
|
|
if (this._selectedOpenSearchButton >= 0)
|
|
|
|
return;
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
if (this._providerMeta.length > 0 && !recursing) {
|
|
|
|
this._selectedProvider = this._providerMeta.length - 1;
|
|
|
|
this.selectUp(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
selectDown: function(recursing) {
|
|
|
|
let current = this._selectedProvider;
|
2011-01-17 21:38:47 +00:00
|
|
|
if (this._selectedOpenSearchButton == -1) {
|
|
|
|
if (current == -1)
|
|
|
|
current = 0;
|
|
|
|
for (let i = current; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
if (!meta.actor.visible)
|
|
|
|
continue;
|
|
|
|
let success = this._modifyActorSelection(meta.resultDisplay, false);
|
|
|
|
if (success) {
|
|
|
|
this._selectedProvider = i;
|
|
|
|
return;
|
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-17 21:38:47 +00:00
|
|
|
this._selectedOpenSearchButton++;
|
|
|
|
|
|
|
|
if (this._selectedOpenSearchButton < this._openSearchProviders.length) {
|
|
|
|
this._updateOpenSearchButtonState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._selectedOpenSearchButton = -1;
|
|
|
|
this._updateOpenSearchButtonState();
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
if (this._providerMeta.length > 0 && !recursing) {
|
|
|
|
this._selectedProvider = 0;
|
|
|
|
this.selectDown(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
activateSelected: function() {
|
2011-01-17 21:38:47 +00:00
|
|
|
if (this._selectedOpenSearchButton != -1) {
|
|
|
|
let provider = this._openSearchProviders[this._selectedOpenSearchButton];
|
|
|
|
this._openSearchSystem.activateResult(provider.id);
|
|
|
|
Main.overview.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
let current = this._selectedProvider;
|
|
|
|
if (current < 0)
|
|
|
|
return;
|
|
|
|
let meta = this._providerMeta[current];
|
|
|
|
let resultDisplay = meta.resultDisplay;
|
|
|
|
resultDisplay.activateSelected();
|
|
|
|
Main.overview.hide();
|
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|