# HG changeset patch # User Ian Neal # Date 1647194368 0 # Parent b76049f9547e13821d09c25f0b0e8dde651fac69 Bug 1256716 - [SM] Implement 'Edit Draft' command and hide it when not in a draft folder (port Thunderbird bug 1106412). r=frg a=frg Port relevant parts of: * Bug 956481 - Remove ellipsis from some Message menuitems. * Bug 957974 - Change "Message > Edit Message As New" to "Edit As New Message". * Bug 1106412 - Menu items for "Edit draft" functionality missing after bug 321355 fixes "Edit as New Message" to do just that * Bug 1297674 - Menu item 'Copy' is inactive when viewing .eml attachment * Bug 731688 - Introduce compose type EditAsNew. * Bug 731688 - Support conversion from HTML to plain text and vice versa in 'Edit as New Message', 'Edit Draft' and 'New Message from Template'. diff --git a/suite/locales/en-US/chrome/mailnews/messenger.dtd b/suite/locales/en-US/chrome/mailnews/messenger.dtd --- a/suite/locales/en-US/chrome/mailnews/messenger.dtd +++ b/suite/locales/en-US/chrome/mailnews/messenger.dtd @@ -308,19 +308,21 @@ - - - + + + + + @@ -463,18 +465,19 @@ - - + + + diff --git a/suite/mailnews/components/compose/content/MsgComposeCommands.js b/suite/mailnews/components/compose/content/MsgComposeCommands.js --- a/suite/mailnews/components/compose/content/MsgComposeCommands.js +++ b/suite/mailnews/components/compose/content/MsgComposeCommands.js @@ -197,16 +197,26 @@ var stateListener = { case Ci.nsIMsgCompType.ReplyWithTemplate: case Ci.nsIMsgCompType.ReplyToList: this.NotifyComposeBodyReadyReply(); break; case Ci.nsIMsgCompType.ForwardInline: this.NotifyComposeBodyReadyForwardInline(); break; + + case Ci.nsIMsgCompType.Draft: + case Ci.nsIMsgCompType.Template: + case Ci.nsIMsgCompType.Redirect: + case Ci.nsIMsgCompType.EditAsNew: + break; + + default: + dump("Unexpected nsIMsgCompType in NotifyComposeBodyReady (" + + gComposeType + ")\n"); } // Set the selected item in the identity list as needed, which will cause // an identity/signature switch. This can only be done once the message // body has already been assembled with the signature we need to switch. if (gMsgCompose.identity != gCurrentIdentity) { // Since switching the signature loses the caret position, we record it // and restore it later. diff --git a/suite/mailnews/content/mail3PaneWindowCommands.js b/suite/mailnews/content/mail3PaneWindowCommands.js --- a/suite/mailnews/content/mail3PaneWindowCommands.js +++ b/suite/mailnews/content/mail3PaneWindowCommands.js @@ -123,16 +123,17 @@ var DefaultController = case "button_replyall": case "cmd_replySenderAndGroup": case "cmd_replyAllRecipients": case "cmd_forward": case "button_forward": case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_editDraftMsg": case "cmd_createFilterFromMenu": case "cmd_delete": case "cmd_shiftDelete": case "button_delete": case "button_shiftDelete": case "button_junk": case "cmd_nextMsg": case "button_next": @@ -279,16 +280,17 @@ var DefaultController = case "button_replyall": case "cmd_replySenderAndGroup": case "cmd_replyAllRecipients": case "cmd_forward": case "button_forward": case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_editDraftMsg": case "cmd_openMessage": case "button_print": case "cmd_print": case "cmd_viewPageSource": case "cmd_reload": case "cmd_applyFiltersToSelection": if (command == "cmd_applyFiltersToSelection") { @@ -518,17 +520,20 @@ var DefaultController = break; case "cmd_forwardInline": MsgForwardAsInline(null); break; case "cmd_forwardAttachment": MsgForwardAsAttachment(null); break; case "cmd_editAsNew": - MsgEditMessageAsNew(); + MsgEditMessageAsNew(null); + break; + case "cmd_editDraftMsg": + MsgEditDraftMessage(null); break; case "cmd_createFilterFromMenu": MsgCreateFilter(); break; case "cmd_createFilterFromPopup": CreateFilter(document.popupNode); break; case "cmd_delete": diff --git a/suite/mailnews/content/mailCommands.js b/suite/mailnews/content/mailCommands.js --- a/suite/mailnews/content/mailCommands.js +++ b/suite/mailnews/content/mailCommands.js @@ -77,17 +77,18 @@ function GetIdentityForHeader(aMsgHdr, a } } return ""; } let hintForIdentity = ""; if (aType == Ci.nsIMsgCompType.ReplyToList) hintForIdentity = findDeliveredToIdentityEmail(); - else if (aType == Ci.nsIMsgCompType.Template) + else if (aType == Ci.nsIMsgCompType.Template || + aType == Ci.nsIMsgCompType.EditAsNew) hintForIdentity = aMsgHdr.author; else hintForIdentity = aMsgHdr.recipients + "," + aMsgHdr.ccList + "," + findDeliveredToIdentityEmail(); let server = null; let identity = null; let folder = aMsgHdr.folder; diff --git a/suite/mailnews/content/mailContextMenus.js b/suite/mailnews/content/mailContextMenus.js --- a/suite/mailnews/content/mailContextMenus.js +++ b/suite/mailnews/content/mailContextMenus.js @@ -141,16 +141,22 @@ function FillMailContextMenu(aTarget, aE ShowMenuItem("mailContext-openNewWindow", inThreadPane && single); ShowMenuItem("mailContext-openNewTab", inThreadPane && single); ShowMenuItem("mailContext-downloadflagged", inThreadPane || (numSelected > 1)); ShowMenuItem("mailContext-downloadselected", inThreadPane || (numSelected > 1)); ShowMenuItem("mailContext-editAsNew", showMailItems && oneOrMore); + // Show "Edit Draft Message" menus only in a drafts folder; + // otherwise hide them. + let showEditDraft = showCommandInSpecialFolder("cmd_editDraftMsg", + Ci.nsMsgFolderFlags.Drafts); + ShowMenuItem("mailContext-editDraftMsg", + showMailItems && oneOrMore && showEditDraft); ShowMenuItem("mailContext-replySender", showMailItems && single); ShowMenuItem("mailContext-replyList", showMailItems && single && !isNewsgroup && IsListPost()); ShowMenuItem("mailContext-replyNewsgroup", showMailItems && single && isNewsgroup); ShowMenuItem("mailContext-replySenderAndNewsgroup", showMailItems && single && isNewsgroup); ShowMenuItem("mailContext-replyAll", showMailItems && single); diff --git a/suite/mailnews/content/mailWindowOverlay.js b/suite/mailnews/content/mailWindowOverlay.js --- a/suite/mailnews/content/mailWindowOverlay.js +++ b/suite/mailnews/content/mailWindowOverlay.js @@ -310,16 +310,20 @@ function InitMessageMenu() { var canCopy = selectedMsg && (!gMessageDisplay.isDummy || window.arguments[0].scheme == "file"); document.getElementById("copyMenu").disabled = !canCopy; // Disable the Forward as/Tag menu items if no message is selected. document.getElementById("forwardAsMenu").disabled = !selectedMsg; document.getElementById("tagMenu").disabled = !selectedMsg; + // Show "Edit Draft Message" menus only in a drafts folder; + // otherwise hide them. + showCommandInSpecialFolder("cmd_editDraftMsg", Ci.nsMsgFolderFlags.Drafts); + // Initialize the Open Message menuitem var winType = document.documentElement.getAttribute("windowtype"); if (winType == "mail:3pane") document.getElementById("openMessageWindowMenuitem").hidden = isFeed; // Initialize the Open Feed Message handler menu let index = FeedMessageHandler.onOpenPref; document.getElementById("menu_openFeedMessage") @@ -331,16 +335,36 @@ function InitMessageMenu() { openRssMenu.hidden = true; // Disable the Mark menu when we're not in a folder. document.getElementById("markMenu").disabled = !msgFolder; document.commandDispatcher.updateCommands("create-menu-message"); } +/** + * Show folder-specific menu items only for messages in special folders, e.g. + * show 'cmd_editDraftMsg' in Drafts folder. + * + * aCommandId the ID of a command to be shown in folders having aFolderFlag + * aFolderFlag the nsMsgFolderFlag that the folder must have to show the + * command + */ +function showCommandInSpecialFolder(aCommandId, aFolderFlag) { + let msg = gFolderDisplay.selectedMessage; + let folder = gFolderDisplay.displayedFolder; + // Check msg.folder exists as messages opened from a file have none. + let inSpecialFolder = (msg && + msg.folder && + msg.folder.isSpecialFolder(aFolderFlag, true)) || + (folder && folder.getFlag(aFolderFlag)); + document.getElementById(aCommandId).setAttribute("hidden", !inSpecialFolder); + return inSpecialFolder; +} + function InitViewHeadersMenu() { var headerchoice = Services.prefs.getIntPref("mail.show_headers", Ci.nsMimeHeaderDisplayTypes.NormalHeaders); document .getElementById("cmd_viewAllHeader") .setAttribute("checked", headerchoice == Ci.nsMimeHeaderDisplayTypes.AllHeaders); @@ -1228,18 +1252,22 @@ function MsgForwardMessage(event) { function MsgForwardAsAttachment(event) { ComposeMsgByType(msgComposeType.ForwardAsAttachment, event); } function MsgForwardAsInline(event) { ComposeMsgByType(msgComposeType.ForwardInline, event); } -function MsgEditMessageAsNew() { - ComposeMsgByType(msgComposeType.Template); +function MsgEditMessageAsNew(aEvent) { + ComposeMsgByType(msgComposeType.EditAsNew, aEvent); +} + +function MsgEditDraftMessage(aEvent) { + ComposeMsgByType(msgComposeType.Draft, aEvent); } function MsgComposeDraftMessage() { ComposeMsgByType(msgComposeType.Draft, null, msgComposeFormat.Default); } function MsgCreateFilter() { // retrieve Sender direct from selected message's headers diff --git a/suite/mailnews/content/mailWindowOverlay.xul b/suite/mailnews/content/mailWindowOverlay.xul --- a/suite/mailnews/content/mailWindowOverlay.xul +++ b/suite/mailnews/content/mailWindowOverlay.xul @@ -228,17 +228,18 @@ - + + @@ -358,17 +359,20 @@ - + + label="&contextEditMsgAsNew.label;" + accesskey="&contextEditMsgAsNew.accesskey;" + oncommand="MsgEditMessageAsNew(event);"/> + @@ -1347,20 +1355,24 @@ command="cmd_forwardInline"/> + diff --git a/suite/mailnews/content/messageWindow.js b/suite/mailnews/content/messageWindow.js --- a/suite/mailnews/content/messageWindow.js +++ b/suite/mailnews/content/messageWindow.js @@ -595,16 +595,17 @@ var MessageWindowController = case "cmd_replySenderAndGroup": case "cmd_replyAllRecipients": case "button_replyall": case "cmd_forward": case "button_forward": case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_editDraftMsg": case "cmd_getNextNMessages": case "cmd_find": case "cmd_findNext": case "cmd_findPrev": case "button_search": case "cmd_search": case "cmd_reload": case "cmd_saveAsFile": @@ -674,16 +675,17 @@ var MessageWindowController = case "button_replyall": case "cmd_replySenderAndGroup": case "cmd_replyAllRecipients": case "cmd_forward": case "button_forward": case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_editDraftMsg": case "cmd_print": case "cmd_printpreview": case "button_print": case "cmd_saveAsFile": return true; case "cmd_saveAsTemplate": var target = getMessageBrowser().contentPrincipal.URI.scheme; return target != "news"; @@ -810,17 +812,20 @@ var MessageWindowController = break; case "cmd_forwardInline": MsgForwardAsInline(null); break; case "cmd_forwardAttachment": MsgForwardAsAttachment(null); break; case "cmd_editAsNew": - MsgEditMessageAsNew(); + MsgEditMessageAsNew(null); + break; + case "cmd_editDraftMsg": + MsgEditDraftMessage(null); break; case "cmd_createFilterFromPopup": CreateFilter(document.popupNode); break; case "cmd_createFilterFromMenu": MsgCreateFilter(); break; case "cmd_delete":