Bug 392293 - The disabled state of the mini-buttons in DM is not handled correctly. r=Mardak, r=Mano

This commit is contained in:
sdwilsh%shawnwilsher.com 2008-01-07 00:14:00 +00:00
Родитель 4f7f102106
Коммит 6bf632e764
4 изменённых файлов: 111 добавлений и 94 удалений

Просмотреть файл

@ -91,8 +91,7 @@ DownloadProgressListener.prototype = {
// Update ui text values after switching states
updateTime(dl);
updateStatus(dl);
gDownloadViewController.onCommandUpdate();
updateButtons(dl);
} catch (e) { }
},

Просмотреть файл

@ -96,6 +96,14 @@
]]>
</getter>
</property>
<property name="buttons">
<getter>
<![CDATA[
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
return this.getElementsByTagNameNS(XULNS, "button");
]]>
</getter>
</property>
</implementation>
</binding>
@ -116,7 +124,8 @@
</xul:vbox>
<xul:vbox pack="center">
<xul:button class="cancel mini-button" tooltiptext="&cmd.cancel.label;"
command="cmd_cancel" ondblclick="event.stopPropagation();"/>
cmd="cmd_cancel" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_cancel', this);"/>
</xul:vbox>
</xul:hbox>
</content>
@ -139,9 +148,11 @@
xbl:inherits="value=progress,mode=progressmode"/>
</xul:vbox>
<xul:button class="pause mini-button" tooltiptext="&cmd.pause.label;"
command="cmd_pause" ondblclick="event.stopPropagation();"/>
cmd="cmd_pause" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_pause', this);"/>
<xul:button class="cancel mini-button" tooltiptext="&cmd.cancel.label;"
command="cmd_cancel" ondblclick="event.stopPropagation();"/>
cmd="cmd_cancel" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_cancel', this);"/>
</xul:hbox>
<xul:label xbl:inherits="value=status,tooltiptext=statusTip" flex="1"
crop="right" class="status"/>
@ -168,9 +179,11 @@
xbl:inherits="value=progress,mode=progressmode"/>
</xul:vbox>
<xul:button class="resume mini-button" tooltiptext="&cmd.resume.label;"
command="cmd_resume" ondblclick="event.stopPropagation();"/>
cmd="cmd_resume" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_resume', this);"/>
<xul:button class="cancel mini-button" tooltiptext="&cmd.cancel.label;"
command="cmd_cancel" ondblclick="event.stopPropagation();"/>
cmd="cmd_cancel" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_cancel', this);"/>
</xul:hbox>
<xul:label xbl:inherits="value=status,tooltiptext=statusTip" flex="1"
crop="right" class="status"/>
@ -221,7 +234,8 @@
<xul:label xbl:inherits="value=status,tooltiptext=statusTip"
crop="end" flex="1" class="status"/>
<xul:button class="retry mini-button" tooltiptext="&cmd.retry.label;"
command="cmd_retry" ondblclick="event.stopPropagation();"/>
cmd="cmd_retry" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_retry', this);"/>
</xul:hbox>
</xul:vbox>
</xul:hbox>
@ -246,7 +260,8 @@
<xul:label xbl:inherits="value=status,tooltiptext=statusTip"
crop="end" flex="1" class="status"/>
<xul:button class="retry mini-button" tooltiptext="&cmd.retry.label;"
command="cmd_retry" ondblclick="event.stopPropagation();"/>
cmd="cmd_retry" ondblclick="event.stopPropagation();"
oncommand="performCommand('cmd_retry', this);"/>
</xul:hbox>
</xul:vbox>
</xul:hbox>

Просмотреть файл

@ -122,14 +122,6 @@ var gStmt = gDownloadManager.DBConnection.createStatement(
////////////////////////////////////////////////////////////////////////////////
//// Utility Functions
function fireEventForElement(aElement, aEventType)
{
var e = document.createEvent("Events");
e.initEvent("download-" + aEventType, true, true);
aElement.dispatchEvent(e);
}
function getDownload(aID)
{
return document.getElementById("dl" + aID);
@ -341,8 +333,7 @@ function copySourceLocation(aDownload)
clipboard.copyString(uri);
}
// This is called by the progress listener. We don't actually use the event
// system here to minimize time wastage.
// This is called by the progress listener.
var gLastComputedMean = -1;
var gLastActiveDownloads = 0;
function onUpdateProgress()
@ -557,13 +548,20 @@ function buildContextMenu(aEvent)
popup.removeChild(popup.firstChild);
if (gDownloadsView.selectedItem) {
var idx = parseInt(gDownloadsView.selectedItem.getAttribute("state"));
let dl = gDownloadsView.selectedItem;
let idx = parseInt(dl.getAttribute("state"));
if (idx < 0)
idx = 0;
var menus = gContextMenus[idx];
for (var i = 0; i < menus.length; ++i)
popup.appendChild(document.getElementById(menus[i]).cloneNode(true));
for (let i = 0; i < menus.length; ++i) {
let menuitem = document.getElementById(menus[i]).cloneNode(true);
let cmd = menuitem.getAttribute("cmd");
if (cmd)
menuitem.disabled = !gDownloadViewController.isCommandEnabled(cmd, dl);
popup.appendChild(menuitem);
}
return true;
}
@ -606,27 +604,15 @@ var gDownloadDNDObserver =
//// Command Updating and Command Handlers
var gDownloadViewController = {
supportsCommand: function(aCommand)
isCommandEnabled: function(aCommand, aItem)
{
var commandNode = document.getElementById(aCommand);
return commandNode && commandNode.parentNode ==
document.getElementById("downloadsCommands");
},
isCommandEnabled: function(aCommand)
{
if (!window.gDownloadsView)
return false;
// This switch statement is for commands that do not need a download object
switch (aCommand) {
case "cmd_clearList":
return gDownloadManager.canCleanUp;
}
var dl = gDownloadsView.selectedItem;
if (!dl)
return false;
let dl = aItem;
switch (aCommand) {
case "cmd_cancel":
@ -652,25 +638,10 @@ var gDownloadViewController = {
return false;
},
doCommand: function(aCommand)
doCommand: function(aCommand, aItem)
{
if (this.isCommandEnabled(aCommand))
this.commands[aCommand](gDownloadsView.selectedItem);
},
onCommandUpdate: function ()
{
var downloadsCommands = document.getElementById("downloadsCommands");
for (var i = 0; i < downloadsCommands.childNodes.length; ++i)
this.updateCommand(downloadsCommands.childNodes[i]);
},
updateCommand: function (command)
{
if (this.isCommandEnabled(command.id))
command.removeAttribute("disabled");
else
command.setAttribute("disabled", "true");
if (this.isCommandEnabled(aCommand, aItem))
this.commands[aCommand](aItem);
},
commands: {
@ -713,6 +684,32 @@ var gDownloadViewController = {
}
};
/**
* Helper function to do commands.
*
* @param aCmd
* The command to be performed.
* @param aItem
* The richlistitem that represents the download that will have the
* command performed on it. If this is null, it assumes the currently
* selected item. If the item passed in is not a richlistitem that
* represents a download, it will walk up the parent nodes until it finds
* a DOM node that is.
*/
function performCommand(aCmd, aItem)
{
let elm = aItem;
if (!elm) {
elm = gDownloadsView.selectedItem;
} else {
while (elm.nodeName != "richlistitem" ||
elm.getAttribute("type") != "download")
elm = elm.parentNode;
}
gDownloadViewController.doCommand(aCmd, elm);
}
function setSearchboxFocus()
{
gSearchBox.focus();
@ -773,6 +770,23 @@ function createDownloadItem(aAttrs)
return null;
}
/**
* Updates the disabled state of the buttons of a downlaod.
*
* @param aItem
* The richlistitem representing the download.
*/
function updateButtons(aItem)
{
let buttons = aItem.buttons;
for (let i = 0; i < buttons.length; ++i) {
let cmd = buttons[i].getAttribute("cmd");
let enabled = gDownloadViewController.isCommandEnabled(cmd, aItem);
buttons[i].disabled = !enabled;
}
}
/**
* Updates the status for a download item depending on its state
*
@ -1070,7 +1084,7 @@ function doDefaultForSelected()
var menuitem = document.getElementById(gContextMenus[state][0]);
// Try to do the action if the command is enabled
gDownloadViewController.doCommand(menuitem.command);
gDownloadViewController.doCommand(menuitem.getAttribute("cmd"), item);
}
function removeFromView(aDownload)
@ -1183,6 +1197,10 @@ function stepListBuilder(aNumItems) {
// Add item to the end and color just that one item
gDownloadsView.appendChild(item);
stripeifyList(item);
// Because of the joys of XBL, we can't update the buttons until the
// download object is in the document.
updateButtons(item);
}
} catch (e) {
// Something went wrong when stepping or getting values, so clear and quit
@ -1228,6 +1246,10 @@ function prependList(aDownload)
// Add item to the beginning and color the whole list
gDownloadsView.insertBefore(item, gDownloadsView.firstChild);
stripeifyList(item);
// Because of the joys of XBL, we can't update the buttons until the
// download object is in the document.
updateButtons(item);
}
}

Просмотреть файл

@ -76,35 +76,6 @@
<stringbundle id="downloadStrings" src="chrome://mozapps/locale/downloads/downloads.properties"/>
</stringbundleset>
<commandset id="downloadsCommands"
commandupdater="true"
oncommandupdate="gDownloadViewController.onCommandUpdate();">
<command id="cmd_cancel"
oncommand="gDownloadViewController.doCommand('cmd_cancel');"/>
<command id="cmd_open"
oncommand="gDownloadViewController.doCommand('cmd_open');"/>
<command id="cmd_openReferrer"
oncommand="gDownloadViewController.doCommand('cmd_openReferrer');"/>
<command id="cmd_pause"
oncommand="gDownloadViewController.doCommand('cmd_pause');"/>
<command id="cmd_pauseResume"
oncommand="gDownloadViewController.doCommand('cmd_pauseResume');"/>
<command id="cmd_removeFromList"
oncommand="gDownloadViewController.doCommand('cmd_removeFromList');"/>
<command id="cmd_resume"
oncommand="gDownloadViewController.doCommand('cmd_resume');"/>
<command id="cmd_retry"
oncommand="gDownloadViewController.doCommand('cmd_retry');"/>
<command id="cmd_show"
oncommand="gDownloadViewController.doCommand('cmd_show');"/>
<command id="cmd_showInfo"
oncommand="gDownloadViewController.doCommand('cmd_showInfo');"/>
<command id="cmd_copyLocation"
oncommand="gDownloadViewController.doCommand('cmd_copyLocation');"/>
<command id="cmd_clearList"
oncommand="gDownloadViewController.doCommand('cmd_clearList');"/>
</commandset>
<!-- Use this commandset for command which do not depened on focus or selection -->
<commandset id="generalCommands">
<command id="cmd_findDownload" oncommand="setSearchboxFocus();"/>
@ -135,17 +106,21 @@
<vbox id="contextMenuPalette" hidden="true">
<menuitem id="menuitem_pause"
label="&cmd.pause.label;" accesskey="&cmd.pause.accesskey;"
command="cmd_pause"/>
oncommand="performCommand('cmd_pause');"
cmd="cmd_pause"/>
<menuitem id="menuitem_resume"
label="&cmd.resume.label;" accesskey="&cmd.resume.accesskey;"
command="cmd_resume"/>
oncommand="performCommand('cmd_resume');"
cmd="cmd_resume"/>
<menuitem id="menuitem_cancel"
label="&cmd.cancel.label;" accesskey="&cmd.cancel.accesskey;"
command="cmd_cancel"/>
oncommand="performCommand('cmd_cancel');"
cmd="cmd_cancel"/>
<menuitem id="menuitem_open" default="true"
label="&cmd.open.label;" accesskey="&cmd.open.accesskey;"
command="cmd_open"/>
oncommand="performCommand('cmd_open');"
cmd="cmd_open"/>
<menuitem id="menuitem_show"
#ifdef XP_MACOSX
label="&cmd.show.labelMac;"
@ -154,32 +129,38 @@
label="&cmd.show.label;"
accesskey="&cmd.show.accesskey;"
#endif
command="cmd_show"/>
oncommand="performCommand('cmd_show');"
cmd="cmd_show"/>
<menuitem id="menuitem_retry" default="true"
label="&cmd.retry.label;" accesskey="&cmd.retry.accesskey;"
command="cmd_retry"/>
oncommand="performCommand('cmd_retry');"
cmd="cmd_retry"/>
<menuitem id="menuitem_removeFromList"
label="&cmd.removeFromList.label;" accesskey="&cmd.removeFromList.accesskey;"
command="cmd_removeFromList"/>
oncommand="performCommand('cmd_removeFromList');"
cmd="cmd_removeFromList"/>
<menuseparator id="menuseparator"/>
<menuitem id="menuitem_openReferrer"
label="&cmd.goToDownloadPage.label;"
accesskey="&cmd.goToDownloadPage.accesskey;"
command="cmd_openReferrer"/>
oncommand="performCommand('cmd_openReferrer');"
cmd="cmd_openReferrer"/>
<menuitem id="menuitem_copyLocation"
label="&cmd.copyDownloadLink.label;"
accesskey="&cmd.copyDownloadLink.accesskey;"
command="cmd_copyLocation"/>
oncommand="performCommand('cmd_copyLocation');"
cmd="cmd_copyLocation"/>
<menuitem id="menuitem_clearList"
label="&cmd.clearList.label;"
accesskey="&cmd.clearList.accesskey;"
command="cmd_clearList"/>
oncommand="performCommand('cmd_clearList');"
cmd="cmd_clearList"/>
</vbox>
<menupopup id="downloadContextMenu" onpopupshowing="return buildContextMenu(event);"/>