mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1116769 - Change webapprt downloadItems to a Map and remove nonstandard for-each-in loops. r=mak
This commit is contained in:
parent
aa438796b6
commit
5d700f7d59
@ -578,7 +578,7 @@ DownloadItem.prototype = {
|
|||||||
|
|
||||||
let gDownloadList = {
|
let gDownloadList = {
|
||||||
downloadItemsMap: new Map(),
|
downloadItemsMap: new Map(),
|
||||||
downloadItems: {},
|
idToDownloadItemMap: new Map(),
|
||||||
_autoIncrementID: 0,
|
_autoIncrementID: 0,
|
||||||
downloadView: null,
|
downloadView: null,
|
||||||
searchBox: null,
|
searchBox: null,
|
||||||
@ -727,7 +727,7 @@ let gDownloadList = {
|
|||||||
this.downloadView.parentNode.replaceChild(empty, this.downloadView);
|
this.downloadView.parentNode.replaceChild(empty, this.downloadView);
|
||||||
this.downloadView = empty;
|
this.downloadView = empty;
|
||||||
|
|
||||||
for each (let downloadItem in this.downloadItems) {
|
for (let downloadItem of this.idToDownloadItemMap.values()) {
|
||||||
if (downloadItem.inProgress ||
|
if (downloadItem.inProgress ||
|
||||||
downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
|
downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
|
||||||
this.downloadView.appendChild(downloadItem.element);
|
this.downloadView.appendChild(downloadItem.element);
|
||||||
@ -773,7 +773,7 @@ let gDownloadList = {
|
|||||||
let button = document.getElementById("clearListButton");
|
let button = document.getElementById("clearListButton");
|
||||||
|
|
||||||
// The button is enabled if we have items in the list that we can clean up.
|
// The button is enabled if we have items in the list that we can clean up.
|
||||||
for each (let downloadItem in this.downloadItems) {
|
for (let downloadItem of this.idToDownloadItemMap.values()) {
|
||||||
if (!downloadItem.inProgress &&
|
if (!downloadItem.inProgress &&
|
||||||
downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
|
downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
@ -808,8 +808,7 @@ let gDownloadList = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.downloadView.selectedItem) {
|
if (this.downloadView.selectedItem) {
|
||||||
let dl = this.downloadView.selectedItem;
|
let downloadItem = this._getSelectedDownloadItem();
|
||||||
let downloadItem = this.downloadItems[dl.getAttribute("id")];
|
|
||||||
|
|
||||||
let idx = downloadItem.state;
|
let idx = downloadItem.state;
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
@ -838,13 +837,11 @@ let gDownloadList = {
|
|||||||
*/
|
*/
|
||||||
doDefaultForSelected: function() {
|
doDefaultForSelected: function() {
|
||||||
// Make sure we have something selected.
|
// Make sure we have something selected.
|
||||||
let item = this.downloadView.selectedItem;
|
let download = this._getSelectedDownloadItem();
|
||||||
if (!item) {
|
if (!download) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let download = this.downloadItems[item.getAttribute("id")];
|
|
||||||
|
|
||||||
// Get the default action (first item in the menu).
|
// Get the default action (first item in the menu).
|
||||||
let menuitem = document.getElementById(this.contextMenus[download.state][0]);
|
let menuitem = document.getElementById(this.contextMenus[download.state][0]);
|
||||||
|
|
||||||
@ -891,17 +888,17 @@ let gDownloadList = {
|
|||||||
elm = elm.parentNode;
|
elm = elm.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
let downloadItem = this.downloadItems[elm.getAttribute("id")];
|
let downloadItem = this._getDownloadItemForElement(elm);
|
||||||
downloadItem.doCommand(aCmd);
|
downloadItem.doCommand(aCmd);
|
||||||
},
|
},
|
||||||
|
|
||||||
onDragStart: function(aEvent) {
|
onDragStart: function(aEvent) {
|
||||||
if (!this.downloadView.selectedItem) {
|
let downloadItem = this._getSelectedDownloadItem();
|
||||||
|
if (!downloadItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dl = this.downloadView.selectedItem;
|
let dl = this.downloadView.selectedItem;
|
||||||
let downloadItem = this.downloadItems[dl.getAttribute("id")];
|
|
||||||
let f = downloadItem.localFile;
|
let f = downloadItem.localFile;
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
return;
|
return;
|
||||||
@ -983,7 +980,7 @@ let gDownloadList = {
|
|||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
let totalTransferred = 0;
|
let totalTransferred = 0;
|
||||||
|
|
||||||
for each (let downloadItem in this.downloadItems) {
|
for (let downloadItem of this.idToDownloadItemMap.values()) {
|
||||||
if (!downloadItem.inProgress) {
|
if (!downloadItem.inProgress) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1030,7 +1027,7 @@ let gDownloadList = {
|
|||||||
|
|
||||||
let downloadItem = new DownloadItem(newID, aDownload);
|
let downloadItem = new DownloadItem(newID, aDownload);
|
||||||
this.downloadItemsMap.set(aDownload, downloadItem);
|
this.downloadItemsMap.set(aDownload, downloadItem);
|
||||||
this.downloadItems[newID] = downloadItem;
|
this.idToDownloadItemMap.set(newID, downloadItem);
|
||||||
|
|
||||||
if (downloadItem.inProgress ||
|
if (downloadItem.inProgress ||
|
||||||
downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
|
downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) {
|
||||||
@ -1088,7 +1085,7 @@ let gDownloadList = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.downloadItemsMap.delete(aDownload);
|
this.downloadItemsMap.delete(aDownload);
|
||||||
delete this.downloadItems[downloadItem.id];
|
this.idToDownloadItemMap.delete(downloadItem.id);
|
||||||
|
|
||||||
this.removeFromView(downloadItem);
|
this.removeFromView(downloadItem);
|
||||||
},
|
},
|
||||||
@ -1106,6 +1103,13 @@ let gDownloadList = {
|
|||||||
// We might have removed the last item, so update the clear list button.
|
// We might have removed the last item, so update the clear list button.
|
||||||
this.updateClearListButton();
|
this.updateClearListButton();
|
||||||
},
|
},
|
||||||
|
_getDownloadItemForElement(element) {
|
||||||
|
return this.idToDownloadItemMap.get(element.getAttribute("id"));
|
||||||
|
},
|
||||||
|
_getSelectedDownloadItem() {
|
||||||
|
let dl = this.downloadView.selectedItem;
|
||||||
|
return dl ? this._getDownloadItemForElement(dl) : null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function Startup() {
|
function Startup() {
|
||||||
|
Loading…
Reference in New Issue
Block a user