Revised download UI.

git-svn-id: svn://10.0.0.236/trunk@130774 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
blakeross%telocity.com
2002-09-30 03:23:09 +00:00
parent ff629c1add
commit 35f08349d6
5 changed files with 3 additions and 435 deletions

View File

@@ -1,254 +0,0 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
* Blake Ross <blakeross@telocity.com>
* Jan Varga <varga@utcru.sk>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const NC_NS = "http://home.netscape.com/NC-rdf#";
var gDownloadManager = null;
var gDownloadView = null;
var gRDFService = null;
var gNC_File = null;
var gStatusBar = null;
function selectDownload(aDownload)
{
var dlElt = document.getElementById(aDownload.target.path);
}
function Startup()
{
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);
gNC_File = gRDFService.GetResource(NC_NS + "File");
const dlmgrContractID = "@mozilla.org/download-manager;1";
const dlmgrIID = Components.interfaces.nsIDownloadManager;
gDownloadManager = Components.classes[dlmgrContractID].getService(dlmgrIID);
var ds = gDownloadManager.datasource;
gDownloadView = document.getElementById("downloadView");
gDownloadView.database.AddDataSource(ds);
gDownloadView.builder.rebuild();
window.setTimeout(onRebuild, 0);
var key;
if (navigator.platform.indexOf("Win") != -1)
key = "Win";
else if (navigator.platform.indexOf("Mac") != -1)
key = "Mac";
else {
key = "Unix";
document.getElementById("btn_openfile").hidden = true;
}
var bundle = document.getElementById("dlMgrBundle")
var label = bundle.getString("showInShellLabel" + key);
var accesskey = bundle.getString("showInShellAccesskey" + key);
var showBtn = document.getElementById("btn_showinshell");
showBtn.setAttribute("label", label);
showBtn.setAttribute("accesskey", accesskey);
}
function onRebuild() {
gDownloadView.controllers.appendController(downloadViewController);
gDownloadView.treeBoxObject.selection.select(0);
}
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 = gDownloadView.treeBoxObject.selection.count;
if (!selectionCount) return false;
var selectedItem = getSelectedItem();
switch (aCommand) {
case "cmd_openfile":
return selectionCount == 1;
case "cmd_showinshell":
return selectionCount == 1;
case "cmd_remove":
return selectionCount;
case "cmd_selectAll":
return gDownloadView.view.rowCount != selectionCount;
default:
return false;
}
},
doCommand: function dVC_doCommand (aCommand)
{
var selectedItem, selectedItems;
var file, i;
switch (aCommand) {
case "cmd_openfile":
selectedItem = getSelectedItem();
file = getFileForItem(selectedItem);
file.launch();
break;
case "cmd_showinshell":
selectedItem = getSelectedItem();
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/navigator.xul";
window.openDialog(browserURL, "_blank", "chrome,all,dialog=no", parent.path);
}
}
else {
file.reveal();
}
break;
case "cmd_remove":
selectedItems = getSelectedItems();
gDownloadManager.startBatchUpdate();
// Notify the datasource that we're about to begin a batch operation
var observer = gDownloadView.builder.QueryInterface(Components.interfaces.nsIRDFObserver);
var ds = gDownloadView.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();
gDownloadView.builder.rebuild();
if (minValue >= gDownloadView.treeBoxObject.view.rowCount)
--minValue;
gDownloadView.treeBoxObject.selection.select(minValue);
break;
case "cmd_selectAll":
gDownloadView.treeBoxObject.selection.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 getSelectedItem()
{
return gDownloadView.contentView.getItemAtIndex(gDownloadView.currentIndex);
}
function getSelectedItems()
{
var items = [];
var k = 0;
var selection = gDownloadView.treeBoxObject.selection;
var rangeCount = selection.getRangeCount();
for (var i = 0; i < rangeCount; i++) {
var startIndex = {};
var endIndex = {};
selection.getRangeAt(i, startIndex, endIndex);
for (var j = startIndex.value; j <= endIndex.value; j++)
items[k++] = gDownloadView.contentView.getItemAtIndex(j);
}
return items;
}
function getFileForItem(aElement)
{
var itemResource = gRDFService.GetResource(aElement.id);
var fileResource = gDownloadView.database.GetTarget(itemResource, gNC_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;
}

View File

@@ -1,176 +0,0 @@
<?xml version="1.0"?>
<!--
The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is mozilla.org code.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Ben Goodger <ben@netscape.com> (Original Author)
Blake Ross <blaker@netscape.com>
Jan Varga <varga@utcru.sk>
-->
<?xml-stylesheet href="chrome://global/skin/"?>
<?xml-stylesheet href="chrome://browser/skin/downloads/downloadmanager.css"?>
<?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>
<!DOCTYPE window [
<!ENTITY % downloadManagerDTD SYSTEM "chrome://browser/locale/downloads/downloadmanager.dtd">
%downloadManagerDTD;
<!ENTITY % downloadProgressDTD SYSTEM "chrome://global/locale/nsProgressDialog.dtd" >
%downloadProgressDTD;
]>
<window id="downloadManager"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:nc="http://home.netscape.com/NC-rdf#"
windowtype="Download:Manager"
width="500" height="300" screenX="10" screenY="10"
persist="width height screenX screenY"
title="&downloadManager.title;"
onload="Startup();">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://browser/content/downloads/downloadmanager.js"/>
<commandset id="commandUpdate_Downloads"
commandupdater="true"
events="focus,tree-select"
oncommandupdate="downloadViewController.onCommandUpdate()"/>
<command id="cmd_properties"
oncommand="goDoCommand('cmd_properties');"/>
<command id="cmd_remove"
oncommand="goDoCommand('cmd_remove');"/>
<command id="cmd_openfile"
oncommand="goDoCommand('cmd_openfile');"/>
<command id="cmd_showinshell"
oncommand="goDoCommand('cmd_showinshell');"/>
<keyset>
<key id="key_remove" keycode="VK_DELETE" command="cmd_remove"/>
</keyset>
<toolbox id="toolbox">
<toolbar id="download-toolbar" tbalign="stretch" class="chromeclass-toolbar" persist="collapsed">
<toolbarbutton label="&cmd.remove.label;" accesskey="&cmd.remove.accesskey;"
command="cmd_remove"/>
<toolbarseparator/>
<toolbarbutton id="btn_openfile" label="&cmd.openfile.label;" accesskey="&cmd.openfile.accesskey;"
command="cmd_openfile"/>
<toolbarbutton id="btn_showinshell" command="cmd_showinshell"/>
</toolbar>
</toolbox>
<tree id="downloadView" flex="1" class="plain"
datasources="rdf:null" ref="NC:DownloadsRoot" flags="dont-test-empty"
enableColumnDrag="true"
onselect="this.treeBoxObject.view.selectionChanged(); onSelect(event);">
<treecols>
<treecol id="Name" primary="true"
label="&name.label;"
class="sortDirectionIndicator" width="3*" flex="3"
sort="http://home.netscape.com/NC-rdf#Name"
persist="width sortActive sortDirection"/>
<splitter class="tree-splitter"/>
<treecol id="StatusText"
label="&status.label;"
class="sortDirectionIndicator" width="1*" flex="1"
sort="http://home.netscape.com/NC-rdf#StatusText"
persist="width hidden sortActive sortDirection"/>
<!--
<splitter class="tree-splitter"/>
<treecol id="TimeRemaining"
label="&timeremaining.label;"
class="sortDirectionIndicator" width="1*" flex="1"
sort="http://home.netscape.com/NC-rdf#TimeRemaining"
persist="width hidden sortActive sortDirection"/>
-->
<splitter class="tree-splitter"/>
<treecol id="Transferred"
label="&transferred.label;"
class="sortDirectionIndicator" width="1*" flex="1"
sort="http://home.netscape.com/NC-rdf#Transferred"
persist="width hidden sortActive sortDirection"/>
<!--
<splitter class="tree-splitter"/>
<treecol id="TimeElapsed" hidden="true"
label="&timeelapsed.label;"
class="sortDirectionIndicator" width="1*" flex="1"
sort="http://home.netscape.com/NC-rdf#TimeElapsed"
persist="width hidden sortActive sortDirection"/>
-->
<splitter class="tree-splitter"/>
<treecol id="Source"
label="&source.label;"
class="sortDirectionIndicator" width="1*" flex="1"
sort="http://home.netscape.com/NC-rdf#URL"
persist="width hidden sortActive sortDirection"/>
</treecols>
<template>
<rule nc:DownloadState="1" parsetype="Integer">
<treechildren>
<treeitem uri="rdf:*">
<treerow>
<treecell src="moz-icon:rdf:http://home.netscape.com/NC-rdf#File"
label="rdf:http://home.netscape.com/NC-rdf#Name"/>
<treecell label="rdf:http://home.netscape.com/NC-rdf#StatusText"/>
<!-- <treecell label="rdf:http://home.netscape.com/NC-rdf#TimeRemaining"/> -->
<treecell label="rdf:http://home.netscape.com/NC-rdf#Transferred"/>
<!-- <treecell label="rdf:http://home.netscape.com/NC-rdf#TimeElapsed"/> -->
<treecell label="rdf:http://home.netscape.com/NC-rdf#URL"/>
</treerow>
</treeitem>
</treechildren>
</rule>
<rule nc:DownloadState="2" parsetype="Integer">
<treechildren>
<treeitem uri="rdf:*">
<treerow>
<treecell src="moz-icon:rdf:http://home.netscape.com/NC-rdf#File"
label="rdf:http://home.netscape.com/NC-rdf#Name"/>
<treecell label="rdf:http://home.netscape.com/NC-rdf#StatusText"/>
<!-- <treecell label="rdf:http://home.netscape.com/NC-rdf#TimeRemaining"/> -->
<treecell label="rdf:http://home.netscape.com/NC-rdf#Transferred"/>
<!-- <treecell label="rdf:http://home.netscape.com/NC-rdf#TimeElapsed"/> -->
<treecell label="rdf:http://home.netscape.com/NC-rdf#URL"/>
</treerow>
</treeitem>
</treechildren>
</rule>
<rule nc:DownloadState="3" parsetype="Integer">
<treechildren>
<treeitem uri="rdf:*">
<treerow>
<treecell src="moz-icon:rdf:http://home.netscape.com/NC-rdf#File"
label="rdf:http://home.netscape.com/NC-rdf#Name"/>
<treecell label="rdf:http://home.netscape.com/NC-rdf#StatusText"/>
<!-- <treecell label="rdf:http://home.netscape.com/NC-rdf#TimeRemaining"/> -->
<treecell label="rdf:http://home.netscape.com/NC-rdf#Transferred"/>
<!-- <treecell label="rdf:http://home.netscape.com/NC-rdf#TimeElapsed"/> -->
<treecell label="rdf:http://home.netscape.com/NC-rdf#URL"/>
</treerow>
</treeitem>
</treechildren>
</rule>
</template>
</tree>
</window>

View File

@@ -1,6 +1,4 @@
browser.jar:
content/browser/downloads/downloadmanager.xul (content/downloadmanager.xul)
content/browser/downloads/downloadmanager.js (content/downloadmanager.js)
content/browser/downloads/downloadPanel.js (content/downloadPanel.js)
content/browser/downloads/downloadPanel.xul (content/downloadPanel.xul)
content/browser/downloads/download-bindings.xml (content/download-bindings.xml)

View File

@@ -2,7 +2,7 @@
font-weight: bold;
}
page > #downloadView {
#downloadView {
background-color: white;
padding: 10px;
}
@@ -12,7 +12,7 @@ download {
min-height: 25px;
}
#downloadView > treechildren:-moz-tree-image(Name) {
#downloadHistoryView > treechildren:-moz-tree-image(Name) {
margin-right: 2px;
}

View File

@@ -70,7 +70,7 @@ static PRBool gQuitting = PR_FALSE;
#define DOWNLOAD_MANAGER_FE_URL "chrome://browser/content/downloadmanager/downloadmanager.xul"
#define DOWNLOAD_MANAGER_BUNDLE "chrome://browser/locale/downloadmanager/downloadmanager.properties"
#define INTERVAL 500
#define DOWNLOAD_ENDED_TIMEOUT 5000
#define DOWNLOAD_ENDED_TIMEOUT 10000
nsIRDFResource* gNC_DownloadsRoot;
nsIRDFResource* gNC_File;