diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 82831125d31..5c5eb6dd956 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2521,23 +2521,6 @@ function toNavigator() OpenBrowserWindow(); } -function toDownloadManager() -{ - var dlmgr = Components.classes['@mozilla.org/download-manager;1'].getService(); - dlmgr = dlmgr.QueryInterface(Components.interfaces.nsIDownloadManager); - - var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); - windowMediator = windowMediator.QueryInterface(nsIWindowMediator); - - var dlmgrWindow = windowMediator.getMostRecentWindow("Download:Manager"); - if (dlmgrWindow) { - dlmgrWindow.focus(); - } - else { - window.openDialog("chrome://browser/content/downloads/downloadmanager.xul", "Downloads", "chrome,extrachrome,resizable,scrollbars,toolbar,dialog=no"); - } -} - function toJavaScriptConsole() { toOpenWindowByType("global:console", "chrome://browser/content/console/console.xul"); diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 67eab85f773..a5ceac1b319 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -171,6 +171,7 @@ Contributor(s): - @@ -883,9 +883,9 @@ Contributor(s): diff --git a/browser/base/locale/browser.dtd b/browser/base/locale/browser.dtd index 3e9df95c3ad..a8b5c4369af 100644 --- a/browser/base/locale/browser.dtd +++ b/browser/base/locale/browser.dtd @@ -252,4 +252,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/browser/base/skin/browser.css b/browser/base/skin/browser.css index c8f004a69fa..b281efd2ad8 100644 --- a/browser/base/skin/browser.css +++ b/browser/base/skin/browser.css @@ -704,23 +704,11 @@ toolbar[iconsize="small"] #history-button[disabled="true"] { -moz-image-region: rect(0px 53px 27px 27px) !important; } -#sidebar-header { - height: 23px; - background-color: -moz-Dialog; - -moz-appearance: toolbox; - border-bottom: 1px solid ThreeDShadow; - border-top: 1px solid ThreeDHighlight; -} - #sidebar { border-bottom: 1px solid ThreeDShadow; background-color: white; } -#sidebar-title { - padding-left: 4px; -} - #go-button[disabled="true"] { -moz-image-region: rect(0px 80px 27px 54px) !important; } diff --git a/browser/components/downloads/content/downloadPanel.js b/browser/components/downloads/content/downloadPanel.js index f2a06360d72..f5bfb925072 100644 --- a/browser/components/downloads/content/downloadPanel.js +++ b/browser/components/downloads/content/downloadPanel.js @@ -1,13 +1,16 @@ const kObserverServiceProgID = "@mozilla.org/observer-service;1"; -var gDownloadView, gDownloadManager; +var gDownloadView; +var gDownloadManager; +var gDownloadHistoryView; +var gRDFService; const dlObserver = { observe: function(subject, topic, state) { - var subject = subject.QueryInterface(Components.interfaces.nsIDownload); - var elt = document.getElementById(subject.target.path); + var dl = subject.QueryInterface(Components.interfaces.nsIDownload); + var elt = document.getElementById(dl.target.path); switch (topic) { case "dl-progress": - elt.setAttribute("progress", subject.percentComplete); + elt.setAttribute("progress", dl.percentComplete); break; default: elt.onEnd(topic); @@ -18,20 +21,32 @@ const dlObserver = { function Startup() { gDownloadView = document.getElementById("downloadView"); + gDownloadHistoryView = document.getElementById("downloadHistoryView"); const dlmgrContractID = "@mozilla.org/download-manager;1"; const dlmgrIID = Components.interfaces.nsIDownloadManager; gDownloadManager = Components.classes[dlmgrContractID].getService(dlmgrIID); var ds = gDownloadManager.datasource; gDownloadView.database.AddDataSource(ds); gDownloadView.builder.rebuild(); + gDownloadHistoryView.database.AddDataSource(ds); + gDownloadHistoryView.builder.rebuild(); + const rdfSvcContractID = "@mozilla.org/rdf/rdf-service;1"; + const rdfSvcIID = Components.interfaces.nsIRDFService; + gRDFService = Components.classes[rdfSvcContractID].getService(rdfSvcIID); + var observerService = Components.classes[kObserverServiceProgID] .getService(Components.interfaces.nsIObserverService); observerService.addObserver(dlObserver, "dl-progress", false); observerService.addObserver(dlObserver, "dl-done", false); observerService.addObserver(dlObserver, "dl-cancel", false); observerService.addObserver(dlObserver, "dl-failed", false); + + window.setTimeout(onRebuild, 0); +} +function onRebuild() { + gDownloadHistoryView.controllers.appendController(downloadViewController); } function Shutdown() { @@ -68,3 +83,137 @@ var downloadDNDObserver = return this._flavourSet; } } + +function onSelect(aEvent) { + window.updateCommands("tree-select"); +} + +var downloadViewController = { + supportsCommand: function dVC_supportsCommand (aCommand) + { + switch (aCommand) { + case "cmd_properties": + case "cmd_remove": + case "cmd_openfile": + case "cmd_showinshell": + case "cmd_selectAll": + return true; + } + return false; + }, + + isCommandEnabled: function dVC_isCommandEnabled (aCommand) + { + var selectionCount = gDownloadHistoryView.selectedCount; + if (!selectionCount) return false; + + var selectedItem = gDownloadHistoryView.selectedItem; + switch (aCommand) { + case "cmd_openfile": + return selectionCount == 1; + case "cmd_showinshell": + return selectionCount == 1; + case "cmd_remove": + return selectionCount; + case "cmd_selectAll": + return gDownloadHistoryView.getRowCount() != selectionCount; + default: + return false; + } + }, + + doCommand: function dVC_doCommand (aCommand) + { + var selectedItem, selectedItems; + var file, i; + + switch (aCommand) { + case "cmd_openfile": + selectedItem = gDownloadHistoryView.selectedItem; + file = getFileForItem(selectedItem); + file.launch(); + break; + case "cmd_showinshell": + selectedItem = gDownloadHistoryView.selectedItem; + file = getFileForItem(selectedItem); + + // on unix, open a browser window rooted at the parent + if (navigator.platform.indexOf("Win") == -1 && navigator.platform.indexOf("Mac") == -1) { + file = file.QueryInterface(Components.interfaces.nsIFile); + var parent = file.parent; + if (parent) { + //XXXBlake use chromeUrlForTask pref here + const browserURL = "chrome://browser/content/browser.xul"; + window.openDialog(browserURL, "_blank", "chrome,all,dialog=no", parent.path); + } + } + else { + file.reveal(); + } + break; + case "cmd_remove": + selectedItems = gDownloadHistoryView.selectedItems; + var selectedIndex = gDownloadHistoryView.selectedIndex; + gDownloadManager.startBatchUpdate(); + + // Notify the datasource that we're about to begin a batch operation + var observer = gDownloadHistoryView.builder.QueryInterface(Components.interfaces.nsIRDFObserver); + var ds = gDownloadHistoryView.database; + observer.beginUpdateBatch(ds); + + for (i = 0; i <= selectedItems.length - 1; ++i) { + gDownloadManager.removeDownload(selectedItems[i].id); + } + + gDownloadManager.endBatchUpdate(); + observer.endUpdateBatch(ds); + var remote = gDownloadManager.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource); + remote.Flush(); + gDownloadHistoryView.builder.rebuild(); + var rowCount = gDownloadHistoryView.getRowCount(); + if (selectedIndex > ( rowCount- 1)) + selectedIndex = rowCount - 1; + + gDownloadHistoryView.selectedIndex = selectedIndex; + break; + case "cmd_selectAll": + gDownloadHistoryView.selectAll(); + break; + default: + } + }, + + onEvent: function dVC_onEvent (aEvent) + { + switch (aEvent) { + case "tree-select": + this.onCommandUpdate(); + } + }, + + onCommandUpdate: function dVC_onCommandUpdate () + { + var cmds = ["cmd_properties", "cmd_pause", "cmd_cancel", "cmd_remove", + "cmd_openfile", "cmd_showinshell"]; + for (var command in cmds) + goUpdateCommand(cmds[command]); + } +}; + +function getFileForItem(aElement) +{ + var itemResource = gRDFService.GetResource(aElement.id); + var NC_File = gRDFService.GetResource(NC_NS + "File"); + var fileResource = gDownloadHistoryView.database.GetTarget(itemResource, NC_File, true); + fileResource = fileResource.QueryInterface(Components.interfaces.nsIRDFResource); + return createLocalFile(fileResource.Value); +} + +function createLocalFile(aFilePath) +{ + var lfContractID = "@mozilla.org/file/local;1"; + var lfIID = Components.interfaces.nsILocalFile; + var lf = Components.classes[lfContractID].createInstance(lfIID); + lf.initWithPath(aFilePath); + return lf; +} diff --git a/browser/components/downloads/content/downloadPanel.xul b/browser/components/downloads/content/downloadPanel.xul index 925621f956f..0209c8a12ee 100644 --- a/browser/components/downloads/content/downloadPanel.xul +++ b/browser/components/downloads/content/downloadPanel.xul @@ -2,6 +2,11 @@ + +%downloadManagerDTD; +]> +