Bug 305667 - Download manager inaccessible after download started with alt+click/alt+enter or context menu save as. r=mconnor

git-svn-id: svn://10.0.0.236/trunk@178967 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
doronr%us.ibm.com 2005-08-25 18:18:16 +00:00
parent 78dd90f582
commit 3946eb2ff9
3 changed files with 101 additions and 16 deletions

View File

@ -60,6 +60,9 @@
<![CDATA[
var x = document.getAnonymousElementByAttribute(this, "anonid", "main-box");
this.scrollBoxObject = x.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
// add a template build listener
this.builder.addListener(this._builder());
]]>
</constructor>
@ -85,6 +88,54 @@
</getter>
</property>
<method name="_builder">
<body>
<![CDATA[
var myThis = this;
return {
item: null,
willRebuild : function(builder) {},
didRebuild : function(builder) {
myThis._refreshSelection()
}
}
]]>
</body>
</method>
<method name="_refreshSelection">
<body>
<![CDATA[
// cache the selected index
var selectedIndex = this._selectedIndex;
// refreshes selection. Called for example when a template rebuild
// happens.
if (this.selectedItem && this.selectedItem.hasAttribute("id")) {
var id = this.selectedItem.getAttribute("id");
var item = document.getElementById(id);
// if we find no item, clear selection so that the code at the bottom
// takes over
if (item)
this.selectedItem = item;
else
this.clearSelection();
}
// if no id or the id no longer exists (above code fails)
if (!this.selectedItem) {
// if the selectedIndex is larger than the row count, select the last
// item.
if (selectedIndex >= this.getRowCount())
this.selectedIndex = this.getRowCount() - 1;
else
this.selectedIndex = selectedIndex;
}
]]>
</body>
</method>
<method name="fireActiveItemEvent">
<body>
<![CDATA[
@ -98,6 +149,7 @@
</body>
</method>
<field name="_selectedIndex">-1</field>
<property name="selectedIndex">
<getter>
<![CDATA[
@ -127,8 +179,10 @@
} else if (val >= 0) {
// only set if we get an item returned
var item = this.getItemAtIndex(val);
if (item)
if (item) {
this.selectedItem = item
this._selectedIndex = val;
}
}
]]>
</setter>
@ -152,6 +206,7 @@
this.fireActiveItemEvent();
}
this._selectedIndex = this.getIndexOf(val);
this._fireOnSelect();
]]>
</setter>
@ -161,6 +216,7 @@
<body>
<![CDATA[
this.selectedItem = null;
this._selectedIndex = -1;
]]>
</body>
</method>
@ -214,6 +270,26 @@
</body>
</method>
<method name="getIndexOf">
<parameter name="aElement"/>
<body>
<![CDATA[
var run = 0;
var index = -1;
var children = this.children;
while (children[run] != aElement && run < children.length) {
run++;
}
if (children[run] == aElement)
index = run;
return index;
]]>
</body>
</method>
<method name="init">
<body>
<![CDATA[

View File

@ -270,15 +270,39 @@ function onDownloadCancel(aEvent)
function onDownloadPause(aEvent)
{
var selectedIndex = gDownloadsView.selectedIndex;
var uri = aEvent.target.id;
gDownloadManager.pauseDownload(uri);
setRDFProperty(uri, "DownloadStatus", aEvent.target.getAttribute("status-internal"));
setRDFProperty(uri, "ProgressPercent", aEvent.target.getAttribute("progress"));
// now reset the richlistbox
gDownloadsView.clearSelection();
var rowCount = gDownloadsView.getRowCount();
if (selectedIndex >= rowCount)
gDownloadsView.selectedIndex = rowCount - 1;
else
gDownloadsView.selectedIndex = selectedIndex;
gDownloadsView.selectedItem.focus();
}
function onDownloadResume(aEvent)
{
var selectedIndex = gDownloadsView.selectedIndex;
gDownloadManager.resumeDownload(aEvent.target.id);
// now reset the richlistbox
gDownloadsView.clearSelection();
var rowCount = gDownloadsView.getRowCount();
if (selectedIndex >= rowCount)
gDownloadsView.selectedIndex = rowCount - 1;
else
gDownloadsView.selectedIndex = selectedIndex
gDownloadsView.selectedItem.focus();
}
function onDownloadRemove(aEvent)
@ -286,16 +310,6 @@ function onDownloadRemove(aEvent)
if (aEvent.target.removable) {
var selectedIndex = gDownloadsView.selectedIndex;
gDownloadManager.removeDownload(aEvent.target.id);
// now reset the richlistbox since the template was rebuilt
gDownloadsView.clearSelection();
if (selectedIndex >= gDownloadsView.getRowCount())
gDownloadsView.selectedIndex = selectedIndex - 1;
else
gDownloadsView.selectedIndex = selectedIndex;
gDownloadsView.focus();
gDownloadViewController.onCommandUpdate();
}
}

View File

@ -1033,7 +1033,6 @@ var gExtensionsViewController = {
var movingID = aSelectedItem.id;
var moveTopID = gExtensionsView.children[0].id;
gExtensionManager.moveToIndexOf(movingID, moveTopID);
gExtensionsView.selectedItem = document.getElementById(movingID);
},
cmd_moveup: function (aSelectedItem)
@ -1041,7 +1040,6 @@ var gExtensionsViewController = {
var movingID = aSelectedItem.id;
var moveAboveID = aSelectedItem.previousSibling.id;
gExtensionManager.moveToIndexOf(movingID, moveAboveID);
gExtensionsView.selectedItem = document.getElementById(movingID);
},
cmd_movedn: function (aSelectedItem)
@ -1049,7 +1047,6 @@ var gExtensionsViewController = {
var movingID = aSelectedItem.id;
var moveBelowID = aSelectedItem.nextSibling.id;
gExtensionManager.moveToIndexOf(movingID, moveBelowID);
gExtensionsView.selectedItem = document.getElementById(movingID);
},
cmd_update: function (aSelectedItem)
@ -1121,13 +1118,11 @@ var gExtensionsViewController = {
cmd_disable: function (aSelectedItem)
{
gExtensionManager.disableItem(getIDFromResourceURI(aSelectedItem.id));
gExtensionsView.selectedItem = document.getElementById(aSelectedItem.id);
},
cmd_enable: function (aSelectedItem)
{
gExtensionManager.enableItem(getIDFromResourceURI(aSelectedItem.id));
gExtensionsView.selectedItem = document.getElementById(aSelectedItem.id);
#ifdef MOZ_PHOENIX
}
}