141410 - download manager doesn't highlight the active transfer by default. r=caillon sr=ben a=asa

This commit is contained in:
blakeross%telocity.com 2002-07-27 00:47:18 +00:00
parent 42b95e93bf
commit 0b2bc1dde5
5 changed files with 77 additions and 23 deletions

View File

@ -125,9 +125,12 @@ interface nsIDownloadManager : nsISupports {
* Opens the Download Manager front end.
*
* @param aParent The parent, or opener, of the front end (optional).
* @param aDownload A download to pass to the manager window. Useful
* if, for example, you want the window to select a
* certain download (optional).
*/
void open(in nsIDOMWindow aParent);
void open(in nsIDOMWindow aParent, in nsIDownload aDownload);
/**
* Opens an individual progress dialog displaying progress for the download.

View File

@ -46,11 +46,34 @@ var gRDFService = null;
var gNC_File = null;
var gStatusBar = null;
const dlObserver = {
observe: function(subject, topic, state) {
if (topic != "download-starting") return;
selectDownload(subject.QueryInterface(Components.interfaces.nsIDownload));
}
};
function selectDownload(aDownload)
{
var dlElt = document.getElementById(aDownload.target.path);
var dlIndex = gDownloadView.contentView.getIndexOfItem(dlElt);
gDownloadView.treeBoxObject.selection.select(dlIndex);
gDownloadView.treeBoxObject.ensureRowIsVisible(dlIndex);
}
function Startup()
{
if (!window.arguments.length)
return;
try {
var observerService = Components.classes[kObserverServiceProgID]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(dlObserver, "download-starting", false);
}
catch (ex) {
}
const rdfSvcContractID = "@mozilla.org/rdf/rdf-service;1";
const rdfSvcIID = Components.interfaces.nsIRDFService;
gRDFService = Components.classes[rdfSvcContractID].getService(rdfSvcIID);
@ -89,15 +112,25 @@ function Startup()
function onRebuild() {
gDownloadView.controllers.appendController(downloadViewController);
gDownloadView.focus();
// Select the first item in the view, if any.
if (gDownloadView.view.rowCount)
// If the window was opened automatically because
// a download started, select the new download
if (window.arguments.length > 1 && window.arguments[1]) {
var dl = window.arguments[1];
selectDownload(dl.QueryInterface(Components.interfaces.nsIDownload));
}
else if (gDownloadView.view.rowCount) {
// Select the first item in the view, if any.
gDownloadView.treeBoxObject.selection.select(0);
}
}
function onSelect(aEvent) {
if (!gStatusBar)
gStatusBar = document.getElementById("statusbar-text");
if (gDownloadView.currentIndex >= 0)
var selectionCount = gDownloadView.treeBoxObject.selection.count;
if (selectionCount == 1)
gStatusBar.label = getSelectedItem().id;
else
gStatusBar.label = "";
@ -130,14 +163,8 @@ var downloadViewController = {
var isDownloading = gDownloadManager.getDownload(selectedItem.id);
switch (aCommand) {
case "cmd_openfile":
try {
if (!isDownloading && getFileForItem(selectedItem).isExecutable())
return false;
} catch(e) {
// Exception means file doesn't exist; launch is not allowed.
if (isDownloading)
return false;
}
case "cmd_showinshell":
// some apps like kazaa/morpheus let you "preview" in-progress downloads because
// that's possible for movies and music. for now, just disable indiscriminately.
@ -174,6 +201,16 @@ var downloadViewController = {
case "cmd_openfile":
selectedItem = getSelectedItem();
file = getFileForItem(selectedItem);
if (file.isExecutable()) {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var strBundle = document.getElementById("dlProgressDlgBundle");
var title = strBundle.getFormattedString("openingAlertTitle", [file.leafName]);
var msg = strBundle.getFormattedString("securityAlertMsg", [file.leafName]);
var okToProceed = promptService.confirm(window, title, msg);
if (!okToProceed)
return;
}
file.launch();
break;
case "cmd_showinshell":
@ -202,7 +239,6 @@ var downloadViewController = {
gDownloadManager.cancelDownload(selectedItems[i].id);
window.updateCommands("tree-select");
break;
case "cmd_remove":
case "cmd_remove":
selectedItems = getSelectedItems();
gDownloadManager.startBatchUpdate();
@ -288,3 +324,14 @@ function createLocalFile(aFilePath)
lf.initWithPath(aFilePath);
return lf;
}
function Shutdown()
{
try {
var observerService = Components.classes[kObserverServiceProgID]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(dlObserver, "download-starting");
}
catch (ex) {
}
}

View File

@ -44,7 +44,8 @@
width="500" height="300" screenX="10" screenY="10"
persist="width height screenX screenY"
title="&downloadManager.title;"
onload="Startup();">
onload="Startup();"
onunload="Shutdown();">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
@ -52,6 +53,8 @@
<stringbundle id="dlMgrBundle"
src="chrome://communicator/locale/downloadmanager/downloadmanager.properties"/>
<stringbundle id="dlProgressDlgBundle"
src="chrome://global/locale/nsProgressDialog.properties"/>
<data id="strings.confirmCancel">&confirmCancel;</data>
<data id="strings.progressMsgNoRate">&progressMsgNoRate;</data>

View File

@ -698,7 +698,7 @@ nsDownloadManager::EndBatchUpdate()
}
NS_IMETHODIMP
nsDownloadManager::Open(nsIDOMWindow* aParent)
nsDownloadManager::Open(nsIDOMWindow* aParent, nsIDownload* aDownload)
{
// first assert new progress info so the ui is correctly updated
@ -710,11 +710,16 @@ nsDownloadManager::Open(nsIDOMWindow* aParent)
nsCOMPtr<nsIWindowMediator> wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupports> dlSupports(do_QueryInterface(aDownload));
// if the window's already open, do nothing (focusing it would be annoying)
nsCOMPtr<nsIDOMWindowInternal> recentWindow;
wm->GetMostRecentWindow(NS_LITERAL_STRING("Download:Manager").get(), getter_AddRefs(recentWindow));
if (recentWindow)
return NS_OK;
if (recentWindow) {
nsCOMPtr<nsIObserverService> obsService = do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_FAILED(rv)) return rv;
return obsService->NotifyObservers(dlSupports, "download-starting", nsnull);
}
// if we ever have the capability to display the UI of third party dl managers,
// we'll open their UI here instead.
@ -725,6 +730,7 @@ nsDownloadManager::Open(nsIDOMWindow* aParent)
nsCOMPtr<nsISupportsArray> params(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID));
nsCOMPtr<nsISupports> dsSupports(do_QueryInterface(mDataSource));
params->AppendElement(dsSupports);
params->AppendElement(dlSupports);
nsCOMPtr<nsIDOMWindow> newWindow;
rv = ww->OpenWindow(aParent,
@ -736,16 +742,12 @@ nsDownloadManager::Open(nsIDOMWindow* aParent)
if (NS_FAILED(rv)) return rv;
// XXX whether or not mDocument is null is not a sufficient flag,
// because in the future we may support using a third party download manager that
// doesn't use our architecture
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(newWindow);
if (!target) return NS_ERROR_FAILURE;
rv = target->AddEventListener(NS_LITERAL_STRING("load"), this, PR_FALSE);
if (NS_FAILED(rv)) return rv;
return target->AddEventListener(NS_LITERAL_STRING("unload"), this, PR_FALSE);
}
@ -841,7 +843,6 @@ nsDownloadManager::HandleEvent(nsIDOMEvent* aEvent)
nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(target));
mDocument = do_QueryInterface(targetNode);
mListener->SetDocument(mDocument);
return NS_OK;
}

View File

@ -77,7 +77,7 @@ public:
branch->GetIntPref(DOWNLOAD_MANAGER_BEHAVIOR_PREF, &behavior);
if (behavior == 0)
return dm->Open(nsnull);
return dm->Open(nsnull, this);
if (behavior == 1) {
nsCAutoString path;
rv = aTarget->GetNativePath(path);