searchDisplay: Add a base class for common parts of search results
Right now, this doesn't give us very much, since IconGrid and StBoxLayout have different APIs. But since we want to introduce result caching, it makes to reduce the duplication we already have so we don't need to add the code to do so in both places. https://bugzilla.gnome.org/show_bug.cgi?id=693836
This commit is contained in:
parent
62e1c08dd6
commit
e602199bfb
@ -180,12 +180,38 @@ const GridSearchResult = new Lang.Class({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const ListSearchResults = new Lang.Class({
|
const SearchResultsBase = new Lang.Class({
|
||||||
Name: 'ListSearchResults',
|
Name: 'SearchResultsBase',
|
||||||
|
|
||||||
_init: function(provider) {
|
_init: function(provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
|
|
||||||
|
this._notDisplayedResult = [];
|
||||||
|
this._terms = [];
|
||||||
|
},
|
||||||
|
|
||||||
|
hasMoreResults: function() {
|
||||||
|
return this._notDisplayedResult.length > 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
_keyFocusIn: function(icon) {
|
||||||
|
this.emit('key-focus-in', icon);
|
||||||
|
},
|
||||||
|
|
||||||
|
setResults: function(results, terms) {
|
||||||
|
// copy the lists
|
||||||
|
this._notDisplayedResult = results.slice(0);
|
||||||
|
this._terms = terms.slice(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const ListSearchResults = new Lang.Class({
|
||||||
|
Name: 'ListSearchResults',
|
||||||
|
Extends: SearchResultsBase,
|
||||||
|
|
||||||
|
_init: function(provider) {
|
||||||
|
this.parent(provider);
|
||||||
|
|
||||||
this.actor = new St.BoxLayout({ style_class: 'search-section-content' });
|
this.actor = new St.BoxLayout({ style_class: 'search-section-content' });
|
||||||
this.providerIcon = new ProviderIcon(provider);
|
this.providerIcon = new ProviderIcon(provider);
|
||||||
this.providerIcon.connect('clicked', Lang.bind(this,
|
this.providerIcon.connect('clicked', Lang.bind(this,
|
||||||
@ -202,9 +228,6 @@ const ListSearchResults = new Lang.Class({
|
|||||||
this._content = new St.BoxLayout({ style_class: 'list-search-results',
|
this._content = new St.BoxLayout({ style_class: 'list-search-results',
|
||||||
vertical: true });
|
vertical: true });
|
||||||
this.actor.add(this._content, { expand: true });
|
this.actor.add(this._content, { expand: true });
|
||||||
|
|
||||||
this._notDisplayedResult = [];
|
|
||||||
this._terms = [];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultsForDisplay: function() {
|
getResultsForDisplay: function() {
|
||||||
@ -217,20 +240,6 @@ const ListSearchResults = new Lang.Class({
|
|||||||
return this._content.get_n_children();
|
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);
|
|
||||||
},
|
|
||||||
|
|
||||||
_keyFocusIn: function(icon) {
|
|
||||||
this.emit('key-focus-in', icon);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderResults: function(metas) {
|
renderResults: function(metas) {
|
||||||
for (let i = 0; i < metas.length; i++) {
|
for (let i = 0; i < metas.length; i++) {
|
||||||
let display = new ListSearchResult(this.provider, metas[i], this._terms);
|
let display = new ListSearchResult(this.provider, metas[i], this._terms);
|
||||||
@ -254,18 +263,16 @@ Signals.addSignalMethods(ListSearchResults.prototype);
|
|||||||
|
|
||||||
const GridSearchResults = new Lang.Class({
|
const GridSearchResults = new Lang.Class({
|
||||||
Name: 'GridSearchResults',
|
Name: 'GridSearchResults',
|
||||||
|
Extends: SearchResultsBase,
|
||||||
|
|
||||||
_init: function(provider) {
|
_init: function(provider) {
|
||||||
this.provider = provider;
|
this.parent(provider);
|
||||||
|
|
||||||
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 });
|
||||||
this.actor = new St.Bin({ x_align: St.Align.MIDDLE });
|
this.actor = new St.Bin({ x_align: St.Align.MIDDLE });
|
||||||
|
|
||||||
this.actor.set_child(this._grid.actor);
|
this.actor.set_child(this._grid.actor);
|
||||||
|
|
||||||
this._notDisplayedResult = [];
|
|
||||||
this._terms = [];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getResultsForDisplay: function() {
|
getResultsForDisplay: function() {
|
||||||
@ -278,20 +285,6 @@ const GridSearchResults = new Lang.Class({
|
|||||||
return this._grid.visibleItemsCount();
|
return this._grid.visibleItemsCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
hasMoreResults: function() {
|
|
||||||
return this._notDisplayedResult.length > 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
setResults: function(results, terms) {
|
|
||||||
// copy the lists
|
|
||||||
this._notDisplayedResult = results.slice(0);
|
|
||||||
this._terms = terms.slice(0);
|
|
||||||
},
|
|
||||||
|
|
||||||
_keyFocusIn: function(icon) {
|
|
||||||
this.emit('key-focus-in', icon);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderResults: function(metas) {
|
renderResults: function(metas) {
|
||||||
for (let i = 0; i < metas.length; i++) {
|
for (let i = 0; i < metas.length; i++) {
|
||||||
let display = new GridSearchResult(this.provider, metas[i], this._terms);
|
let display = new GridSearchResult(this.provider, metas[i], this._terms);
|
||||||
|
Loading…
Reference in New Issue
Block a user