mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-07 15:57:31 +09:00
[PALEMOON] Bug 1115369 - Use notifications instead of getViewItem for DownloadsView
This commit is contained in:
parent
bed4e6a109
commit
e4e51e5782
3 changed files with 78 additions and 98 deletions
|
|
@ -570,7 +570,7 @@ const DownloadsPanel = {
|
|||
// still exist, and update the allowed items interactions accordingly. We
|
||||
// do these checks on a background thread, and don't prevent the panel to
|
||||
// be displayed while these checks are being performed.
|
||||
for each (let viewItem in DownloadsView._viewItems) {
|
||||
for (let viewItem of DownloadsView._visibleViewItems.values()) {
|
||||
viewItem.verifyTargetExists();
|
||||
}
|
||||
|
||||
|
|
@ -711,11 +711,11 @@ const DownloadsView = {
|
|||
_dataItems: [],
|
||||
|
||||
/**
|
||||
* Object containing the available DownloadsViewItem objects, indexed by their
|
||||
* numeric download identifier. There is a limited number of view items in
|
||||
* the panel at any given time.
|
||||
* Associates the visible DownloadsDataItem objects with their corresponding
|
||||
* DownloadsViewItem object. There is a limited number of view items in the
|
||||
* panel at any given time.
|
||||
*/
|
||||
_viewItems: {},
|
||||
_visibleViewItems: new Map(),
|
||||
|
||||
/**
|
||||
* Called when the number of items in the list changes.
|
||||
|
|
@ -879,31 +879,21 @@ const DownloadsView = {
|
|||
this._itemCountChanged();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the view item associated with the provided data item for this view.
|
||||
*
|
||||
* @param aDataItem
|
||||
* DownloadsDataItem object for which the view item is requested.
|
||||
*
|
||||
* @return Object that can be used to notify item status events.
|
||||
*/
|
||||
getViewItem: function DV_getViewItem(aDataItem)
|
||||
{
|
||||
// If the item is visible, just return it, otherwise return a mock object
|
||||
// that doesn't react to notifications.
|
||||
if (aDataItem.downloadGuid in this._viewItems) {
|
||||
return this._viewItems[aDataItem.downloadGuid];
|
||||
// DownloadsView
|
||||
onDataItemStateChanged(aDataItem, aOldState) {
|
||||
let viewItem = this._visibleViewItems.get(aDataItem);
|
||||
if (viewItem) {
|
||||
viewItem.onStateChanged(aOldState);
|
||||
}
|
||||
return this._invisibleViewItem;
|
||||
},
|
||||
|
||||
/**
|
||||
* Mock DownloadsDataItem object that doesn't react to notifications.
|
||||
*/
|
||||
_invisibleViewItem: Object.freeze({
|
||||
onStateChange: function () { },
|
||||
onProgressChange: function () { }
|
||||
}),
|
||||
// DownloadsView
|
||||
onDataItemChanged(aDataItem) {
|
||||
let viewItem = this._visibleViewItems.get(aDataItem);
|
||||
if (viewItem) {
|
||||
viewItem.onChanged();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new view item associated with the specified data item, and adds
|
||||
|
|
@ -916,7 +906,7 @@ const DownloadsView = {
|
|||
|
||||
let element = document.createElement("richlistitem");
|
||||
let viewItem = new DownloadsViewItem(aDataItem, element);
|
||||
this._viewItems[aDataItem.downloadGuid] = viewItem;
|
||||
this._visibleViewItems.set(aDataItem, viewItem);
|
||||
if (aNewest) {
|
||||
this.richListBox.insertBefore(element, this.richListBox.firstChild);
|
||||
} else {
|
||||
|
|
@ -930,14 +920,14 @@ const DownloadsView = {
|
|||
_removeViewItem: function DV_removeViewItem(aDataItem)
|
||||
{
|
||||
DownloadsCommon.log("Removing a DownloadsViewItem from the downloads list.");
|
||||
let element = this.getViewItem(aDataItem)._element;
|
||||
let element = this._visibleViewItems.get(aDataItem)._element;
|
||||
let previousSelectedIndex = this.richListBox.selectedIndex;
|
||||
this.richListBox.removeChild(element);
|
||||
if (previousSelectedIndex != -1) {
|
||||
this.richListBox.selectedIndex = Math.min(previousSelectedIndex,
|
||||
this.richListBox.itemCount - 1);
|
||||
}
|
||||
delete this._viewItems[aDataItem.downloadGuid];
|
||||
this._visibleViewItems.delete(aDataItem);
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1134,7 +1124,7 @@ DownloadsViewItem.prototype = {
|
|||
* the download might be the same as before, if the data layer received
|
||||
* multiple events for the same download.
|
||||
*/
|
||||
onStateChange: function DVI_onStateChange(aOldState)
|
||||
onStateChanged(aOldState) {
|
||||
{
|
||||
// If a download just finished successfully, it means that the target file
|
||||
// now exists and we can extract its specific icon. To ensure that the icon
|
||||
|
|
@ -1155,14 +1145,12 @@ DownloadsViewItem.prototype = {
|
|||
|
||||
// Update the user interface after switching states.
|
||||
this._element.setAttribute("state", this.dataItem.state);
|
||||
this._updateProgress();
|
||||
this._updateStatusLine();
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the download progress has changed.
|
||||
*/
|
||||
onProgressChange: function DVI_onProgressChange() {
|
||||
onChanged() {
|
||||
this._updateProgress();
|
||||
this._updateStatusLine();
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue