Don't reset the page selection if the results have changed while the user

was browsing exiting results

This is most noticeable when viewing results in xephyr, and then opening
a document in your regular session. But it could also be noticeable if
downloading a new file completes while the user is in the overlay.

This patch also moves the call to _displayMatchedItems() to _redisplay
instead of making it in both _setDefaultList() and _doSearchFilter().
This commit is contained in:
Marina Zhurakhinskaya 2009-03-11 17:56:22 -04:00
parent 39eb563687
commit 30a9c6b2f4
3 changed files with 34 additions and 28 deletions

View File

@ -131,7 +131,7 @@ AppDisplay.prototype = {
// We still need to determine what events other than search can trigger // We still need to determine what events other than search can trigger
// a change in the set of applications that are being shown while the // a change in the set of applications that are being shown while the
// user in in the overlay mode, however let's redisplay just in case. // user in in the overlay mode, however let's redisplay just in case.
me._redisplay(); me._redisplay(false);
}); });
// Load the GAppInfos now so it doesn't slow down the first // Load the GAppInfos now so it doesn't slow down the first
@ -174,7 +174,6 @@ AppDisplay.prototype = {
this._matchedItems.push(appId); this._matchedItems.push(appId);
} }
} }
this._displayMatchedItems(true);
}, },
// Compares items associated with the item ids based on the alphabetical order // Compares items associated with the item ids based on the alphabetical order

View File

@ -110,7 +110,7 @@ DocDisplay.prototype = {
// but redisplaying right away is cool when we use Zephyr. // but redisplaying right away is cool when we use Zephyr.
// Also, we might be displaying remote documents, like Google Docs, in the future // Also, we might be displaying remote documents, like Google Docs, in the future
// which might be edited by someone else. // which might be edited by someone else.
me._redisplay(); me._redisplay(false);
}); });
}, },
@ -163,8 +163,6 @@ DocDisplay.prototype = {
} }
this._matchedItems.sort(Lang.bind(this, function (a,b) { return this._compareItems(a,b); })); this._matchedItems.sort(Lang.bind(this, function (a,b) { return this._compareItems(a,b); }));
this._displayMatchedItems(true);
}, },
// Compares items associated with the item ids based on how recently the items // Compares items associated with the item ids based on how recently the items

View File

@ -225,7 +225,7 @@ GenericDisplay.prototype = {
// Sets the search string and displays the matching items. // Sets the search string and displays the matching items.
setSearch: function(text) { setSearch: function(text) {
this._search = text.toLowerCase(); this._search = text.toLowerCase();
this._redisplay(); this._redisplay(true);
}, },
// Sets this._activatedItem to the item that is selected and emits 'activated' signal. // Sets this._activatedItem to the item that is selected and emits 'activated' signal.
@ -314,13 +314,14 @@ GenericDisplay.prototype = {
this._setDimensionsAndMaxItems(width, height); this._setDimensionsAndMaxItems(width, height);
this._grid.width = this._width; this._grid.width = this._width;
this._grid.height = this._height; this._grid.height = this._height;
this._pageDisplayed = 0;
this._displayMatchedItems(true); this._displayMatchedItems(true);
}, },
// Updates the displayed items and makes the display actor visible. // Updates the displayed items and makes the display actor visible.
show: function() { show: function() {
this._keepDisplayCurrent = true; this._keepDisplayCurrent = true;
this._redisplay(); this._redisplay(true);
this._grid.show(); this._grid.show();
}, },
@ -337,19 +338,17 @@ GenericDisplay.prototype = {
* Displays items that match the current request and should show up on the current page. * Displays items that match the current request and should show up on the current page.
* Updates the display control to reflect the matched items set and the page selected. * Updates the display control to reflect the matched items set and the page selected.
* *
* matchedItemsChanged - indicates if the set of the matched items changed prior to the * resetDisplayControl - indicates if the display control should be re-created because
* request. If it did, the current page is reset to 0 and the display * the results or the space allocated for them changed. If it's false,
* control is updated. * the existing display control is used and only the page links are
* updated to reflect the current page selection.
*/ */
_displayMatchedItems: function(matchedItemsChanged) { _displayMatchedItems: function(resetDisplayControl) {
// When generating a new list to display, we first remove all the old // When generating a new list to display, we first remove all the old
// displayed items which will unset the selection. So we need // displayed items which will unset the selection. So we need
// to keep a flag which indicates if this display had the selection. // to keep a flag which indicates if this display had the selection.
let hadSelected = this.hasSelected(); let hadSelected = this.hasSelected();
if (matchedItemsChanged)
this._pageDisplayed = 0;
this._removeAllDisplayItems(); this._removeAllDisplayItems();
for (let i = this._maxItemsPerPage * this._pageDisplayed; i < this._matchedItems.length && i < this._maxItemsPerPage * (this._pageDisplayed + 1); i++) { for (let i = this._maxItemsPerPage * this._pageDisplayed; i < this._matchedItems.length && i < this._maxItemsPerPage * (this._pageDisplayed + 1); i++) {
@ -362,7 +361,7 @@ GenericDisplay.prototype = {
this.selectFirstItem(); this.selectFirstItem();
} }
this._updateDisplayControl(matchedItemsChanged); this._updateDisplayControl(resetDisplayControl);
}, },
// Creates a display item based on the information associated with itemId // Creates a display item based on the information associated with itemId
@ -434,8 +433,16 @@ GenericDisplay.prototype = {
this._removeDisplayItem(itemId); this._removeDisplayItem(itemId);
}, },
// Updates the displayed items, applying the search string if one exists. /*
_redisplay: function() { * Updates the displayed items, applying the search string if one exists.
*
* resetPage - indicates if the page selection should be reset when displaying the matching results.
* We reset the page selection when the change in results was initiated by the user by
* entering a different search criteria or by viewing the results list in a different
* size mode, but we keep the page selection the same if the results got updated on
* their own while the user was browsing through the result pages.
*/
_redisplay: function(resetPage) {
if (!this._keepDisplayCurrent) if (!this._keepDisplayCurrent)
return; return;
@ -445,6 +452,11 @@ GenericDisplay.prototype = {
else else
this._doSearchFilter(); this._doSearchFilter();
if (resetPage)
this._pageDisplayed = 0;
this._displayMatchedItems(true);
this.emit('redisplayed'); this.emit('redisplayed');
}, },
@ -492,8 +504,7 @@ GenericDisplay.prototype = {
this._height = maxItemsInColumn * ITEM_DISPLAY_HEIGHT; this._height = maxItemsInColumn * ITEM_DISPLAY_HEIGHT;
}, },
// Applies the search string to the list of items to find matches, // Applies the search string to the list of items to find matches, and displays the matching items.
// and displays the matching items.
_doSearchFilter: function() { _doSearchFilter: function() {
let matchedItemsForSearch = {}; let matchedItemsForSearch = {};
@ -529,8 +540,6 @@ GenericDisplay.prototype = {
else else
return this._compareItems(a, b); return this._compareItems(a, b);
})); }));
this._displayMatchedItems(true);
}, },
// Displays the page specified by the pageNumber argument. The pageNumber is 0-based. // Displays the page specified by the pageNumber argument. The pageNumber is 0-based.
@ -542,13 +551,13 @@ GenericDisplay.prototype = {
/* /*
* Updates the display control to reflect the matched items set and the page selected. * Updates the display control to reflect the matched items set and the page selected.
* *
* matchedItemsChanged - indicates if the set of the matched items changed prior to the * resetDisplayControl - indicates if the display control should be re-created because
* request. If it did, the display control is updated to reflect the * the results or the space allocated for them changed. If it's false,
* new set of pages. Otherwise, the page links are updated for the * the existing display control is used and only the page links are
* current set of pages. * updated to reflect the current page selection.
*/ */
_updateDisplayControl: function(matchedItemsChanged) { _updateDisplayControl: function(resetDisplayControl) {
if (matchedItemsChanged) { if (resetDisplayControl) {
this.displayControl.remove_all(); this.displayControl.remove_all();
let pageNumber = 0; let pageNumber = 0;
for (let i = 0; i < this._matchedItems.length; i = i + this._maxItemsPerPage) { for (let i = 0; i < this._matchedItems.length; i = i + this._maxItemsPerPage) {