~ubuntu-branches/ubuntu/trusty/gnome-shell/trusty-proposed

« back to all changes in this revision

Viewing changes to js/ui/searchDisplay.js

Tags: upstream-3.3.90
ImportĀ upstreamĀ versionĀ 3.3.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
const MAX_SEARCH_RESULTS_ROWS = 1;
16
16
 
17
17
 
18
 
function SearchResult(provider, metaInfo, terms) {
19
 
    this._init(provider, metaInfo, terms);
20
 
}
 
18
const SearchResult = new Lang.Class({
 
19
    Name: 'SearchResult',
21
20
 
22
 
SearchResult.prototype = {
23
21
    _init: function(provider, metaInfo, terms) {
24
22
        this.provider = provider;
25
23
        this.metaInfo = metaInfo;
97
95
        else
98
96
            this.provider.activateResult(this.metaInfo.id, params);
99
97
    }
100
 
};
101
 
 
102
 
 
103
 
function GridSearchResults(provider, grid) {
104
 
    this._init(provider, grid);
105
 
}
106
 
 
107
 
GridSearchResults.prototype = {
108
 
    __proto__: Search.SearchResultDisplay.prototype,
 
98
});
 
99
 
 
100
 
 
101
const GridSearchResults = new Lang.Class({
 
102
    Name: 'GridSearchResults',
 
103
    Extends: Search.SearchResultDisplay,
109
104
 
110
105
    _init: function(provider, grid) {
111
 
        Search.SearchResultDisplay.prototype._init.call(this, provider);
 
106
        this.parent(provider);
 
107
 
112
108
        this._grid = grid || new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS,
113
109
                                                     xAlign: St.Align.START });
114
110
        this.actor = new St.Bin({ x_align: St.Align.START });
119
115
        this.actor.connect('notify::width', Lang.bind(this, function() {
120
116
            this._width = this.actor.width;
121
117
            Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
122
 
                this._tryAddResults();
 
118
                let results = this.getResultsForDisplay();
 
119
                if (results.length == 0)
 
120
                    return;
 
121
 
 
122
                if (provider.async) {
 
123
                    provider.getResultMetasAsync(results,
 
124
                                                 Lang.bind(this, this.renderResults));
 
125
                } else {
 
126
                    let metas = provider.getResultMetas(results);
 
127
                    this.renderResults(metas);
 
128
                }
123
129
            }));
124
130
        }));
125
131
        this._notDisplayedResult = [];
126
132
        this._terms = [];
 
133
        this._pendingClear = false;
127
134
    },
128
135
 
129
 
    _tryAddResults: function() {
 
136
    getResultsForDisplay: function() {
 
137
        let alreadyVisible = this._pendingClear ? 0 : this._grid.visibleItemsCount();
130
138
        let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
131
 
                         - this._grid.visibleItemsCount();
132
 
 
133
 
        for (let i = Math.min(this._notDisplayedResult.length, canDisplay); i > 0; i--) {
134
 
            let result = this._notDisplayedResult.shift();
135
 
            let meta = this.provider.getResultMeta(result);
136
 
            let display = new SearchResult(this.provider, meta, this._terms);
137
 
            this._grid.addItem(display.actor);
138
 
        }
 
139
                         - alreadyVisible;
 
140
 
 
141
        let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
 
142
 
 
143
        return this._notDisplayedResult.splice(0, numResults);
139
144
    },
140
145
 
141
146
    getVisibleResultCount: function() {
142
147
        return this._grid.visibleItemsCount();
143
148
    },
144
149
 
145
 
    renderResults: function(results, terms) {
 
150
    setResults: function(results, terms) {
146
151
        // copy the lists
147
152
        this._notDisplayedResult = results.slice(0);
148
153
        this._terms = terms.slice(0);
149
 
        this._tryAddResults();
 
154
        this._pendingClear = true;
 
155
    },
 
156
 
 
157
    renderResults: function(metas) {
 
158
        for (let i = 0; i < metas.length; i++) {
 
159
            let display = new SearchResult(this.provider, metas[i], this._terms);
 
160
            this._grid.addItem(display.actor);
 
161
        }
150
162
    },
151
163
 
152
164
    clear: function () {
153
 
        this._terms = [];
154
 
        this._notDisplayedResult = [];
155
165
        this._grid.removeAll();
156
166
        this.selectionIndex = -1;
 
167
        this._pendingClear = false;
157
168
    },
158
169
 
159
170
    selectIndex: function (index) {
179
190
        let targetActor = this._grid.getItemAtIndex(this.selectionIndex);
180
191
        targetActor._delegate.activate();
181
192
    }
182
 
};
183
 
 
184
 
 
185
 
function SearchResults(searchSystem, openSearchSystem) {
186
 
    this._init(searchSystem, openSearchSystem);
187
 
}
188
 
 
189
 
SearchResults.prototype = {
 
193
});
 
194
 
 
195
const SearchResults = new Lang.Class({
 
196
    Name: 'SearchResults',
 
197
 
190
198
    _init: function(searchSystem, openSearchSystem) {
191
199
        this._searchSystem = searchSystem;
192
200
        this._searchSystem.connect('search-updated', Lang.bind(this, this._updateCurrentResults));
296
304
 
297
305
        this._providerMeta.push({ provider: provider,
298
306
                                  actor: providerBox,
299
 
                                  resultDisplay: resultDisplay });
 
307
                                  resultDisplay: resultDisplay,
 
308
                                  hasPendingResults: false });
300
309
        this._content.add(providerBox);
301
310
    },
302
311
 
321
330
        }
322
331
    },
323
332
 
324
 
    _clearDisplayForProvider: function(index) {
325
 
        let meta = this._providerMeta[index];
 
333
    _clearDisplayForProvider: function(provider) {
 
334
        let meta = this._metaForProvider(provider);
326
335
        meta.resultDisplay.clear();
327
336
        meta.actor.hide();
328
337
    },
349
358
        return this._providerMeta[this._providers.indexOf(provider)];
350
359
    },
351
360
 
352
 
    _updateCurrentResults: function(searchSystem, provider, results) {
 
361
    _maybeSetInitialSelection: function() {
 
362
        if (this._selectedOpenSearchButton > -1 || this._selectedProvider > -1)
 
363
            return;
 
364
 
 
365
        for (let i = 0; i < this._providerMeta.length; i++) {
 
366
            let meta = this._providerMeta[i];
 
367
            if (meta.hasPendingResults)
 
368
                return;
 
369
 
 
370
            if (meta.actor.visible)
 
371
                break; // select this one!
 
372
        }
 
373
 
 
374
        this.selectDown(false);
 
375
        this._initialSelectionSet = true;
 
376
    },
 
377
 
 
378
    _updateCurrentResults: function(searchSystem, results) {
353
379
        let terms = searchSystem.getTerms();
354
 
        let meta = this._metaForProvider(provider);
355
 
        meta.resultDisplay.clear();
356
 
        meta.actor.show();
357
 
        meta.resultDisplay.renderResults(results, terms);
358
 
        return true;
 
380
        let [provider, providerResults] = results;
 
381
        let meta = this._metaForProvider(provider);
 
382
        meta.hasPendingResults = false;
 
383
        this._updateProviderResults(provider, providerResults, terms);
 
384
    },
 
385
 
 
386
    _updateProviderResults: function(provider, providerResults, terms) {
 
387
        let meta = this._metaForProvider(provider);
 
388
        if (providerResults.length == 0) {
 
389
            this._clearDisplayForProvider(provider);
 
390
            meta.resultDisplay.setResults([], []);
 
391
        } else {
 
392
            this._providerMetaResults[provider.title] = providerResults;
 
393
            meta.resultDisplay.setResults(providerResults, terms);
 
394
            let results = meta.resultDisplay.getResultsForDisplay();
 
395
 
 
396
            if (provider.async) {
 
397
                provider.getResultMetasAsync(results, Lang.bind(this,
 
398
                    function(metas) {
 
399
                        this._clearDisplayForProvider(provider);
 
400
                        meta.actor.show();
 
401
                        this._content.hide();
 
402
                        meta.resultDisplay.renderResults(metas);
 
403
                        this._maybeSetInitialSelection();
 
404
                        this._content.show();
 
405
                    }));
 
406
            } else {
 
407
                let metas = provider.getResultMetas(results);
 
408
                this._clearDisplayForProvider(provider);
 
409
                meta.actor.show();
 
410
                meta.resultDisplay.renderResults(metas);
 
411
            }
 
412
        }
359
413
    },
360
414
 
361
415
    _updateResults: function(searchSystem, results) {
365
419
        } else {
366
420
            this._selectedOpenSearchButton = -1;
367
421
            this._updateOpenSearchButtonState();
 
422
            this._selectedProvider = -1;
368
423
            this._statusText.hide();
369
424
        }
370
425
 
380
435
 
381
436
        for (let i = 0; i < results.length; i++) {
382
437
            let [provider, providerResults] = results[i];
383
 
            if (providerResults.length == 0) {
384
 
                this._clearDisplayForProvider(i);
385
 
            } else {
386
 
                this._providerMetaResults[provider.title] = providerResults;
387
 
                this._clearDisplayForProvider(i);
388
 
                let meta = this._metaForProvider(provider);
389
 
                meta.actor.show();
390
 
                meta.resultDisplay.renderResults(providerResults, terms);
391
 
            }
 
438
            let meta = this._metaForProvider(provider);
 
439
            meta.hasPendingResults = provider.async;
 
440
            if (!meta.hasPendingResults)
 
441
                this._updateProviderResults(provider, providerResults, terms);
392
442
        }
393
443
 
394
 
        if (this._selectedOpenSearchButton == -1)
395
 
            this.selectDown(false);
396
 
 
 
444
        this._maybeSetInitialSelection();
397
445
        this._content.show();
398
446
 
399
447
        return true;
486
534
        resultDisplay.activateSelected();
487
535
        Main.overview.hide();
488
536
    }
489
 
};
 
537
});