2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-11-18 04:23:44 -05:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Lang = imports.lang;
|
2010-10-14 08:27:28 -04:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2011-03-21 18:53:07 -04:00
|
|
|
const Meta = imports.gi.Meta;
|
2013-03-11 14:21:42 -04:00
|
|
|
const Signals = imports.signals;
|
2010-10-14 08:27:28 -04:00
|
|
|
const St = imports.gi.St;
|
2012-03-16 12:17:23 -04:00
|
|
|
const Atk = imports.gi.Atk;
|
2010-11-18 04:23:44 -05:00
|
|
|
|
|
|
|
const DND = imports.ui.dnd;
|
2010-10-14 08:27:28 -04:00
|
|
|
const IconGrid = imports.ui.iconGrid;
|
2010-11-18 04:23:44 -05:00
|
|
|
const Main = imports.ui.main;
|
2011-01-21 17:49:03 -05:00
|
|
|
const Overview = imports.ui.overview;
|
2012-08-01 21:48:10 -04:00
|
|
|
const Separator = imports.ui.separator;
|
2010-11-18 04:23:44 -05:00
|
|
|
const Search = imports.ui.search;
|
2013-03-11 14:21:42 -04:00
|
|
|
const Util = imports.misc.util;
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
const MAX_LIST_SEARCH_RESULTS_ROWS = 3;
|
|
|
|
const MAX_GRID_SEARCH_RESULTS_ROWS = 1;
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2013-01-23 14:35:28 -05:00
|
|
|
const MaxWidthBin = new Lang.Class({
|
|
|
|
Name: 'MaxWidthBin',
|
|
|
|
Extends: St.Bin,
|
|
|
|
|
|
|
|
vfunc_allocate: function(box, flags) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.parent(adjustedBox, flags);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const SearchResult = new Lang.Class({
|
|
|
|
Name: 'SearchResult',
|
2010-11-18 04:23:44 -05:00
|
|
|
|
|
|
|
_init: function(provider, metaInfo, terms) {
|
|
|
|
this.provider = provider;
|
|
|
|
this.metaInfo = metaInfo;
|
2012-12-05 11:48:22 -05:00
|
|
|
this.terms = terms;
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
this.actor = new St.Button({ reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
track_hover: true,
|
2011-01-25 16:22:00 -05:00
|
|
|
x_align: St.Align.START,
|
|
|
|
y_fill: true });
|
2012-08-01 21:48:10 -04:00
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
this.actor._delegate = this;
|
2012-08-01 21:48:10 -04:00
|
|
|
this.actor.connect('clicked', Lang.bind(this, this.activate));
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
this.provider.activateResult(this.metaInfo.id, this.terms);
|
|
|
|
Main.overview.toggle();
|
|
|
|
},
|
|
|
|
|
|
|
|
setSelected: function(selected) {
|
|
|
|
if (selected)
|
|
|
|
this.actor.add_style_pseudo_class('selected');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('selected');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const ListSearchResult = new Lang.Class({
|
|
|
|
Name: 'ListSearchResult',
|
|
|
|
Extends: SearchResult,
|
|
|
|
|
|
|
|
ICON_SIZE: 64,
|
|
|
|
|
|
|
|
_init: function(provider, metaInfo, terms) {
|
|
|
|
this.parent(provider, metaInfo, terms);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// An icon for, or thumbnail of, content
|
|
|
|
let icon = this.metaInfo['createIcon'](this.ICON_SIZE);
|
|
|
|
if (icon) {
|
|
|
|
content.add(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
let details = new St.BoxLayout({ vertical: true });
|
|
|
|
content.add(details, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
|
|
|
|
let title = new St.Label({ style_class: 'list-search-result-title',
|
|
|
|
text: this.metaInfo['name'] })
|
|
|
|
details.add(title, { x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
2013-03-17 15:33:02 -04:00
|
|
|
this.actor.label_actor = title;
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
if (this.metaInfo['description']) {
|
2013-02-27 11:54:09 -05:00
|
|
|
let description = new St.Label({ style_class: 'list-search-result-description' });
|
|
|
|
description.clutter_text.set_markup(this.metaInfo['description']);
|
2012-08-01 21:48:10 -04:00
|
|
|
details.add(description, { x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.END });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const GridSearchResult = new Lang.Class({
|
|
|
|
Name: 'GridSearchResult',
|
|
|
|
Extends: SearchResult,
|
|
|
|
|
|
|
|
_init: function(provider, metaInfo, terms) {
|
|
|
|
this.parent(provider, metaInfo, terms);
|
|
|
|
|
|
|
|
this.actor.style_class = 'grid-search-result';
|
2010-11-18 04:23:44 -05:00
|
|
|
|
|
|
|
let content = provider.createResultActor(metaInfo, terms);
|
2012-12-10 13:05:58 -05:00
|
|
|
let dragSource = null;
|
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
if (content == null) {
|
2012-08-01 21:48:10 -04:00
|
|
|
content = new St.Bin();
|
2010-10-14 08:27:28 -04:00
|
|
|
let icon = new IconGrid.BaseIcon(this.metaInfo['name'],
|
2011-02-28 14:36:52 -05:00
|
|
|
{ createIcon: this.metaInfo['createIcon'] });
|
2010-10-14 08:27:28 -04:00
|
|
|
content.set_child(icon.actor);
|
2012-03-16 12:17:23 -04:00
|
|
|
content.label_actor = icon.label;
|
2012-12-10 13:05:58 -05:00
|
|
|
dragSource = icon.icon;
|
2011-05-20 07:57:38 -04:00
|
|
|
} else {
|
|
|
|
if (content._delegate && content._delegate.getDragActorSource)
|
2012-12-10 13:05:58 -05:00
|
|
|
dragSource = content._delegate.getDragActorSource();
|
2010-11-18 04:23:44 -05:00
|
|
|
}
|
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
this.actor.set_child(content);
|
2013-03-17 15:33:02 -04:00
|
|
|
this.actor.label_actor = content.label_actor;
|
2010-11-18 04:23:44 -05:00
|
|
|
|
|
|
|
let draggable = DND.makeDraggable(this.actor);
|
|
|
|
draggable.connect('drag-begin',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Main.overview.beginItemDrag(this);
|
|
|
|
}));
|
2011-03-09 10:40:48 -05:00
|
|
|
draggable.connect('drag-cancelled',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Main.overview.cancelledItemDrag(this);
|
|
|
|
}));
|
2010-11-18 04:23:44 -05:00
|
|
|
draggable.connect('drag-end',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
Main.overview.endItemDrag(this);
|
|
|
|
}));
|
2012-12-10 13:05:58 -05:00
|
|
|
|
|
|
|
if (!dragSource)
|
|
|
|
// not exactly right, but alignment problems are hard to notice
|
|
|
|
dragSource = content;
|
|
|
|
this._dragActorSource = dragSource;
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getDragActorSource: function() {
|
2012-12-10 13:05:58 -05:00
|
|
|
return this._dragActorSource;
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2012-11-27 15:06:12 -05:00
|
|
|
getDragActor: function() {
|
2011-08-28 09:35:13 -04:00
|
|
|
return this.metaInfo['createIcon'](Main.overview.dashIconSize);
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2011-01-30 16:09:58 -05:00
|
|
|
shellWorkspaceLaunch: function(params) {
|
2010-11-18 04:23:44 -05:00
|
|
|
if (this.provider.dragActivateResult)
|
2011-01-30 16:09:58 -05:00
|
|
|
this.provider.dragActivateResult(this.metaInfo.id, params);
|
2010-11-18 04:23:44 -05:00
|
|
|
else
|
2012-12-05 11:48:22 -05:00
|
|
|
this.provider.activateResult(this.metaInfo.id, this.terms);
|
2010-11-18 04:23:44 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
const ListSearchResults = new Lang.Class({
|
|
|
|
Name: 'ListSearchResults',
|
|
|
|
|
|
|
|
_init: function(provider) {
|
2012-11-27 15:05:32 -05:00
|
|
|
this.provider = provider;
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'search-section-content' });
|
|
|
|
this.providerIcon = new ProviderIcon(provider);
|
|
|
|
this.providerIcon.connect('clicked', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
provider.launchSearch(this._terms);
|
|
|
|
Main.overview.toggle();
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.actor.add(this.providerIcon, { x_fill: false,
|
|
|
|
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 });
|
2013-01-16 23:02:48 -05:00
|
|
|
this.actor.add(this._content, { expand: true });
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
this._notDisplayedResult = [];
|
|
|
|
this._terms = [];
|
|
|
|
this._pendingClear = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
getResultsForDisplay: function() {
|
|
|
|
let alreadyVisible = this._pendingClear ? 0 : this.getVisibleResultCount();
|
|
|
|
let canDisplay = MAX_LIST_SEARCH_RESULTS_ROWS - alreadyVisible;
|
|
|
|
|
|
|
|
let newResults = this._notDisplayedResult.splice(0, canDisplay);
|
|
|
|
return newResults;
|
|
|
|
},
|
|
|
|
|
|
|
|
getVisibleResultCount: function() {
|
|
|
|
return this._content.get_n_children();
|
|
|
|
},
|
|
|
|
|
|
|
|
hasMoreResults: function() {
|
|
|
|
return this._notDisplayedResult.length > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
setResults: function(results, terms) {
|
|
|
|
// copy the lists
|
|
|
|
this._notDisplayedResult = results.slice(0);
|
|
|
|
this._terms = terms.slice(0);
|
|
|
|
this._pendingClear = true;
|
|
|
|
},
|
|
|
|
|
2013-03-11 14:21:42 -04:00
|
|
|
_keyFocusIn: function(icon) {
|
|
|
|
this.emit('key-focus-in', icon);
|
|
|
|
},
|
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
renderResults: function(metas) {
|
|
|
|
for (let i = 0; i < metas.length; i++) {
|
|
|
|
let display = new ListSearchResult(this.provider, metas[i], this._terms);
|
2013-03-11 14:21:42 -04:00
|
|
|
display.actor.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
|
2012-08-01 21:48:10 -04:00
|
|
|
this._content.add_actor(display.actor);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function () {
|
|
|
|
this._content.destroy_all_children();
|
|
|
|
this._pendingClear = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFirstResult: function() {
|
|
|
|
if (this.getVisibleResultCount() > 0)
|
|
|
|
return this._content.get_child_at_index(0)._delegate;
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
2013-03-11 14:21:42 -04:00
|
|
|
Signals.addSignalMethods(ListSearchResults.prototype);
|
2010-10-14 08:27:28 -04:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const GridSearchResults = new Lang.Class({
|
|
|
|
Name: 'GridSearchResults',
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2012-11-27 15:06:12 -05:00
|
|
|
_init: function(provider) {
|
2012-11-27 15:05:32 -05:00
|
|
|
this.provider = provider;
|
2011-11-20 11:07:14 -05:00
|
|
|
|
2012-11-27 15:06:12 -05:00
|
|
|
this._grid = new IconGrid.IconGrid({ rowLimit: MAX_GRID_SEARCH_RESULTS_ROWS,
|
|
|
|
xAlign: St.Align.START });
|
2012-08-01 21:48:10 -04:00
|
|
|
this.actor = new St.Bin({ x_align: St.Align.MIDDLE });
|
2011-03-21 18:53:07 -04:00
|
|
|
|
2010-10-14 08:27:28 -04:00
|
|
|
this.actor.set_child(this._grid.actor);
|
2012-08-01 21:48:10 -04:00
|
|
|
|
2011-03-21 18:53:07 -04:00
|
|
|
this._notDisplayedResult = [];
|
|
|
|
this._terms = [];
|
2012-02-21 13:53:25 -05:00
|
|
|
this._pendingClear = false;
|
2011-03-21 18:53:07 -04:00
|
|
|
},
|
|
|
|
|
2012-02-17 13:39:25 -05:00
|
|
|
getResultsForDisplay: function() {
|
2012-02-21 13:53:25 -05:00
|
|
|
let alreadyVisible = this._pendingClear ? 0 : this._grid.visibleItemsCount();
|
2012-08-01 21:48:10 -04:00
|
|
|
let canDisplay = this._grid.childrenInRow(this.actor.width) * this._grid.getRowLimit()
|
2012-02-21 13:53:25 -05:00
|
|
|
- alreadyVisible;
|
2011-03-21 18:53:07 -04:00
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
let newResults = this._notDisplayedResult.splice(0, canDisplay);
|
|
|
|
return newResults;
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getVisibleResultCount: function() {
|
2010-10-14 08:27:28 -04:00
|
|
|
return this._grid.visibleItemsCount();
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2012-08-09 17:52:36 -04:00
|
|
|
hasMoreResults: function() {
|
|
|
|
return this._notDisplayedResult.length > 0;
|
|
|
|
},
|
|
|
|
|
2012-02-17 13:39:25 -05:00
|
|
|
setResults: function(results, terms) {
|
2011-03-21 18:53:07 -04:00
|
|
|
// copy the lists
|
|
|
|
this._notDisplayedResult = results.slice(0);
|
|
|
|
this._terms = terms.slice(0);
|
2012-02-21 13:53:25 -05:00
|
|
|
this._pendingClear = true;
|
2012-02-17 13:39:25 -05:00
|
|
|
},
|
|
|
|
|
2013-03-11 14:21:42 -04:00
|
|
|
_keyFocusIn: function(icon) {
|
|
|
|
this.emit('key-focus-in', icon);
|
|
|
|
},
|
|
|
|
|
2012-02-17 13:39:25 -05:00
|
|
|
renderResults: function(metas) {
|
|
|
|
for (let i = 0; i < metas.length; i++) {
|
2012-08-01 21:48:10 -04:00
|
|
|
let display = new GridSearchResult(this.provider, metas[i], this._terms);
|
2013-03-11 14:21:42 -04:00
|
|
|
display.actor.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
|
2012-02-17 13:39:25 -05:00
|
|
|
this._grid.addItem(display.actor);
|
|
|
|
}
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2010-10-14 08:27:28 -04:00
|
|
|
clear: function () {
|
|
|
|
this._grid.removeAll();
|
2012-02-21 13:53:25 -05:00
|
|
|
this._pendingClear = false;
|
2010-10-14 08:27:28 -04:00
|
|
|
},
|
|
|
|
|
2011-11-13 22:13:26 -05:00
|
|
|
getFirstResult: function() {
|
|
|
|
if (this.getVisibleResultCount() > 0)
|
|
|
|
return this._grid.getItemAtIndex(0)._delegate;
|
|
|
|
else
|
|
|
|
return null;
|
2010-11-18 04:23:44 -05:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2013-03-11 14:21:42 -04:00
|
|
|
Signals.addSignalMethods(GridSearchResults.prototype);
|
2010-10-14 08:27:28 -04:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const SearchResults = new Lang.Class({
|
|
|
|
Name: 'SearchResults',
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2012-02-21 15:25:36 -05:00
|
|
|
_init: function(searchSystem) {
|
2010-11-18 04:23:44 -05:00
|
|
|
this._searchSystem = searchSystem;
|
2012-05-07 11:44:28 -04:00
|
|
|
this._searchSystem.connect('search-updated', Lang.bind(this, this._updateResults));
|
2011-01-17 16:38:47 -05:00
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ name: 'searchResults',
|
|
|
|
vertical: true });
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2010-10-14 08:27:28 -04:00
|
|
|
this._content = new St.BoxLayout({ name: 'searchResultsContent',
|
|
|
|
vertical: true });
|
2013-01-23 14:35:28 -05:00
|
|
|
this._contentBin = new MaxWidthBin({ name: 'searchResultsBin',
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
child: this._content });
|
|
|
|
|
|
|
|
let scrollChild = new St.BoxLayout();
|
|
|
|
scrollChild.add(this._contentBin, { expand: true });
|
2010-10-14 08:27:28 -04:00
|
|
|
|
2012-11-25 23:33:44 -05:00
|
|
|
this._scrollView = new St.ScrollView({ x_fill: true,
|
|
|
|
y_fill: false,
|
2013-02-25 14:48:06 -05:00
|
|
|
overlay_scrollbars: true,
|
|
|
|
style_class: 'search-display vfade' });
|
2012-11-25 23:33:44 -05:00
|
|
|
this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
2013-01-23 14:35:28 -05:00
|
|
|
this._scrollView.add_actor(scrollChild);
|
2012-11-25 23:33:44 -05:00
|
|
|
let action = new Clutter.PanAction({ interpolate: true });
|
|
|
|
action.connect('pan', Lang.bind(this, this._onPan));
|
|
|
|
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 });
|
2010-10-14 08:27:28 -04:00
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
this._statusText = new St.Label({ style_class: 'search-statustext' });
|
2012-08-31 13:27:35 -04:00
|
|
|
this._statusBin = new St.Bin({ x_align: St.Align.MIDDLE,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
this._content.add(this._statusBin, { expand: true });
|
|
|
|
this._statusBin.add_actor(this._statusText);
|
2010-11-18 04:23:44 -05:00
|
|
|
this._providers = this._searchSystem.getProviders();
|
|
|
|
this._providerMeta = [];
|
2011-07-24 06:29:36 -04:00
|
|
|
for (let i = 0; i < this._providers.length; i++) {
|
2010-11-18 04:23:44 -05:00
|
|
|
this.createProviderMeta(this._providers[i]);
|
2011-07-24 06:29:36 -04:00
|
|
|
}
|
2011-01-17 16:38:47 -05:00
|
|
|
|
2011-11-13 22:13:26 -05:00
|
|
|
this._highlightDefault = false;
|
|
|
|
this._defaultResult = null;
|
2011-01-17 16:38:47 -05:00
|
|
|
},
|
|
|
|
|
2012-11-25 23:33:44 -05:00
|
|
|
_onPan: function(action) {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2013-03-11 14:21:42 -04:00
|
|
|
_keyFocusIn: function(provider, icon) {
|
|
|
|
Util.ensureActorVisibleInScrollView(this._scrollView, icon);
|
|
|
|
},
|
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
createProviderMeta: function(provider) {
|
2012-08-01 21:48:10 -04:00
|
|
|
let providerBox = new St.BoxLayout({ style_class: 'search-section',
|
|
|
|
vertical: true });
|
2012-08-09 17:52:36 -04:00
|
|
|
let providerIcon = null;
|
2012-08-01 21:48:10 -04:00
|
|
|
let resultDisplay = null;
|
2012-08-09 17:52:36 -04:00
|
|
|
|
|
|
|
if (provider.appInfo) {
|
2012-08-01 21:48:10 -04:00
|
|
|
resultDisplay = new ListSearchResults(provider);
|
|
|
|
providerIcon = resultDisplay.providerIcon;
|
|
|
|
} else {
|
|
|
|
resultDisplay = new GridSearchResults(provider);
|
2012-08-09 17:52:36 -04:00
|
|
|
}
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2013-03-11 14:21:42 -04:00
|
|
|
resultDisplay.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
|
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
let resultDisplayBin = new St.Bin({ child: resultDisplay.actor,
|
2010-11-18 04:23:44 -05:00
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
providerBox.add(resultDisplayBin, { expand: true });
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
let separator = new Separator.HorizontalSeparator({ style_class: 'search-section-separator' });
|
|
|
|
providerBox.add(separator.actor);
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2011-08-28 07:20:37 -04:00
|
|
|
this._providerMeta.push({ provider: provider,
|
|
|
|
actor: providerBox,
|
2012-08-09 17:52:36 -04:00
|
|
|
icon: providerIcon,
|
2012-05-07 11:44:28 -04:00
|
|
|
resultDisplay: resultDisplay });
|
2010-10-14 08:27:28 -04:00
|
|
|
this._content.add(providerBox);
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2011-08-28 07:20:37 -04: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 04:23:44 -05:00
|
|
|
_clearDisplay: function() {
|
|
|
|
for (let i = 0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
meta.resultDisplay.clear();
|
|
|
|
meta.actor.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-21 13:53:25 -05:00
|
|
|
_clearDisplayForProvider: function(provider) {
|
|
|
|
let meta = this._metaForProvider(provider);
|
2011-07-24 06:29:36 -04:00
|
|
|
meta.resultDisplay.clear();
|
|
|
|
meta.actor.hide();
|
|
|
|
},
|
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
reset: function() {
|
|
|
|
this._searchSystem.reset();
|
2012-08-31 13:27:35 -04:00
|
|
|
this._statusBin.hide();
|
2010-11-18 04:23:44 -05:00
|
|
|
this._clearDisplay();
|
2013-02-08 11:49:37 -05:00
|
|
|
this._defaultResult = null;
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
startingSearch: function() {
|
|
|
|
this.reset();
|
2012-12-03 10:59:28 -05:00
|
|
|
this._statusText.set_text(_("Searching…"));
|
2012-08-31 13:27:35 -04:00
|
|
|
this._statusBin.show();
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_metaForProvider: function(provider) {
|
|
|
|
return this._providerMeta[this._providers.indexOf(provider)];
|
|
|
|
},
|
|
|
|
|
2012-02-21 13:53:25 -05:00
|
|
|
_maybeSetInitialSelection: function() {
|
2011-11-13 22:13:26 -05:00
|
|
|
let newDefaultResult = null;
|
|
|
|
|
2012-02-21 13:53:25 -05:00
|
|
|
for (let i = 0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
|
2012-03-10 10:20:47 -05:00
|
|
|
if (!meta.actor.visible)
|
|
|
|
continue;
|
|
|
|
|
2011-11-13 22:13:26 -05:00
|
|
|
let firstResult = meta.resultDisplay.getFirstResult();
|
2012-03-10 10:20:47 -05:00
|
|
|
if (firstResult) {
|
2011-11-13 22:13:26 -05:00
|
|
|
newDefaultResult = firstResult;
|
2012-02-21 13:53:25 -05:00
|
|
|
break; // select this one!
|
2011-11-13 22:13:26 -05:00
|
|
|
}
|
2012-02-21 13:53:25 -05:00
|
|
|
}
|
|
|
|
|
2011-11-13 22:13:26 -05:00
|
|
|
if (newDefaultResult != this._defaultResult) {
|
|
|
|
if (this._defaultResult)
|
|
|
|
this._defaultResult.setSelected(false);
|
|
|
|
if (newDefaultResult)
|
|
|
|
newDefaultResult.setSelected(this._highlightDefault);
|
|
|
|
|
|
|
|
this._defaultResult = newDefaultResult;
|
|
|
|
}
|
2012-02-21 13:53:25 -05:00
|
|
|
},
|
|
|
|
|
2012-05-07 11:44:28 -04:00
|
|
|
_updateStatusText: function () {
|
|
|
|
let haveResults = false;
|
|
|
|
|
|
|
|
for (let i = 0; i < this._providerMeta.length; ++i)
|
|
|
|
if (this._providerMeta[i].resultDisplay.getFirstResult()) {
|
|
|
|
haveResults = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!haveResults) {
|
2012-08-31 13:27:35 -04:00
|
|
|
this._statusText.set_text(_("No results."));
|
|
|
|
this._statusBin.show();
|
2012-05-07 11:44:28 -04:00
|
|
|
} else {
|
2012-08-31 13:27:35 -04:00
|
|
|
this._statusBin.hide();
|
2012-05-07 11:44:28 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateResults: function(searchSystem, results) {
|
2011-07-24 06:29:36 -04:00
|
|
|
let terms = searchSystem.getTerms();
|
2012-02-21 13:53:25 -05:00
|
|
|
let [provider, providerResults] = results;
|
2011-07-24 06:29:36 -04:00
|
|
|
let meta = this._metaForProvider(provider);
|
2012-02-21 13:53:25 -05:00
|
|
|
|
|
|
|
if (providerResults.length == 0) {
|
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.resultDisplay.setResults([], []);
|
2012-05-07 11:44:28 -04:00
|
|
|
this._maybeSetInitialSelection();
|
|
|
|
this._updateStatusText();
|
2012-02-21 13:53:25 -05:00
|
|
|
} else {
|
|
|
|
meta.resultDisplay.setResults(providerResults, terms);
|
|
|
|
let results = meta.resultDisplay.getResultsForDisplay();
|
|
|
|
|
2012-08-09 17:52:36 -04:00
|
|
|
if (meta.icon)
|
|
|
|
meta.icon.moreIcon.visible =
|
|
|
|
meta.resultDisplay.hasMoreResults() &&
|
|
|
|
provider.canLaunchSearch;
|
|
|
|
|
2012-05-02 15:54:25 -04:00
|
|
|
provider.getResultMetas(results, Lang.bind(this, function(metas) {
|
2012-02-21 13:53:25 -05:00
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.actor.show();
|
2012-05-02 15:54:25 -04:00
|
|
|
|
2012-05-07 11:44:28 -04:00
|
|
|
// Hiding drops the key focus if we have it
|
2012-05-02 15:54:25 -04:00
|
|
|
let focus = global.stage.get_key_focus();
|
2012-05-07 11:44:28 -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.
|
2012-05-02 15:54:25 -04:00
|
|
|
this._content.hide();
|
|
|
|
|
2012-02-21 13:53:25 -05:00
|
|
|
meta.resultDisplay.renderResults(metas);
|
2012-05-02 15:54:25 -04:00
|
|
|
this._maybeSetInitialSelection();
|
2012-05-07 11:44:28 -04:00
|
|
|
this._updateStatusText();
|
2012-05-02 15:54:25 -04:00
|
|
|
|
|
|
|
this._content.show();
|
|
|
|
if (this._content.contains(focus))
|
|
|
|
global.stage.set_key_focus(focus);
|
|
|
|
}));
|
2012-02-21 13:53:25 -05:00
|
|
|
}
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2011-11-13 22:13:26 -05:00
|
|
|
activateDefault: function() {
|
2012-03-10 10:20:47 -05:00
|
|
|
if (this._defaultResult)
|
2011-11-13 22:13:26 -05:00
|
|
|
this._defaultResult.activate();
|
|
|
|
},
|
|
|
|
|
|
|
|
highlightDefault: function(highlight) {
|
|
|
|
this._highlightDefault = highlight;
|
|
|
|
if (this._defaultResult)
|
|
|
|
this._defaultResult.setSelected(highlight);
|
|
|
|
},
|
|
|
|
|
|
|
|
navigateFocus: function(direction) {
|
2012-03-09 21:40:46 -05:00
|
|
|
let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
|
|
|
|
if (direction == Gtk.DirectionType.TAB_BACKWARD ||
|
|
|
|
direction == (rtl ? Gtk.DirectionType.RIGHT
|
|
|
|
: Gtk.DirectionType.LEFT) ||
|
|
|
|
direction == Gtk.DirectionType.UP) {
|
|
|
|
this.actor.navigate_focus(null, direction, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let from = this._defaultResult ? this._defaultResult.actor : null;
|
|
|
|
this.actor.navigate_focus(from, direction, false);
|
2010-11-18 04:23:44 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2012-08-09 17:52:36 -04:00
|
|
|
|
|
|
|
const ProviderIcon = new Lang.Class({
|
|
|
|
Name: 'ProviderIcon',
|
|
|
|
Extends: St.Button,
|
|
|
|
|
|
|
|
PROVIDER_ICON_SIZE: 48,
|
|
|
|
|
|
|
|
_init: function(provider) {
|
|
|
|
this.provider = provider;
|
|
|
|
this.parent({ style_class: 'search-provider-icon',
|
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
2013-03-17 15:40:57 -04:00
|
|
|
accessible_name: provider.appInfo.get_name(),
|
2012-08-09 17:52:36 -04:00
|
|
|
track_hover: true });
|
|
|
|
|
|
|
|
this._content = new St.Widget({ layout_manager: new Clutter.BinLayout() });
|
|
|
|
this.set_child(this._content);
|
|
|
|
|
|
|
|
let rtl = (this.get_text_direction() == Clutter.TextDirection.RTL);
|
|
|
|
|
|
|
|
this.moreIcon = new St.Widget({ style_class: 'search-provider-icon-more',
|
|
|
|
visible: false,
|
|
|
|
x_align: rtl ? Clutter.ActorAlign.START : Clutter.ActorAlign.END,
|
|
|
|
y_align: Clutter.ActorAlign.END,
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true });
|
|
|
|
|
|
|
|
let icon = new St.Icon({ icon_size: this.PROVIDER_ICON_SIZE,
|
|
|
|
gicon: provider.appInfo.get_icon() });
|
|
|
|
this._content.add_actor(icon);
|
|
|
|
this._content.add_actor(this.moreIcon);
|
|
|
|
}
|
|
|
|
});
|