search.js: Propagate searchResultsView down the hierarchy

This commit is contained in:
raresvis 2017-06-28 00:58:07 +03:00
parent 04ad2b24d8
commit 7bbff9d0c0
2 changed files with 22 additions and 17 deletions

View File

@ -1131,7 +1131,7 @@ const AppSearchProvider = new Lang.Class({
this.getInitialResultSet(terms, callback, cancellable); this.getInitialResultSet(terms, callback, cancellable);
}, },
createResultObject: function (resultMeta) { createResultObject: function (resultMeta, searchResultsView) {
let app = this._appSys.lookup_app(resultMeta['id']); let app = this._appSys.lookup_app(resultMeta['id']);
return new AppIcon(app); return new AppIcon(app);
} }

View File

@ -48,9 +48,10 @@ const MaxWidthBin = new Lang.Class({
const SearchResult = new Lang.Class({ const SearchResult = new Lang.Class({
Name: 'SearchResult', Name: 'SearchResult',
_init: function(provider, metaInfo) { _init: function(provider, metaInfo, searchResultsView) {
this.provider = provider; this.provider = provider;
this.metaInfo = metaInfo; this.metaInfo = metaInfo;
this._searchResultsView = searchResultsView;
this.actor = new St.Button({ reactive: true, this.actor = new St.Button({ reactive: true,
can_focus: true, can_focus: true,
@ -74,8 +75,8 @@ const ListSearchResult = new Lang.Class({
ICON_SIZE: 24, ICON_SIZE: 24,
_init: function(provider, metaInfo) { _init: function(provider, metaInfo, searchResultsView) {
this.parent(provider, metaInfo); this.parent(provider, metaInfo, searchResultsView);
this.actor.style_class = 'list-search-result'; this.actor.style_class = 'list-search-result';
this.actor.x_fill = true; this.actor.x_fill = true;
@ -121,8 +122,8 @@ const GridSearchResult = new Lang.Class({
Name: 'GridSearchResult', Name: 'GridSearchResult',
Extends: SearchResult, Extends: SearchResult,
_init: function(provider, metaInfo) { _init: function(provider, metaInfo, searchResultsView) {
this.parent(provider, metaInfo); this.parent(provider, metaInfo, searchResultsView);
this.actor.style_class = 'grid-search-result'; this.actor.style_class = 'grid-search-result';
@ -137,8 +138,9 @@ const GridSearchResult = new Lang.Class({
const SearchResultsBase = new Lang.Class({ const SearchResultsBase = new Lang.Class({
Name: 'SearchResultsBase', Name: 'SearchResultsBase',
_init: function(provider) { _init: function(provider, searchResultsView) {
this.provider = provider; this.provider = provider;
this._searchResultsView = searchResultsView;
this._terms = []; this._terms = [];
@ -166,7 +168,8 @@ const SearchResultsBase = new Lang.Class({
_createResultDisplay: function(meta) { _createResultDisplay: function(meta) {
if (this.provider.createResultObject) if (this.provider.createResultObject)
return this.provider.createResultObject(meta); return this.provider.createResultObject(meta,
this._searchResultsView);
return null; return null;
}, },
@ -271,8 +274,8 @@ const ListSearchResults = new Lang.Class({
Name: 'ListSearchResults', Name: 'ListSearchResults',
Extends: SearchResultsBase, Extends: SearchResultsBase,
_init: function(provider) { _init: function(provider, searchResultsView) {
this.parent(provider); this.parent(provider, searchResultsView);
this._container = new St.BoxLayout({ style_class: 'search-section-content' }); this._container = new St.BoxLayout({ style_class: 'search-section-content' });
this.providerInfo = new ProviderInfo(provider); this.providerInfo = new ProviderInfo(provider);
@ -309,7 +312,8 @@ const ListSearchResults = new Lang.Class({
}, },
_createResultDisplay: function(meta) { _createResultDisplay: function(meta) {
return this.parent(meta) || new ListSearchResult(this.provider, meta); return this.parent(meta, this._searchResultsView) ||
new ListSearchResult(this.provider, meta, this._searchResultsView);
}, },
_addItem: function(display) { _addItem: function(display) {
@ -329,14 +333,14 @@ const GridSearchResults = new Lang.Class({
Name: 'GridSearchResults', Name: 'GridSearchResults',
Extends: SearchResultsBase, Extends: SearchResultsBase,
_init: function(provider, parentContainer) { _init: function(provider, searchResultsView) {
this.parent(provider); this.parent(provider, searchResultsView);
// We need to use the parent container to know how much results we can show. // We need to use the parent container to know how much results we can show.
// None of the actors in this class can be used for that, since the main actor // None of the actors in this class can be used for that, since the main actor
// goes hidden when no results are displayed, and then it lost its allocation. // goes hidden when no results are displayed, and then it lost its allocation.
// Then on the next use of _getMaxDisplayedResults allocation is 0, en therefore // Then on the next use of _getMaxDisplayedResults allocation is 0, en therefore
// it doesn't show any result although we have some. // it doesn't show any result although we have some.
this._parentContainer = parentContainer; this._parentContainer = searchResultsView.actor;
this._grid = new IconGrid.IconGrid({ rowLimit: MAX_GRID_SEARCH_RESULTS_ROWS, this._grid = new IconGrid.IconGrid({ rowLimit: MAX_GRID_SEARCH_RESULTS_ROWS,
xAlign: St.Align.START }); xAlign: St.Align.START });
@ -357,7 +361,8 @@ const GridSearchResults = new Lang.Class({
}, },
_createResultDisplay: function(meta) { _createResultDisplay: function(meta) {
return this.parent(meta) || new GridSearchResult(this.provider, meta); return this.parent(meta, this._searchResultsView) ||
new GridSearchResult(this.provider, meta, this._searchResultsView);
}, },
_addItem: function(display) { _addItem: function(display) {
@ -559,9 +564,9 @@ const SearchResults = new Lang.Class({
let providerDisplay; let providerDisplay;
if (provider.appInfo) if (provider.appInfo)
providerDisplay = new ListSearchResults(provider); providerDisplay = new ListSearchResults(provider, this);
else else
providerDisplay = new GridSearchResults(provider, this.actor); providerDisplay = new GridSearchResults(provider, this);
providerDisplay.connect('key-focus-in', Lang.bind(this, this._keyFocusIn)); providerDisplay.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
providerDisplay.actor.hide(); providerDisplay.actor.hide();