Index: msgHdrViewOverlay.js
===================================================================
RCS file: /cvsroot/mozilla/mailnews/base/resources/content/msgHdrViewOverlay.js,v
retrieving revision 1.132
diff -u11 -r1.132 msgHdrViewOverlay.js
--- msgHdrViewOverlay.js 15 Feb 2005 00:31:07 -0000 1.132
+++ msgHdrViewOverlay.js 23 Mar 2005 13:36:05 -0000
@@ -62,22 +62,26 @@
var gCollapsedHeaderViewMode = false;
var gCollectAddressTimer = null;
var gCollectAddress = null;
var gBuildAttachmentsForCurrentMsg = false;
var gBuildAttachmentPopupForCurrentMsg = true;
var gBuiltExpandedView = false;
var gBuiltCollapsedView = false;
var gOpenLabel;
var gOpenLabelAccesskey;
var gSaveLabel;
var gSaveLabelAccesskey;
+var gDetachLabel;
+var gDetachLabelAccesskey;
+var gDeleteLabel;
+var gDeleteLabelAccesskey;
var gMessengerBundle;
var gProfileDirURL;
var gIOService;
var gFileHandler;
var msgHeaderParser = Components.classes[msgHeaderParserContractID].getService(Components.interfaces.nsIMsgHeaderParser);
var abAddressCollector = null;
// other components may listen to on start header & on end header notifications for each message we display
// to do that you need to add yourself to our gMessageListeners array with object that has two properties:
// onStartHeaders and onEndHeaders.
@@ -899,22 +903,23 @@
}
// createnewAttachmentInfo --> constructor method for creating new attachment object which goes into the
// data attachment array.
function createNewAttachmentInfo(contentType, url, displayName, uri, isExternalAttachment)
{
this.contentType = contentType;
this.url = url;
this.displayName = displayName;
this.uri = uri;
this.isExternalAttachment = isExternalAttachment;
+ this.attachment = this;
}
createNewAttachmentInfo.prototype.saveAttachment = function saveAttachment()
{
messenger.saveAttachment(this.contentType,
this.url,
encodeURIComponent(this.displayName),
this.uri, false);
}
createNewAttachmentInfo.prototype.openAttachment = function openAttachment()
@@ -927,39 +932,97 @@
createNewAttachmentInfo.prototype.printAttachment = function printAttachment()
{
/* we haven't implemented the ability to print attachments yet...
messenger.printAttachment(this.contentType,
this.url,
encodeURIComponent(this.displayName),
this.uri);
*/
}
+createNewAttachmentInfo.prototype.deleteAttachment = function deleteAttachment()
+{
+ messenger.detachAttachment(this.contentType,
+ this.url,
+ encodeURIComponent(this.displayName),
+ this.uri,
+ false);
+}
+
+createNewAttachmentInfo.prototype.detachAttachment = function detachAttachment()
+{
+ messenger.detachAttachment(this.contentType,
+ this.url,
+ encodeURIComponent(this.displayName),
+ this.uri,
+ true);
+}
+
+function CanDetachAttachments()
+{
+ var uri = GetLoadedMessage();
+ return !IsNewsMessage(uri) && (!IsImapMessage(uri) || CheckOnline());
+}
+
function onShowAttachmentContextMenu()
{
// if no attachments are selected, disable the Open and Save...
var attachmentList = document.getElementById('attachmentList');
var selectedAttachments = attachmentList.selectedItems;
var openMenu = document.getElementById('context-openAttachment');
var saveMenu = document.getElementById('context-saveAttachment');
- if (selectedAttachments.length > 0)
+ var detachMenu = document.getElementById('context-detachAttachment');
+ var deleteMenu = document.getElementById('context-deleteAttachment');
+ var detachAllMenu = document.getElementById('context-detachAllAttachments');
+ var deleteAllMenu = document.getElementById('context-deleteAllAttachments');
+ var canDetach = CanDetachAttachments();
+ var canOpen = false;
+ for (var i = 0; i < selectedAttachments.length && !canOpen; i++)
+ canOpen = selectedAttachments[i].attachment.contentType != 'text/x-moz-deleted';
+ if (canOpen && selectedAttachments.length == 1)
{
openMenu.removeAttribute('disabled');
- saveMenu.removeAttribute('disabled');
}
else
{
openMenu.setAttribute('disabled', true);
+ }
+ if (canOpen)
+ {
+ saveMenu.removeAttribute('disabled');
+ }
+ else
+ {
saveMenu.setAttribute('disabled', true);
}
+ if (canDetach && canOpen)
+ {
+ detachMenu.removeAttribute('disabled');
+ deleteMenu.removeAttribute('disabled');
+ }
+ else
+ {
+ detachMenu.setAttribute('disabled', 'true');
+ deleteMenu.setAttribute('disabled', 'true');
+ }
+ if (canDetach)
+ {
+ detachAllMenu.removeAttribute('disabled');
+ deleteAllMenu.removeAttribute('disabled');
+ }
+ else
+ {
+ detachAllMenu.setAttribute('disabled', 'true');
+ deleteAllMenu.setAttribute('disabled', 'true');
+ }
}
// this is our onclick handler for the attachment list.
// A double click in a listitem simulates "opening" the attachment....
function attachmentListClick(event)
{
// we only care about button 0 (left click) events
if (event.button != 0) return;
if (event.detail == 2) // double click
{
@@ -970,48 +1033,52 @@
}
}
}
// on command handlers for the attachment list context menu...
// commandPrefix matches one of our existing functions
// (openAttachment, saveAttachment, etc.)
function handleAttachmentSelection(commandPrefix)
{
var attachmentList = document.getElementById('attachmentList');
var selectedAttachments = attachmentList.selectedItems;
- var listItem = selectedAttachments[0];
-
- listItem.attachment[commandPrefix]();
+ if (selectedAttachments.length > 1)
+ HandleMultipleAttachments(commandPrefix, selectedAttachments);
+ else
+ selectedAttachments[0].attachment[commandPrefix]();
}
function displayAttachmentsForExpandedView()
{
var numAttachments = currentAttachments.length;
if (numAttachments > 0 && !gBuildAttachmentsForCurrentMsg)
{
var attachmentList = document.getElementById('attachmentList');
for (index in currentAttachments)
{
var attachment = currentAttachments[index];
// we need to create a listitem to insert the attachment
// into the attachment list..
var item = attachmentList.appendItem(attachment.displayName,"");
- item.setAttribute("class", "listitem-iconic");
+ item.setAttribute("class", "listitem-iconic attachment-item");
item.setAttribute("tooltip", "attachmentListTooltip");
item.attachment = attachment;
item.setAttribute("attachmentUrl", attachment.url);
item.setAttribute("attachmentContentType", attachment.contentType);
item.setAttribute("attachmentUri", attachment.uri);
- setApplicationIconForAttachment(attachment, item);
+ if (attachment.contentType == "text/x-moz-deleted")
+ item.setAttribute('disabled', 'true');
+ else
+ setApplicationIconForAttachment(attachment, item);
} // for each attachment
gBuildAttachmentsForCurrentMsg = true;
}
var expandedAttachmentBox = document.getElementById('expandedAttachmentBox');
expandedAttachmentBox.collapsed = numAttachments <= 0;
}
// attachment --> the attachment struct containing all the information on the attachment
// listitem --> the listitem currently showing the attachment.
@@ -1051,125 +1118,192 @@
// First clear out the old view...
ClearAttachmentMenu(popup);
for (index in currentAttachments)
{
++attachmentIndex;
addAttachmentToPopup(popup, currentAttachments[index], attachmentIndex);
}
gBuildAttachmentPopupForCurrentMsg = false;
+ var detachAllMenu = document.getElementById('file-detachAllAttachments');
+ var deleteAllMenu = document.getElementById('file-deleteAllAttachments');
+ if (CanDetachAttachments())
+ {
+ detachAllMenu.removeAttribute('disabled');
+ deleteAllMenu.removeAttribute('disabled');
+ }
+ else
+ {
+ detachAllMenu.setAttribute('disabled', 'true');
+ deleteAllMenu.setAttribute('disabled', 'true');
+ }
}
// Public method used to clear the file attachment menu
function ClearAttachmentMenu(popup)
{
if ( popup )
{
- while ( popup.childNodes.length > 2 )
+ while ( popup.childNodes[0].localName == 'menu' )
popup.removeChild(popup.childNodes[0]);
}
}
// Public method used to determine the number of attachments for the currently displayed message...
function GetNumberOfAttachmentsForDisplayedMessage()
{
return currentAttachments.length;
}
// private method used to build up a menu list of attachments
function addAttachmentToPopup(popup, attachment, attachmentIndex)
{
if (popup)
{
var item = document.createElement('menu');
if ( item )
{
if (!gMessengerBundle)
gMessengerBundle = document.getElementById("bundle_messenger");
- // insert the item just before the separator...the separator is the 2nd to last element in the popup.
- item.setAttribute('class', 'menu-iconic');
- setApplicationIconForAttachment(attachment,item);
- var numItemsInPopup = popup.childNodes.length;
- item = popup.insertBefore(item, popup.childNodes[numItemsInPopup-2]);
+ // insert the item just before the separator
+ item = popup.insertBefore(item, popup.childNodes[attachmentIndex - 1]);
+ item.setAttribute('class', 'menu-iconic attachment-item');
var formattedDisplayNameString = gMessengerBundle.getFormattedString("attachmentDisplayNameFormat",
[attachmentIndex, attachment.displayName]);
item.setAttribute('label', formattedDisplayNameString);
item.setAttribute('accesskey', attachmentIndex);
+ if (attachment.contentType == "text/x-moz-deleted") {
+ item.setAttribute('disabled', 'true');
+ return;
+ }
+ setApplicationIconForAttachment(attachment, item);
+ var canDetach = CanDetachAttachments();
var openpopup = document.createElement('menupopup');
openpopup = item.appendChild(openpopup);
var menuitementry = document.createElement('menuitem');
menuitementry.attachment = attachment;
menuitementry.setAttribute('oncommand', 'this.attachment.openAttachment()');
+ if (!gDeleteLabel)
+ gDeleteLabel = gMessengerBundle.getString("deleteLabel");
+ if (!gDeleteLabelAccesskey)
+ gDeleteLabelAccesskey = gMessengerBundle.getString("deleteLabelAccesskey");
+ if (!gDetachLabel)
+ gDetachLabel = gMessengerBundle.getString("detachLabel");
+ if (!gDetachLabelAccesskey)
+ gDetachLabelAccesskey = gMessengerBundle.getString("detachLabelAccesskey");
if (!gSaveLabel)
gSaveLabel = gMessengerBundle.getString("saveLabel");
if (!gSaveLabelAccesskey)
gSaveLabelAccesskey = gMessengerBundle.getString("saveLabelAccesskey");
if (!gOpenLabel)
gOpenLabel = gMessengerBundle.getString("openLabel");
if (!gOpenLabelAccesskey)
gOpenLabelAccesskey = gMessengerBundle.getString("openLabelAccesskey");
menuitementry.setAttribute('label', gOpenLabel);
menuitementry.setAttribute('accesskey', gOpenLabelAccesskey);
menuitementry = openpopup.appendChild(menuitementry);
- var menuseparator = document.createElement('menuseparator');
- openpopup.appendChild(menuseparator);
-
menuitementry = document.createElement('menuitem');
menuitementry.attachment = attachment;
menuitementry.setAttribute('oncommand', 'this.attachment.saveAttachment()');
menuitementry.setAttribute('label', gSaveLabel);
menuitementry.setAttribute('accesskey', gSaveLabelAccesskey);
menuitementry = openpopup.appendChild(menuitementry);
+
+ var menuseparator = document.createElement('menuseparator');
+ openpopup.appendChild(menuseparator);
+
+ menuitementry = document.createElement('menuitem');
+ menuitementry.attachment = attachment;
+ menuitementry.setAttribute('oncommand', 'this.attachment.detachAttachment()');
+ menuitementry.setAttribute('label', gDetachLabel);
+ menuitementry.setAttribute('accesskey', gDetachLabelAccesskey);
+ if (!canDetach)
+ menuitementry.setAttribute('disabled', 'true');
+ menuitementry = openpopup.appendChild(menuitementry);
+
+ menuitementry = document.createElement('menuitem');
+ menuitementry.attachment = attachment;
+ menuitementry.setAttribute('oncommand', 'this.attachment.deleteAttachment()');
+ menuitementry.setAttribute('label', gDeleteLabel);
+ menuitementry.setAttribute('accesskey', gDeleteLabelAccesskey);
+ if (!canDetach)
+ menuitementry.setAttribute('disabled', 'true');
+ menuitementry = openpopup.appendChild(menuitementry);
} // if we created a menu item for this attachment...
} // if we have a popup
}
-function SaveAllAttachments()
+function HandleMultipleAttachments(commandPrefix, selectedAttachments)
{
try
{
// convert our attachment data into some c++ friendly structs
var attachmentContentTypeArray = new Array();
var attachmentUrlArray = new Array();
var attachmentDisplayNameArray = new Array();
var attachmentMessageUriArray = new Array();
// populate these arrays..
- for (index in currentAttachments)
+ for (index in selectedAttachments)
{
- var attachment = currentAttachments[index];
+ var attachment = selectedAttachments[index].attachment;
attachmentContentTypeArray[index] = attachment.contentType;
attachmentUrlArray[index] = attachment.url;
attachmentDisplayNameArray[index] = encodeURI(attachment.displayName);
attachmentMessageUriArray[index] = attachment.uri;
}
- // okay the list has been built...now call our save all attachments code...
- messenger.saveAllAttachments(attachmentContentTypeArray.length,
- attachmentContentTypeArray, attachmentUrlArray,
- attachmentDisplayNameArray, attachmentMessageUriArray);
+ // okay the list has been built...now call our action code...
+ switch (commandPrefix)
+ {
+ case "saveAttachment":
+ messenger.saveAllAttachments(attachmentContentTypeArray.length,
+ attachmentContentTypeArray,
+ attachmentUrlArray,
+ attachmentDisplayNameArray,
+ attachmentMessageUriArray);
+ break;
+ case "detachAttachment":
+ messenger.detachAllAttachments(attachmentContentTypeArray.length,
+ attachmentContentTypeArray,
+ attachmentUrlArray,
+ attachmentDisplayNameArray,
+ attachmentMessageUriArray,
+ true /* save */);
+ break;
+ case "deleteAttachment":
+ messenger.detachAllAttachments(attachmentContentTypeArray.length,
+ attachmentContentTypeArray,
+ attachmentUrlArray,
+ attachmentDisplayNameArray,
+ attachmentMessageUriArray,
+ false /* don't save */);
+ break;
+ default:
+ dump (commandPrefix + "** unknown handle all attachments action **\n");
+ }
}
catch (ex)
{
- dump ("** failed to save all attachments **\n");
+ dump ("** failed to handle all attachments **\n");
}
}
function ClearAttachmentList()
{
// we also have to disable the File/Attachments menuitem
node = document.getElementById("fileAttachmentMenu");
if (node)
node.setAttribute("disabled", "true");
// clear selection
Index: msgHdrViewOverlay.xul
===================================================================
RCS file: /cvsroot/mozilla/mailnews/base/resources/content/msgHdrViewOverlay.xul,v
retrieving revision 1.62
diff -u11 -r1.62 msgHdrViewOverlay.xul
--- msgHdrViewOverlay.xul 9 Feb 2005 05:38:29 -0000 1.62
+++ msgHdrViewOverlay.xul 23 Mar 2005 13:36:05 -0000
@@ -53,28 +53,43 @@
-
+
+
+
+
+
+