Bug 876033 - Reselect TopSites tiles when we undo deletion. r=mbrubeck

--HG--
extra : rebase_source : 38e8f9557d98b6bbdd2960f2a54550a388f19582
This commit is contained in:
Sam Foster 2013-07-17 11:19:42 -07:00
parent 347c59e564
commit 99290f8d63

View File

@ -212,13 +212,36 @@ TopSitesView.prototype = {
// we need new context buttons to show (the tile node will go away though)
}
this._lastSelectedSites = (this._lastSelectedSites || []).concat(sites);
// stop the appbar from dismissing
aEvent.preventDefault();
nextContextActions.add('restore');
TopSites.hideSites(sites);
break;
case "restore":
// usually restore is an undo action, so there's no tiles/selection to act on
// usually restore is an undo action, so we have to recreate the tiles and grid selection
if (this._lastSelectedSites) {
let selectedUrls = this._lastSelectedSites.map((site) => site.url);
// re-select the tiles once the tileGroup is done populating and arranging
tileGroup.addEventListener("arranged", function _onArranged(aEvent){
for (let url of selectedUrls) {
let tileNode = tileGroup.querySelector("richgriditem[value='"+url+"']");
if (tileNode) {
tileNode.setAttribute("selected", true);
}
}
tileGroup.removeEventListener("arranged", _onArranged, false);
// <sfoster> we can't just call selectItem n times on tileGroup as selecting means trigger the default action
// for seltype="single" grids.
// so we toggle the attributes and raise the selectionchange "manually"
let event = tileGroup.ownerDocument.createEvent("Events");
event.initEvent("selectionchange", true, true);
tileGroup.dispatchEvent(event);
}, false);
TopSites.restoreSites(this._lastSelectedSites);
// stop the appbar from dismissing,
// the selectionchange event will trigger re-population of the context appbar
aEvent.preventDefault();
}
break;
case "pin":
@ -240,8 +263,6 @@ TopSitesView.prototype = {
// default: no action
}
if (nextContextActions.size) {
// stop the appbar from dismissing
aEvent.preventDefault();
// at next tick, re-populate the context appbar
setTimeout(function(){
// fire a MozContextActionsChange event to update the context appbar
@ -254,6 +275,7 @@ TopSitesView.prototype = {
},0);
}
},
handleEvent: function(aEvent) {
switch (aEvent.type){
case "MozAppbarDismissing":
@ -278,11 +300,8 @@ TopSitesView.prototype = {
} else {
// flush, recreate all
this.isUpdating = true;
// destroy and recreate all item nodes
let item;
while ((item = grid.firstChild)){
grid.removeChild(item);
}
// destroy and recreate all item nodes, skip calling arrangeItems
grid.clearAll(true);
this.populateGrid();
}
},