lookingGlass: Use resultsArea to keep track of results

Now that results are actors we can just use their container to keep
track of them

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:
Marco Trevisan (Treviño) 2019-05-20 23:25:14 +02:00 committed by Florian Müllner
parent 91a5133116
commit 4dea1f801a

View File

@ -793,7 +793,6 @@ class LookingGlass extends St.BoxLayout {
this._it = null; this._it = null;
this._offset = 0; this._offset = 0;
this._results = [];
// Sort of magic, but...eh. // Sort of magic, but...eh.
this._maxItems = 150; this._maxItems = 150;
@ -937,17 +936,14 @@ class LookingGlass extends St.BoxLayout {
} }
_pushResult(command, obj) { _pushResult(command, obj) {
let index = this._results.length + this._offset; let index = this._resultsArea.get_n_children() + this._offset;
let result = new Result(this, CHEVRON + command, obj, index); let result = new Result(this, CHEVRON + command, obj, index);
this._results.push(result);
this._resultsArea.add(result); this._resultsArea.add(result);
if (obj instanceof Clutter.Actor) if (obj instanceof Clutter.Actor)
this.setBorderPaintTarget(obj); this.setBorderPaintTarget(obj);
let children = this._resultsArea.get_children(); if (this._resultsArea.get_n_children() > this._maxItems) {
if (children.length > this._maxItems) { this._resultsArea.get_first_child().destroy();
this._results.shift();
children[0].destroy();
this._offset++; this._offset++;
} }
this._it = obj; this._it = obj;
@ -1034,7 +1030,7 @@ class LookingGlass extends St.BoxLayout {
getResult(idx) { getResult(idx) {
try { try {
return this._results[idx - this._offset].o; return this._resultsArea.get_child_at_index(idx - this._offset).o;
} catch (e) { } catch (e) {
throw new Error(`Unknown result at index ${idx}`); throw new Error(`Unknown result at index ${idx}`);
} }