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;
|
2012-08-08 16:10:00 +00:00
|
|
|
const Signals = imports.signals;
|
2010-10-14 12:27:28 +00:00
|
|
|
const St = imports.gi.St;
|
2012-03-16 16:17:23 +00:00
|
|
|
const Atk = imports.gi.Atk;
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2012-08-09 21:52:36 +00:00
|
|
|
const AppDisplay = imports.ui.appDisplay;
|
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;
|
2012-08-02 01:48:10 +00:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-11-18 09:23:44 +00:00
|
|
|
const Search = imports.ui.search;
|
|
|
|
|
2012-08-02 01:48:10 +00:00
|
|
|
const MAX_SEARCH_RESULTS_ROWS = 3;
|
|
|
|
const MAX_GRID_SEARCH_RESULTS_ROWS = 1;
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
|
2012-08-02 01:48:10 +00:00
|
|
|
const ListSearchResult = new Lang.Class({
|
|
|
|
Name: 'ListSearchResult',
|
|
|
|
|
|
|
|
ICON_SIZE: 64,
|
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',
|
2012-08-02 01:48:10 +00:00
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
track_hover: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
this.actor._delegate = this;
|
|
|
|
|
|
|
|
let content = new St.BoxLayout({ style_class: 'search-result-content',
|
|
|
|
vertical: false });
|
|
|
|
this._content = content;
|
|
|
|
this.actor.set_child(content);
|
|
|
|
|
|
|
|
// An icon for, or thumbnail of, content
|
|
|
|
let icon = this.metaInfo['createIcon'](this.ICON_SIZE);
|
|
|
|
if (icon) {
|
|
|
|
let iconBin = new St.Bin({ style_class: 'search-result-icon',
|
|
|
|
child: icon });
|
|
|
|
content.add(iconBin);
|
|
|
|
}
|
|
|
|
|
|
|
|
let details = new St.BoxLayout({ style_class: 'search-result-details',
|
|
|
|
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: 'search-result-details-title',
|
|
|
|
text: this.metaInfo['name'] })
|
|
|
|
details.add(title, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
// TODO: could highlight terms in the description here, or should
|
|
|
|
// providers provide what should be highlighted?
|
|
|
|
if (this.metaInfo['description']) {
|
|
|
|
let description = new St.Label({ style_class: 'search-result-details-description',
|
|
|
|
text: this.metaInfo['description'] });
|
|
|
|
details.add(description, { x_fill: false,
|
|
|
|
y_fill: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.END });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onResultClicked));
|
|
|
|
},
|
|
|
|
|
|
|
|
setSelected: function(selected) {
|
|
|
|
if (selected)
|
|
|
|
this.actor.add_style_pseudo_class('selected');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_pseudo_class('selected');
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
this.provider.activateResult(this.metaInfo.id);
|
|
|
|
Main.overview.toggle();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onResultClicked: function(actor) {
|
|
|
|
this.activate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const ListSearchResults = new Lang.Class({
|
|
|
|
Name: 'ListSearchResults',
|
|
|
|
Extends: Search.SearchResultDisplay,
|
|
|
|
|
|
|
|
_init: function(provider) {
|
|
|
|
this.parent(provider);
|
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'results-list',
|
|
|
|
vertical: true });
|
|
|
|
this.actor.connect('notify::width', Lang.bind(this, function() {
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
|
|
|
|
let results = this.getResultsForDisplay();
|
|
|
|
if (results.length == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
provider.getResultMetas(results, Lang.bind(this, this.renderResults));
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
this._notDisplayedResult = [];
|
|
|
|
this._terms = [];
|
|
|
|
this._pendingClear = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
getResultsForDisplay: function() {
|
|
|
|
let alreadyVisible = this._pendingClear ? 0 : this.getVisibleResultCount();
|
|
|
|
let canDisplay = MAX_SEARCH_RESULTS_ROWS - alreadyVisible;
|
|
|
|
|
|
|
|
let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
|
|
|
|
|
|
|
|
return this._notDisplayedResult.splice(0, numResults);
|
|
|
|
},
|
|
|
|
|
|
|
|
getVisibleResultCount: function() {
|
|
|
|
return this.actor.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;
|
|
|
|
},
|
|
|
|
|
|
|
|
renderResults: function(metas) {
|
|
|
|
for (let i = 0; i < metas.length; i++) {
|
|
|
|
let display = new ListSearchResult(this.provider, metas[i], this._terms);
|
|
|
|
this.addItem(display.actor);
|
2012-08-08 16:10:00 +00:00
|
|
|
|
|
|
|
display.actor.connect('key-focus-in', Lang.bind(this, this._onFocusedProviderChanged));
|
2012-08-02 01:48:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function () {
|
|
|
|
this.actor.destroy_all_children();
|
|
|
|
this._pendingClear = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFirstResult: function() {
|
|
|
|
if (this.getVisibleResultCount() > 0)
|
|
|
|
return this.getItemAtIndex(0)._delegate;
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
addItem: function(actor, index) {
|
|
|
|
if (index !== undefined)
|
|
|
|
this.actor.insert_child_at_index(actor, index);
|
|
|
|
else
|
|
|
|
this.actor.add_actor(actor);
|
|
|
|
},
|
|
|
|
|
|
|
|
getItemAtIndex: function(index) {
|
|
|
|
return this.actor.get_child_at_index(index);
|
2012-08-08 16:10:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onFocusedProviderChanged: function() {
|
|
|
|
this.emit('focused-provider-changed');
|
2012-08-02 01:48:10 +00:00
|
|
|
}
|
|
|
|
});
|
2012-08-08 16:10:00 +00:00
|
|
|
Signals.addSignalMethods(ListSearchResults.prototype);
|
2012-08-02 01:48:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
const GridSearchResult = new Lang.Class({
|
|
|
|
Name: 'GridSearchResult',
|
|
|
|
|
|
|
|
_init: function(provider, metaInfo, terms) {
|
|
|
|
this.provider = provider;
|
|
|
|
this.metaInfo = metaInfo;
|
|
|
|
this.actor = new St.Button({ style_class: 'grid-search-result',
|
2011-01-25 21:22:00 +00:00
|
|
|
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) {
|
2012-08-02 01:48:10 +00:00
|
|
|
content = new St.Bin({ style_class: 'grid-search-result-content',
|
2010-10-14 12:27:28 +00:00
|
|
|
reactive: true,
|
2011-11-12 04:40:56 +00:00
|
|
|
can_focus: true,
|
2012-03-16 16:17:23 +00:00
|
|
|
track_hover: true,
|
|
|
|
accessible_role: Atk.Role.PUSH_BUTTON });
|
2010-10-14 12:27:28 +00:00
|
|
|
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;
|
2012-03-16 16:17:23 +00:00
|
|
|
content.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
|
|
|
}
|
2012-08-02 01:48:10 +00:00
|
|
|
this.content = content;
|
2010-11-18 09:23:44 +00:00
|
|
|
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)
|
2012-08-02 01:48:10 +00:00
|
|
|
this.content.add_style_pseudo_class('selected');
|
2010-11-18 09:23:44 +00:00
|
|
|
else
|
2012-08-02 01:48:10 +00:00
|
|
|
this.content.remove_style_pseudo_class('selected');
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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
|
2012-08-02 01:48:10 +00:00
|
|
|
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);
|
|
|
|
|
2012-08-02 01:48:10 +00:00
|
|
|
this._grid = grid || new IconGrid.IconGrid({ rowLimit: MAX_GRID_SEARCH_RESULTS_ROWS,
|
2011-08-28 20:14:15 +00:00
|
|
|
xAlign: St.Align.START });
|
2010-10-14 12:27:28 +00:00
|
|
|
this.actor = new St.Bin({ x_align: St.Align.START });
|
|
|
|
this.actor.set_child(this._grid.actor);
|
2012-08-09 21:52:36 +00:00
|
|
|
|
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-05-02 19:54:25 +00:00
|
|
|
provider.getResultMetas(results, Lang.bind(this, this.renderResults));
|
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-08-09 21:52:36 +00:00
|
|
|
this._grid.actor.ensure_style();
|
2012-02-21 18:53:25 +00:00
|
|
|
let alreadyVisible = this._pendingClear ? 0 : this._grid.visibleItemsCount();
|
2012-05-08 20:03:17 +00:00
|
|
|
let canDisplay = this._grid.childrenInRow(this._width) * this._grid.getRowLimit()
|
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-08-09 21:52:36 +00:00
|
|
|
hasMoreResults: function() {
|
|
|
|
return this._notDisplayedResult.length > 0;
|
|
|
|
},
|
|
|
|
|
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++) {
|
2012-08-02 01:48:10 +00:00
|
|
|
let display = new GridSearchResult(this.provider, metas[i], this._terms);
|
2012-02-17 18:39:25 +00:00
|
|
|
this._grid.addItem(display.actor);
|
2012-08-08 16:10:00 +00:00
|
|
|
|
|
|
|
display.content.connect('key-focus-in', Lang.bind(this, this._onFocusedProviderChanged));
|
2012-02-17 18:39:25 +00:00
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
2010-10-14 12:27:28 +00:00
|
|
|
clear: function () {
|
|
|
|
this._grid.removeAll();
|
2012-02-21 18:53:25 +00:00
|
|
|
this._pendingClear = false;
|
2010-10-14 12:27:28 +00:00
|
|
|
},
|
|
|
|
|
2011-11-14 03:13:26 +00:00
|
|
|
getFirstResult: function() {
|
|
|
|
if (this.getVisibleResultCount() > 0)
|
|
|
|
return this._grid.getItemAtIndex(0)._delegate;
|
|
|
|
else
|
|
|
|
return null;
|
2012-08-08 16:10:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onFocusedProviderChanged: function() {
|
|
|
|
this.emit('focused-provider-changed');
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
2011-11-20 16:07:14 +00:00
|
|
|
});
|
2012-08-08 16:10:00 +00:00
|
|
|
Signals.addSignalMethods(GridSearchResults.prototype);
|
|
|
|
|
2010-10-14 12:27:28 +00:00
|
|
|
|
2012-08-02 01:48:10 +00:00
|
|
|
const SearchDisplay = new Lang.Class({
|
|
|
|
Name: 'SearchDisplay',
|
2010-11-18 09:23:44 +00:00
|
|
|
|
2012-02-21 20:25:36 +00:00
|
|
|
_init: function(searchSystem) {
|
2010-11-18 09:23:44 +00:00
|
|
|
this._searchSystem = searchSystem;
|
2012-05-07 15:44:28 +00:00
|
|
|
this._searchSystem.connect('search-updated', Lang.bind(this, this._updateResults));
|
2011-01-17 21:38:47 +00:00
|
|
|
|
|
|
|
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,
|
2012-08-31 17:27:35 +00:00
|
|
|
y_fill: true,
|
2011-01-17 21:38:47 +00:00
|
|
|
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' });
|
2012-08-31 17:27:35 +00: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 09:23:44 +00:00
|
|
|
this._providers = this._searchSystem.getProviders();
|
|
|
|
this._providerMeta = [];
|
2011-07-24 10:29:36 +00:00
|
|
|
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
|
|
|
}
|
2011-01-17 21:38:47 +00:00
|
|
|
|
2011-11-14 03:13:26 +00:00
|
|
|
this._highlightDefault = false;
|
|
|
|
this._defaultResult = null;
|
2011-01-17 21:38:47 +00:00
|
|
|
},
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
createProviderMeta: function(provider) {
|
2012-08-02 01:48:10 +00:00
|
|
|
let providerBox = new St.BoxLayout({ style_class: 'search-section',
|
|
|
|
vertical: true });
|
|
|
|
let providerBoxContent = new St.BoxLayout({ style_class: 'search-section-content' });
|
2012-08-09 21:52:36 +00:00
|
|
|
let isAppsProvider = (provider instanceof AppDisplay.AppSearchProvider);
|
|
|
|
|
|
|
|
let providerIcon;
|
|
|
|
if (!isAppsProvider) {
|
2012-08-16 01:28:49 +00:00
|
|
|
let separator = new PopupMenu.HorzSeparator({ style_class: 'search-section-separator' });
|
|
|
|
providerBox.add(separator.actor, { expand: true });
|
2012-08-02 01:48:10 +00:00
|
|
|
|
2012-08-09 21:52:36 +00:00
|
|
|
providerIcon = new ProviderIcon(provider);
|
|
|
|
providerIcon.connect('launch-search', Lang.bind(this, function(providerIcon) {
|
|
|
|
this._searchSystem.launchSearch(providerIcon.provider);
|
|
|
|
}));
|
2012-08-02 01:48:10 +00:00
|
|
|
providerBoxContent.add(providerIcon.actor, { x_fill: false,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
2012-08-09 21:52:36 +00:00
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
|
|
|
|
let resultDisplayBin = new St.Bin({ style_class: 'search-section-results',
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
2012-08-02 01:48:10 +00:00
|
|
|
providerBoxContent.add(resultDisplayBin, { expand: true });
|
|
|
|
|
|
|
|
providerBox.add(providerBoxContent);
|
2012-08-09 21:52:36 +00:00
|
|
|
|
2012-08-02 01:48:10 +00:00
|
|
|
let resultDisplay;
|
|
|
|
if (isAppsProvider)
|
|
|
|
resultDisplay = new GridSearchResults(provider);
|
|
|
|
else
|
|
|
|
resultDisplay = new ListSearchResults(provider);
|
2012-08-08 16:10:00 +00:00
|
|
|
|
|
|
|
resultDisplay.connect('focused-provider-changed', Lang.bind(this, this._updateProviderIconCanFocus));
|
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-08-09 21:52:36 +00:00
|
|
|
icon: providerIcon,
|
2012-05-07 15:44:28 +00:00
|
|
|
resultDisplay: resultDisplay });
|
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() {
|
|
|
|
for (let i = 0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
meta.resultDisplay.clear();
|
|
|
|
meta.actor.hide();
|
2012-08-08 16:10:00 +00:00
|
|
|
if (meta.icon) meta.icon.actor.can_focus = false;
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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();
|
2012-08-08 16:10:00 +00:00
|
|
|
if (meta.icon) meta.icon.actor.can_focus = false;
|
2011-07-24 10:29:36 +00:00
|
|
|
},
|
|
|
|
|
2010-11-18 09:23:44 +00:00
|
|
|
reset: function() {
|
|
|
|
this._searchSystem.reset();
|
2012-08-31 17:27:35 +00:00
|
|
|
this._statusBin.hide();
|
2010-11-18 09:23:44 +00:00
|
|
|
this._clearDisplay();
|
|
|
|
},
|
|
|
|
|
|
|
|
startingSearch: function() {
|
|
|
|
this.reset();
|
|
|
|
this._statusText.set_text(_("Searching..."));
|
2012-08-31 17:27:35 +00:00
|
|
|
this._statusBin.show();
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
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-08-08 16:10:00 +00:00
|
|
|
_metaForProvidersExcept: function(provider) {
|
|
|
|
let skip = this._providers.indexOf(provider);
|
|
|
|
return this._providerMeta.filter(function(meta, index) { return index != skip }, this);
|
|
|
|
},
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
_maybeSetInitialSelection: function() {
|
2011-11-14 03:13:26 +00:00
|
|
|
let newDefaultResult = null;
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
for (let i = 0; i < this._providerMeta.length; i++) {
|
|
|
|
let meta = this._providerMeta[i];
|
|
|
|
|
2012-03-10 15:20:47 +00:00
|
|
|
if (!meta.actor.visible)
|
|
|
|
continue;
|
|
|
|
|
2011-11-14 03:13:26 +00:00
|
|
|
let firstResult = meta.resultDisplay.getFirstResult();
|
2012-03-10 15:20:47 +00:00
|
|
|
if (firstResult) {
|
2011-11-14 03:13:26 +00:00
|
|
|
newDefaultResult = firstResult;
|
2012-02-21 18:53:25 +00:00
|
|
|
break; // select this one!
|
2011-11-14 03:13:26 +00:00
|
|
|
}
|
2012-02-21 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 03:13:26 +00:00
|
|
|
if (newDefaultResult != this._defaultResult) {
|
|
|
|
if (this._defaultResult)
|
|
|
|
this._defaultResult.setSelected(false);
|
|
|
|
if (newDefaultResult)
|
|
|
|
newDefaultResult.setSelected(this._highlightDefault);
|
|
|
|
|
|
|
|
this._defaultResult = newDefaultResult;
|
|
|
|
}
|
2012-02-21 18:53:25 +00:00
|
|
|
},
|
|
|
|
|
2012-05-07 15:44:28 +00: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 17:27:35 +00:00
|
|
|
this._statusText.set_text(_("No results."));
|
|
|
|
this._statusBin.show();
|
2012-05-07 15:44:28 +00:00
|
|
|
} else {
|
2012-08-31 17:27:35 +00:00
|
|
|
this._statusBin.hide();
|
2012-05-07 15:44:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateResults: 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
|
|
|
|
|
|
|
if (providerResults.length == 0) {
|
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.resultDisplay.setResults([], []);
|
2012-05-07 15:44:28 +00:00
|
|
|
this._maybeSetInitialSelection();
|
|
|
|
this._updateStatusText();
|
2012-02-21 18:53:25 +00:00
|
|
|
} else {
|
|
|
|
meta.resultDisplay.setResults(providerResults, terms);
|
|
|
|
let results = meta.resultDisplay.getResultsForDisplay();
|
|
|
|
|
2012-08-09 21:52:36 +00:00
|
|
|
if (meta.icon)
|
|
|
|
meta.icon.moreIcon.visible = meta.resultDisplay.hasMoreResults();
|
|
|
|
|
2012-05-02 19:54:25 +00:00
|
|
|
provider.getResultMetas(results, Lang.bind(this, function(metas) {
|
2012-02-21 18:53:25 +00:00
|
|
|
this._clearDisplayForProvider(provider);
|
|
|
|
meta.actor.show();
|
2012-05-02 19:54:25 +00:00
|
|
|
|
2012-05-07 15:44:28 +00:00
|
|
|
// Hiding drops the key focus if we have it
|
2012-05-02 19:54:25 +00:00
|
|
|
let focus = global.stage.get_key_focus();
|
2012-05-07 15:44:28 +00: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 19:54:25 +00:00
|
|
|
this._content.hide();
|
|
|
|
|
2012-02-21 18:53:25 +00:00
|
|
|
meta.resultDisplay.renderResults(metas);
|
2012-05-02 19:54:25 +00:00
|
|
|
this._maybeSetInitialSelection();
|
2012-05-07 15:44:28 +00:00
|
|
|
this._updateStatusText();
|
2012-05-02 19:54:25 +00:00
|
|
|
|
|
|
|
this._content.show();
|
|
|
|
if (this._content.contains(focus))
|
|
|
|
global.stage.set_key_focus(focus);
|
|
|
|
}));
|
2012-02-21 18:53:25 +00:00
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
},
|
|
|
|
|
2011-11-14 03:13:26 +00:00
|
|
|
activateDefault: function() {
|
2012-03-10 15:20:47 +00:00
|
|
|
if (this._defaultResult)
|
2011-11-14 03:13:26 +00:00
|
|
|
this._defaultResult.activate();
|
|
|
|
},
|
|
|
|
|
|
|
|
highlightDefault: function(highlight) {
|
|
|
|
this._highlightDefault = highlight;
|
|
|
|
if (this._defaultResult)
|
|
|
|
this._defaultResult.setSelected(highlight);
|
|
|
|
},
|
|
|
|
|
2012-08-08 16:10:00 +00:00
|
|
|
_updateProviderIconCanFocus: function(resultDisplay) {
|
|
|
|
let meta = this._metaForProvider(resultDisplay.provider);
|
|
|
|
if (meta.icon)
|
|
|
|
meta.icon.actor.can_focus = true;
|
|
|
|
|
|
|
|
let others = this._metaForProvidersExcept(resultDisplay.provider);
|
|
|
|
others.forEach(function(meta) { if (meta.icon) meta.icon.actor.can_focus = false; });
|
|
|
|
},
|
|
|
|
|
2011-11-14 03:13:26 +00:00
|
|
|
navigateFocus: function(direction) {
|
2012-03-10 02:40:46 +00: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);
|
|
|
|
if (this._defaultResult) {
|
2011-11-14 03:13:26 +00:00
|
|
|
// The default result appears focused, so navigate directly to the
|
|
|
|
// next result.
|
|
|
|
this.actor.navigate_focus(global.stage.key_focus, direction, false);
|
|
|
|
}
|
2010-11-18 09:23:44 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2012-08-09 21:52:36 +00:00
|
|
|
|
|
|
|
const ProviderIcon = new Lang.Class({
|
|
|
|
Name: 'ProviderIcon',
|
|
|
|
|
|
|
|
PROVIDER_ICON_SIZE: 48,
|
|
|
|
|
|
|
|
MORE_ICON_SIZE: 16,
|
|
|
|
|
|
|
|
_init: function(provider) {
|
|
|
|
this.provider = provider;
|
|
|
|
|
|
|
|
this.actor = new St.Button({ style_class: 'search-section-icon-bin',
|
|
|
|
reactive: true,
|
|
|
|
track_hover: true });
|
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onIconClicked));
|
|
|
|
|
|
|
|
this._content = new St.Widget({ layout_manager: new Clutter.BinLayout() });
|
|
|
|
this.actor.set_child(this._content);
|
|
|
|
|
|
|
|
let rtl = (this.actor.get_text_direction() == Clutter.TextDirection.RTL);
|
|
|
|
|
|
|
|
this.moreIcon = new St.Icon({ style_class: 'search-section-icon-more',
|
|
|
|
icon_size: this.MORE_ICON_SIZE,
|
|
|
|
icon_name: 'list-add-symbolic',
|
|
|
|
visible: false,
|
|
|
|
x_align: rtl ? Clutter.ActorAlign.START : Clutter.ActorAlign.END,
|
|
|
|
y_align: Clutter.ActorAlign.END,
|
|
|
|
// HACK: without these, ClutterBinLayout
|
|
|
|
// ignores alignment properties on the actor
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true });
|
|
|
|
|
|
|
|
this._iconBin = new St.Bin({ style_class: 'search-section-icon',
|
|
|
|
width: this.PROVIDER_ICON_SIZE,
|
|
|
|
height: this.PROVIDER_ICON_SIZE });
|
|
|
|
|
|
|
|
this._content.add_actor(this._iconBin);
|
|
|
|
this._content.add_actor(this.moreIcon);
|
|
|
|
|
|
|
|
this._createProviderIcon();
|
|
|
|
},
|
|
|
|
|
|
|
|
_createProviderIcon: function() {
|
|
|
|
let icon = new St.Icon({ icon_size: this.PROVIDER_ICON_SIZE });
|
|
|
|
|
|
|
|
if (this.provider.icon)
|
|
|
|
icon.gicon = this.provider.icon;
|
|
|
|
else
|
|
|
|
icon.icon_name = 'application-x-executable';
|
|
|
|
|
|
|
|
this._iconBin.set_child(icon);
|
|
|
|
},
|
|
|
|
|
|
|
|
activate: function() {
|
|
|
|
this.emit('launch-search');
|
|
|
|
},
|
|
|
|
|
|
|
|
_onIconClicked: function(actor) {
|
|
|
|
this.activate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(ProviderIcon.prototype);
|