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
|
|
|
|
2013-08-29 17:25:13 -04:00
|
|
|
let content = provider.createResultObject(metaInfo, terms);
|
2012-12-10 13:05:58 -05:00
|
|
|
let dragSource = null;
|
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
if (content == null) {
|
2013-08-29 17:25:13 -04:00
|
|
|
let actor = 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'] });
|
2013-08-29 17:25:13 -04:00
|
|
|
actor.set_child(icon.actor);
|
|
|
|
actor.label_actor = icon.label;
|
2012-12-10 13:05:58 -05:00
|
|
|
dragSource = icon.icon;
|
2013-08-29 17:25:13 -04:00
|
|
|
content = { actor: actor, 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
|
|
|
}
|
|
|
|
|
2013-08-29 17:25:13 -04:00
|
|
|
this.actor.set_child(content.actor);
|
|
|
|
this.actor.label_actor = content.actor.label_actor;
|
|
|
|
this.icon = content.icon;
|
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
|
|
|
|
2013-02-08 17:05:22 -05:00
|
|
|
const SearchResultsBase = new Lang.Class({
|
|
|
|
Name: 'SearchResultsBase',
|
|
|
|
|
|
|
|
_init: function(provider) {
|
|
|
|
this.provider = provider;
|
|
|
|
|
|
|
|
this._terms = [];
|
2013-02-08 18:07:11 -05:00
|
|
|
|
|
|
|
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 });
|
|
|
|
|
|
|
|
let separator = new Separator.HorizontalSeparator({ style_class: 'search-section-separator' });
|
|
|
|
this.actor.add(separator.actor);
|
|
|
|
},
|
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
destroy: function() {
|
|
|
|
this.actor.destroy();
|
|
|
|
this._terms = [];
|
|
|
|
},
|
|
|
|
|
2013-02-08 18:07:11 -05:00
|
|
|
_clearResultDisplay: function() {
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function() {
|
|
|
|
this._clearResultDisplay();
|
|
|
|
this.actor.hide();
|
2013-02-08 17:05:22 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_keyFocusIn: function(icon) {
|
|
|
|
this.emit('key-focus-in', icon);
|
|
|
|
},
|
|
|
|
|
2013-02-08 17:45:53 -05:00
|
|
|
_setMoreIconVisible: function(visible) {
|
|
|
|
},
|
|
|
|
|
|
|
|
updateSearch: function(providerResults, terms, callback) {
|
2013-02-08 18:42:03 -05:00
|
|
|
this._terms = terms;
|
|
|
|
|
2013-02-08 17:45:53 -05:00
|
|
|
if (providerResults.length == 0) {
|
2013-02-08 18:07:11 -05:00
|
|
|
this._clearResultDisplay();
|
|
|
|
this.actor.hide();
|
2013-02-08 17:45:53 -05:00
|
|
|
callback();
|
|
|
|
} else {
|
2013-02-08 18:42:03 -05:00
|
|
|
let maxResults = this._getMaxDisplayedResults();
|
|
|
|
let results = providerResults.slice(0, maxResults);
|
|
|
|
let hasMoreResults = results.length < providerResults.length;
|
2013-02-08 17:45:53 -05:00
|
|
|
|
|
|
|
this.provider.getResultMetas(results, Lang.bind(this, function(metas) {
|
|
|
|
this.clear();
|
|
|
|
|
|
|
|
// 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();
|
2013-02-08 18:07:11 -05:00
|
|
|
this._clearResultDisplay();
|
2013-02-14 14:35:01 -05:00
|
|
|
this._renderResults(metas);
|
2013-02-08 18:42:03 -05:00
|
|
|
this._setMoreIconVisible(hasMoreResults && this.provider.canLaunchSearch);
|
2013-02-08 17:45:53 -05:00
|
|
|
this.actor.show();
|
|
|
|
callback();
|
|
|
|
}));
|
|
|
|
}
|
2013-02-08 17:05:22 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-01 21:48:10 -04:00
|
|
|
const ListSearchResults = new Lang.Class({
|
|
|
|
Name: 'ListSearchResults',
|
2013-02-08 17:05:22 -05:00
|
|
|
Extends: SearchResultsBase,
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
_init: function(provider) {
|
2013-02-08 17:05:22 -05:00
|
|
|
this.parent(provider);
|
2012-08-01 21:48:10 -04:00
|
|
|
|
2013-02-08 18:07:11 -05:00
|
|
|
this._container = new St.BoxLayout({ style_class: 'search-section-content' });
|
2012-08-01 21:48:10 -04:00
|
|
|
this.providerIcon = new ProviderIcon(provider);
|
|
|
|
this.providerIcon.connect('clicked', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
provider.launchSearch(this._terms);
|
|
|
|
Main.overview.toggle();
|
|
|
|
}));
|
|
|
|
|
2013-02-08 18:07:11 -05:00
|
|
|
this._container.add(this.providerIcon, { x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
2012-08-01 21:48:10 -04:00
|
|
|
|
|
|
|
this._content = new St.BoxLayout({ style_class: 'list-search-results',
|
|
|
|
vertical: true });
|
2013-02-08 18:07:11 -05:00
|
|
|
this._container.add(this._content, { expand: true });
|
|
|
|
|
|
|
|
this._resultDisplayBin.set_child(this._container);
|
2012-08-01 21:48:10 -04:00
|
|
|
},
|
|
|
|
|
2013-02-08 17:45:53 -05:00
|
|
|
_setMoreIconVisible: function(visible) {
|
|
|
|
this.providerIcon.moreIcon.visible = true;
|
|
|
|
},
|
|
|
|
|
2013-02-08 18:42:03 -05:00
|
|
|
_getMaxDisplayedResults: function() {
|
|
|
|
return MAX_LIST_SEARCH_RESULTS_ROWS;
|
2012-08-01 21:48:10 -04:00
|
|
|
},
|
|
|
|
|
2013-02-14 14:35:01 -05:00
|
|
|
_renderResults: function(metas) {
|
2012-08-01 21:48:10 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-08 18:07:11 -05:00
|
|
|
_clearResultDisplay: function () {
|
2012-08-01 21:48:10 -04:00
|
|
|
this._content.destroy_all_children();
|
|
|
|
},
|
|
|
|
|
|
|
|
getFirstResult: function() {
|
2013-02-08 18:34:24 -05:00
|
|
|
if (this._content.get_n_children() > 0)
|
2012-08-01 21:48:10 -04:00
|
|
|
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',
|
2013-02-08 17:05:22 -05:00
|
|
|
Extends: SearchResultsBase,
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2012-11-27 15:06:12 -05:00
|
|
|
_init: function(provider) {
|
2013-02-08 17:05:22 -05:00
|
|
|
this.parent(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 });
|
2013-02-08 18:07:11 -05:00
|
|
|
this._bin = new St.Bin({ x_align: St.Align.MIDDLE });
|
|
|
|
this._bin.set_child(this._grid.actor);
|
2011-03-21 18:53:07 -04:00
|
|
|
|
2013-02-08 18:07:11 -05:00
|
|
|
this._resultDisplayBin.set_child(this._bin);
|
2011-03-21 18:53:07 -04:00
|
|
|
},
|
|
|
|
|
2013-02-08 18:42:03 -05:00
|
|
|
_getMaxDisplayedResults: function() {
|
2013-08-22 17:27:05 -04:00
|
|
|
return this._grid.columnsForWidth(this._bin.width) * this._grid.getRowLimit();
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2013-02-14 14:35:01 -05:00
|
|
|
_renderResults: function(metas) {
|
2012-02-17 13:39:25 -05:00
|
|
|
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));
|
2013-08-29 17:25:13 -04:00
|
|
|
this._grid.addItem(display);
|
2012-02-17 13:39:25 -05:00
|
|
|
}
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2013-02-08 18:07:11 -05:00
|
|
|
_clearResultDisplay: function () {
|
2010-10-14 08:27:28 -04:00
|
|
|
this._grid.removeAll();
|
|
|
|
},
|
|
|
|
|
2011-11-13 22:13:26 -05:00
|
|
|
getFirstResult: function() {
|
2013-02-08 18:34:24 -05:00
|
|
|
if (this._grid.visibleItemsCount() > 0)
|
2011-11-13 22:13:26 -05:00
|
|
|
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();
|
2013-02-08 18:23:53 -05:00
|
|
|
this._providerDisplays = {};
|
2011-07-24 06:29:36 -04:00
|
|
|
for (let i = 0; i < this._providers.length; i++) {
|
2013-02-08 18:23:53 -05:00
|
|
|
this.createProviderDisplay(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);
|
|
|
|
},
|
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
createProviderDisplay: function(provider) {
|
|
|
|
let providerDisplay = null;
|
2012-08-09 17:52:36 -04:00
|
|
|
|
|
|
|
if (provider.appInfo) {
|
2013-02-08 18:23:53 -05:00
|
|
|
providerDisplay = new ListSearchResults(provider);
|
2012-08-01 21:48:10 -04:00
|
|
|
} else {
|
2013-02-08 18:23:53 -05:00
|
|
|
providerDisplay = new GridSearchResults(provider);
|
2012-08-09 17:52:36 -04:00
|
|
|
}
|
2010-11-18 04:23:44 -05:00
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
providerDisplay.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
|
|
|
|
this._providerDisplays[provider.id] = providerDisplay;
|
|
|
|
this._content.add(providerDisplay.actor);
|
2010-11-18 04:23:44 -05:00
|
|
|
},
|
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
destroyProviderDisplay: function(provider) {
|
|
|
|
this._providerDisplays[provider.id].destroy();
|
|
|
|
delete this._providerDisplays[provider.id];
|
2011-08-28 07:20:37 -04:00
|
|
|
},
|
|
|
|
|
2010-11-18 04:23:44 -05:00
|
|
|
_clearDisplay: function() {
|
2013-02-08 18:23:53 -05:00
|
|
|
for (let i = 0; i < this._providers.length; i++) {
|
|
|
|
let provider = this._providers[i];
|
|
|
|
let providerDisplay = this._providerDisplays[provider.id];
|
|
|
|
providerDisplay.clear();
|
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
|
|
|
},
|
|
|
|
|
2012-02-21 13:53:25 -05:00
|
|
|
_maybeSetInitialSelection: function() {
|
2011-11-13 22:13:26 -05:00
|
|
|
let newDefaultResult = null;
|
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
for (let i = 0; i < this._providers.length; i++) {
|
|
|
|
let provider = this._providers[i];
|
|
|
|
let display = this._providerDisplays[provider.id];
|
2012-02-21 13:53:25 -05:00
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
if (!display.actor.visible)
|
2012-03-10 10:20:47 -05:00
|
|
|
continue;
|
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
let firstResult = display.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;
|
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
for (let i = 0; i < this._providers.length; i++) {
|
|
|
|
let provider = this._providers[i];
|
|
|
|
let display = this._providerDisplays[provider.id];
|
|
|
|
if (display.getFirstResult()) {
|
2012-05-07 11:44:28 -04:00
|
|
|
haveResults = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-02-08 18:23:53 -05:00
|
|
|
}
|
2012-05-07 11:44:28 -04:00
|
|
|
|
|
|
|
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;
|
2013-02-08 18:23:53 -05:00
|
|
|
let display = this._providerDisplays[provider.id];
|
2012-02-21 13:53:25 -05:00
|
|
|
|
2013-02-08 18:23:53 -05:00
|
|
|
display.updateSearch(providerResults, terms, Lang.bind(this, function() {
|
2012-05-07 11:44:28 -04:00
|
|
|
this._maybeSetInitialSelection();
|
|
|
|
this._updateStatusText();
|
2013-02-08 17:45:53 -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);
|
|
|
|
}
|
|
|
|
});
|