searchDisplay: Split renderResults()
renderResults() updates the results set, determines the number of results to display, retrieves the corresponding result metas and adds a new results actor for each meta. Splitting the function in those parts allows to move the retrieval of the result metas into SearchResults, which is where we ensure flicker-free rendering and control the selection - we want to keep both features for asynchronous result metas which we are about to introduce. https://bugzilla.gnome.org/show_bug.cgi?id=663125
This commit is contained in:
parent
53d9ea7a2c
commit
eb0d803617
@ -115,37 +115,42 @@ const GridSearchResults = new Lang.Class({
|
|||||||
this.actor.connect('notify::width', Lang.bind(this, function() {
|
this.actor.connect('notify::width', Lang.bind(this, function() {
|
||||||
this._width = this.actor.width;
|
this._width = this.actor.width;
|
||||||
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
|
||||||
this._tryAddResults();
|
let results = this.getResultsForDisplay();
|
||||||
|
if (results.length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let metas = provider.getResultMetas(results);
|
||||||
|
this.renderResults(metas);
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
this._notDisplayedResult = [];
|
this._notDisplayedResult = [];
|
||||||
this._terms = [];
|
this._terms = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
_tryAddResults: function() {
|
getResultsForDisplay: function() {
|
||||||
let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
|
let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
|
||||||
- this._grid.visibleItemsCount();
|
- this._grid.visibleItemsCount();
|
||||||
|
|
||||||
let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
|
let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
|
||||||
if (numResults == 0)
|
|
||||||
return;
|
return this._notDisplayedResult.splice(0, numResults);
|
||||||
let results = this._notDisplayedResult.splice(0, numResults);
|
|
||||||
let metas = this.provider.getResultMetas(results);
|
|
||||||
for (let i = 0; i < metas.length; i++) {
|
|
||||||
let display = new SearchResult(this.provider, metas[i], this._terms);
|
|
||||||
this._grid.addItem(display.actor);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getVisibleResultCount: function() {
|
getVisibleResultCount: function() {
|
||||||
return this._grid.visibleItemsCount();
|
return this._grid.visibleItemsCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
renderResults: function(results, terms) {
|
setResults: function(results, terms) {
|
||||||
// copy the lists
|
// copy the lists
|
||||||
this._notDisplayedResult = results.slice(0);
|
this._notDisplayedResult = results.slice(0);
|
||||||
this._terms = terms.slice(0);
|
this._terms = terms.slice(0);
|
||||||
this._tryAddResults();
|
},
|
||||||
|
|
||||||
|
renderResults: function(metas) {
|
||||||
|
for (let i = 0; i < metas.length; i++) {
|
||||||
|
let display = new SearchResult(this.provider, metas[i], this._terms);
|
||||||
|
this._grid.addItem(display.actor);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function () {
|
clear: function () {
|
||||||
@ -350,7 +355,9 @@ const SearchResults = new Lang.Class({
|
|||||||
let meta = this._metaForProvider(provider);
|
let meta = this._metaForProvider(provider);
|
||||||
meta.resultDisplay.clear();
|
meta.resultDisplay.clear();
|
||||||
meta.actor.show();
|
meta.actor.show();
|
||||||
meta.resultDisplay.renderResults(results, terms);
|
meta.resultDisplay.setResults(providerResults, terms);
|
||||||
|
let displayResults = meta.resultDisplay.getResultsForDisplay();
|
||||||
|
meta.resultDisplay.renderResults(provider.getResultMetas(displayResults));
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -383,7 +390,9 @@ const SearchResults = new Lang.Class({
|
|||||||
this._clearDisplayForProvider(i);
|
this._clearDisplayForProvider(i);
|
||||||
let meta = this._metaForProvider(provider);
|
let meta = this._metaForProvider(provider);
|
||||||
meta.actor.show();
|
meta.actor.show();
|
||||||
meta.resultDisplay.renderResults(providerResults, terms);
|
meta.resultDisplay.setResults(providerResults, terms);
|
||||||
|
let displayResults = meta.resultDisplay.getResultsForDisplay();
|
||||||
|
meta.resultDisplay.renderResults(provider.getResultMetas(displayResults));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user