Bug 780200 - FillAttachmentListPopup() should be decoupled from attachmentMenuList. r=squib.
This commit is contained in:
Родитель
9008949d0a
Коммит
68a9750196
|
@ -28,7 +28,6 @@ var gViewAllHeaders = false;
|
|||
var gMinNumberOfHeaders = 0;
|
||||
var gDummyHeaderIdIndex = 0;
|
||||
var gBuildAttachmentsForCurrentMsg = false;
|
||||
var gBuildAttachmentPopupForCurrentMsg = true;
|
||||
var gBuiltExpandedView = false;
|
||||
var gHeadersShowReferences = false;
|
||||
|
||||
|
@ -274,6 +273,8 @@ function OnLoadMsgHeaderPane()
|
|||
"CustomizeAttachmentToolbar", function () {
|
||||
updateSaveAllAttachmentsButton();
|
||||
});
|
||||
|
||||
top.controllers.appendController(AttachmentMenuController);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,7 +432,6 @@ var messageHeaderSink = {
|
|||
ClearCurrentHeaders();
|
||||
gBuiltExpandedView = false;
|
||||
gBuildAttachmentsForCurrentMsg = false;
|
||||
gBuildAttachmentPopupForCurrentMsg = true;
|
||||
ClearAttachmentList();
|
||||
ClearEditMessageBox();
|
||||
gMessageNotificationBar.clearMsgNotifications();
|
||||
|
@ -1975,31 +1975,6 @@ function onHideAttachmentItemContextMenu()
|
|||
attachmentName.removeAttribute("selected");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the attachment list context menu, showing or hiding the appropriate
|
||||
* menu items.
|
||||
*/
|
||||
function onShowAttachmentListContextMenu()
|
||||
{
|
||||
var openAllMenu = document.getElementById("context-openAllAttachments");
|
||||
var saveAllMenu = document.getElementById("context-saveAllAttachments");
|
||||
var detachAllMenu = document.getElementById("context-detachAllAttachments");
|
||||
var deleteAllMenu = document.getElementById("context-deleteAllAttachments");
|
||||
|
||||
var allDetached = currentAttachments.every(function(attachment) {
|
||||
return attachment.isExternalAttachment;
|
||||
});
|
||||
var allDeleted = currentAttachments.every(function(attachment) {
|
||||
return !attachment.hasFile;
|
||||
});
|
||||
var canDetachAll = CanDetachAttachments() && !allDetached && !allDeleted;
|
||||
|
||||
saveAllMenu.disabled = allDeleted;
|
||||
openAllMenu.disabled = allDeleted;
|
||||
detachAllMenu.disabled = !canDetachAll;
|
||||
deleteAllMenu.disabled = !canDetachAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable menu items as appropriate for the single-attachment save all
|
||||
* toolbar button.
|
||||
|
@ -2121,6 +2096,95 @@ var AttachmentListController =
|
|||
{}
|
||||
};
|
||||
|
||||
let AttachmentMenuController = {
|
||||
commands: {
|
||||
cmd_openAllAttachments: {
|
||||
isEnabled: function() {
|
||||
return AttachmentMenuController._someFilesAvailable();
|
||||
},
|
||||
|
||||
doCommand: function() {
|
||||
HandleAllAttachments("open");
|
||||
},
|
||||
},
|
||||
|
||||
cmd_saveAllAttachments: {
|
||||
isEnabled: function() {
|
||||
return AttachmentMenuController._someFilesAvailable();
|
||||
},
|
||||
|
||||
doCommand: function() {
|
||||
HandleAllAttachments("save");
|
||||
},
|
||||
},
|
||||
|
||||
cmd_detachAllAttachments: {
|
||||
isEnabled: function() {
|
||||
return AttachmentMenuController._canDetachFiles();
|
||||
},
|
||||
|
||||
doCommand: function() {
|
||||
HandleAllAttachments("detach");
|
||||
},
|
||||
},
|
||||
|
||||
cmd_deleteAllAttachments: {
|
||||
isEnabled: function() {
|
||||
return AttachmentMenuController._canDetachFiles();
|
||||
},
|
||||
|
||||
doCommand: function() {
|
||||
HandleAllAttachments("delete");
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
_canDetachFiles: function() {
|
||||
let someNotDetached = currentAttachments.some(function(aAttachment) {
|
||||
return !aAttachment.isExternalAttachment;
|
||||
});
|
||||
|
||||
return CanDetachAttachments() &&
|
||||
someNotDetached &&
|
||||
this._someFilesAvailable();
|
||||
},
|
||||
|
||||
_someFilesAvailable: function() {
|
||||
return currentAttachments.some(function(aAttachment) {
|
||||
return aAttachment.hasFile;
|
||||
});
|
||||
},
|
||||
|
||||
supportsCommand: function(aCommand) {
|
||||
return (aCommand in this.commands);
|
||||
},
|
||||
|
||||
isCommandEnabled: function(aCommand) {
|
||||
if (!this.supportsCommand(aCommand))
|
||||
return false;
|
||||
|
||||
return this.commands[aCommand].isEnabled();
|
||||
},
|
||||
|
||||
doCommand: function(aCommand) {
|
||||
if (!this.supportsCommand(aCommand))
|
||||
return;
|
||||
let cmd = this.commands[aCommand];
|
||||
if (!cmd.isEnabled())
|
||||
return;
|
||||
cmd.doCommand();
|
||||
},
|
||||
|
||||
onEvent: function(aEvent) {}
|
||||
};
|
||||
|
||||
function goUpdateAttachmentCommands() {
|
||||
goUpdateCommand('cmd_openAllAttachments');
|
||||
goUpdateCommand('cmd_saveAllAttachments');
|
||||
goUpdateCommand('cmd_detachAllAttachments');
|
||||
goUpdateCommand('cmd_deleteAllAttachments');
|
||||
}
|
||||
|
||||
function displayAttachmentsForExpandedView()
|
||||
{
|
||||
var bundle = document.getElementById("bundle_messenger");
|
||||
|
@ -2305,39 +2369,15 @@ function getIconForAttachment(attachment)
|
|||
/**
|
||||
* Public method called when we create the attachments file menu
|
||||
*/
|
||||
function FillAttachmentListPopup(popup)
|
||||
function FillAttachmentListPopup(aEvent, aPopup)
|
||||
{
|
||||
// The FE sometimes call this routine TWICE...I haven't been able to figure
|
||||
// out why yet... Protect against it...
|
||||
if (!gBuildAttachmentPopupForCurrentMsg)
|
||||
return;
|
||||
|
||||
// otherwise we need to build the attachment view...
|
||||
// First clear out the old view...
|
||||
ClearAttachmentMenu(popup);
|
||||
ClearAttachmentMenu(aPopup);
|
||||
|
||||
for each (let [attachmentIndex, attachment] in Iterator(currentAttachments))
|
||||
addAttachmentToPopup(popup, attachment, attachmentIndex);
|
||||
addAttachmentToPopup(aPopup, attachment, attachmentIndex);
|
||||
|
||||
gBuildAttachmentPopupForCurrentMsg = false;
|
||||
|
||||
var allDetached = currentAttachments.every(function(attachment) {
|
||||
return attachment.isExternalAttachment;
|
||||
});
|
||||
var allDeleted = currentAttachments.every(function(attachment) {
|
||||
return !attachment.hasFile;
|
||||
});
|
||||
var canDetachAll = CanDetachAttachments() && !allDetached && !allDeleted;
|
||||
|
||||
var openAllMenu = document.getElementById("file-openAllAttachments");
|
||||
var saveAllMenu = document.getElementById("file-saveAllAttachments");
|
||||
var detachAllMenu = document.getElementById("file-detachAllAttachments");
|
||||
var deleteAllMenu = document.getElementById("file-deleteAllAttachments");
|
||||
|
||||
saveAllMenu.disabled = allDeleted;
|
||||
openAllMenu.disabled = allDeleted;
|
||||
detachAllMenu.disabled = !canDetachAll;
|
||||
deleteAllMenu.disabled = !canDetachAll;
|
||||
goUpdateAttachmentCommands();
|
||||
}
|
||||
|
||||
// Public method used to clear the file attachment menu
|
||||
|
@ -2392,6 +2432,9 @@ function addAttachmentToPopup(popup, attachment, attachmentIndex)
|
|||
// saving, deleting, detaching, etc.
|
||||
var openpopup = document.createElement("menupopup");
|
||||
openpopup = item.appendChild(openpopup);
|
||||
openpopup.addEventListener("popupshowing", function(aEvent) {
|
||||
aEvent.stopPropagation();
|
||||
});
|
||||
|
||||
// Due to Bug #314228, we must append our menupopup to the new attachment
|
||||
// menu item before we inserting the attachment menu into the popup. If we
|
||||
|
|
|
@ -22,6 +22,23 @@
|
|||
<stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
|
||||
</stringbundleset>
|
||||
|
||||
<commandset id="mailCommands">
|
||||
<commandset id="attachmentCommands">
|
||||
<command id="cmd_openAllAttachments"
|
||||
oncommand="goDoCommand('cmd_openAllAttachments');"
|
||||
disabled="true"/>
|
||||
<command id="cmd_saveAllAttachments"
|
||||
oncommand="goDoCommand('cmd_saveAllAttachments');"
|
||||
disabled="true"/>
|
||||
<command id="cmd_detachAllAttachments"
|
||||
oncommand="goDoCommand('cmd_detachAllAttachments');"
|
||||
disabled="true"/>
|
||||
<command id="cmd_deleteAllAttachments"
|
||||
oncommand="goDoCommand('cmd_deleteAllAttachments');"
|
||||
disabled="true"/>
|
||||
</commandset>
|
||||
</commandset>
|
||||
|
||||
<menupopup id="messageIdContext" popupanchor="bottomleft"
|
||||
onpopupshowing="FillMessageIdContextMenu(document.popupNode);">
|
||||
<menuitem id="messageIdContext-messageIdTarget"
|
||||
|
@ -66,45 +83,56 @@
|
|||
oncommand="HandleMultipleAttachments(this.parentNode.attachments, 'delete');"/>
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="attachmentListContext"
|
||||
onpopupshowing="return onShowAttachmentListContextMenu(event);">
|
||||
<menupopup id="attachmentListContext" onpopupshowing="goUpdateAttachmentCommands();">
|
||||
<menuitem id="context-openAllAttachments"
|
||||
label="&openAllAttachmentsCmd.label;"
|
||||
accesskey="&openAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('open');"/>
|
||||
command="cmd_openAllAttachments"/>
|
||||
<menuitem id="context-saveAllAttachments"
|
||||
label="&saveAllAttachmentsCmd.label;"
|
||||
accesskey="&saveAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('save');"/>
|
||||
command="cmd_saveAllAttachments"/>
|
||||
<menuseparator id="context-menu-separator-all"/>
|
||||
<menuitem id="context-detachAllAttachments"
|
||||
label="&detachAllAttachmentsCmd.label;"
|
||||
accesskey="&detachAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('detach');"/>
|
||||
command="cmd_detachAllAttachments"/>
|
||||
<menuitem id="context-deleteAllAttachments"
|
||||
label="&deleteAllAttachmentsCmd.label;"
|
||||
accesskey="&deleteAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('delete');"/>
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="attachmentMenuList">
|
||||
command="cmd_deleteAllAttachments"/>
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="attachmentMenuList" onpopupshowing="FillAttachmentListPopup(event, this);">
|
||||
<menuseparator/>
|
||||
<menuitem id="file-openAllAttachments"
|
||||
label="&openAllAttachmentsCmd.label;"
|
||||
<menuitem label="&openAllAttachmentsCmd.label;"
|
||||
accesskey="&openAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('open');" />
|
||||
<menuitem id="file-saveAllAttachments"
|
||||
label="&saveAllAttachmentsCmd.label;"
|
||||
command="cmd_openAllAttachments" />
|
||||
<menuitem label="&saveAllAttachmentsCmd.label;"
|
||||
accesskey="&saveAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('save');"/>
|
||||
<menuitem id="file-detachAllAttachments"
|
||||
label="&detachAllAttachmentsCmd.label;"
|
||||
command="cmd_saveAllAttachments"/>
|
||||
<menuitem label="&detachAllAttachmentsCmd.label;"
|
||||
accesskey="&detachAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('detach');" />
|
||||
<menuitem id="file-deleteAllAttachments"
|
||||
label="&deleteAllAttachmentsCmd.label;"
|
||||
command="cmd_detachAllAttachments" />
|
||||
<menuitem label="&deleteAllAttachmentsCmd.label;"
|
||||
accesskey="&deleteAllAttachmentsCmd.accesskey;"
|
||||
oncommand="HandleAllAttachments('delete');" />
|
||||
command="cmd_deleteAllAttachments" />
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="appmenu_attachmentMenuList" onpopupshowing="FillAttachmentListPopup(event, this);">
|
||||
<menuseparator/>
|
||||
<menuitem label="&openAllAttachmentsCmd.label;"
|
||||
accesskey="&openAllAttachmentsCmd.accesskey;"
|
||||
command="cmd_openAllAttachments" />
|
||||
<menuitem label="&saveAllAttachmentsCmd.label;"
|
||||
accesskey="&saveAllAttachmentsCmd.accesskey;"
|
||||
command="cmd_saveAllAttachments"/>
|
||||
<menuitem label="&detachAllAttachmentsCmd.label;"
|
||||
accesskey="&detachAllAttachmentsCmd.accesskey;"
|
||||
command="cmd_detachAllAttachments" />
|
||||
<menuitem label="&deleteAllAttachmentsCmd.label;"
|
||||
accesskey="&deleteAllAttachmentsCmd.accesskey;"
|
||||
command="cmd_deleteAllAttachments" />
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="header-toolbar-context-menu">
|
||||
|
|
Загрузка…
Ссылка в новой задаче