Bug #44668,75691, 73414, 76268 --> Show / hide the edit draft button. Implement new attachment display using a tree widget

and moz-icons. Implement Save All Attachments again with the new attachment look.
Bug #75462 --> ensure there is always a subject so the twisty shows up...
r=hewitt
sr=sspitzer
This commit is contained in:
mscott%netscape.com 2001-05-05 07:40:24 +00:00
parent 94d061b707
commit 1875274a8f
5 changed files with 214 additions and 96 deletions

View file

@ -53,18 +53,14 @@ function file_init()
function file_attachments() function file_attachments()
{ {
var apChild=document.getElementById('attachmentPopup').cloneNode(true); var numAttachments = GetNumberOfAttachmentsForDisplayedMessage();
if (!apChild)
return false;
apChild.removeAttribute('popupanchor');
apChild.removeAttribute('popupalign');
var amParent=document.getElementById('fileAttachmentMenu'); var amParent=document.getElementById('fileAttachmentMenu');
if (!amParent) if (!amParent)
return false; return false;
if (apChild.childNodes.length){
if ( amParent.childNodes.length ) // hide the attachment menu item if the message does not have any messages..
amParent.removeChild(amParent.childNodes[0]); if (numAttachments > 0)
amParent.appendChild(apChild); {
amParent.removeAttribute('hidden'); amParent.removeAttribute('hidden');
} }
else else

View file

@ -733,7 +733,9 @@ Rights Reserved.
observes="cmd_openMessage" observes="cmd_openMessage"
accesskey="&openMessageWindowCmd.accesskey;" accesskey="&openMessageWindowCmd.accesskey;"
key="key_openMessage"/> key="key_openMessage"/>
<menu id="fileAttachmentMenu" label="&openAttachmentCmd.label;"/> <menu id="fileAttachmentMenu" label="&openAttachmentCmd.label;">
<menupopup id="attachmentMenuList" oncreate="FillAttachmentListPopup(this);"/>
</menu>
<menuseparator/> <menuseparator/>
<menuitem id="menu_close"/> <menuitem id="menu_close"/>
<menu label="&saveAsMenu.label;" accesskey="&saveAsMenu.accesskey;"> <menu label="&saveAsMenu.label;" accesskey="&saveAsMenu.accesskey;">

View file

@ -106,6 +106,7 @@ Rights Reserved.
<popup id="threadPaneContext"/> <popup id="threadPaneContext"/>
<popup id="folderPaneContext"/> <popup id="folderPaneContext"/>
<popup id="attachmentTreeContext"/>
<popup id="emailAddressPopup" popupanchor="bottomleft"> <popup id="emailAddressPopup" popupanchor="bottomleft">
<menuitem label="&AddToAddressBook.label;" <menuitem label="&AddToAddressBook.label;"

View file

@ -47,7 +47,8 @@ var gShowUserAgent = false;
var gCollectIncoming = false; var gCollectIncoming = false;
var gCollectNewsgroup = false; var gCollectNewsgroup = false;
var gCollapsedHeaderViewMode = false; var gCollapsedHeaderViewMode = false;
gBuildAttachmentsForCurrentMsg = false; var gBuildAttachmentsForCurrentMsg = false;
var gBuildAttachmentPopupForCurrentMsg = true;
var msgHeaderParser = Components.classes[msgHeaderParserContractID].getService(Components.interfaces.nsIMsgHeaderParser); var msgHeaderParser = Components.classes[msgHeaderParserContractID].getService(Components.interfaces.nsIMsgHeaderParser);
var abAddressCollector = Components.classes[abAddressCollectorContractID].getService(Components.interfaces.nsIAbAddressCollecter); var abAddressCollector = Components.classes[abAddressCollectorContractID].getService(Components.interfaces.nsIAbAddressCollecter);
@ -211,7 +212,8 @@ var messageHeaderSink = {
ClearCurrentHeaders(); ClearCurrentHeaders();
gGeneratedViewAllHeaderInfo = false; gGeneratedViewAllHeaderInfo = false;
gBuildAttachmentsForCurrentMsg = false; gBuildAttachmentsForCurrentMsg = false;
ClearAttachmentMenu(); gBuildAttachmentPopupForCurrentMsg = true;
ClearAttachmentTreeList();
ClearEditMessageButton(); ClearEditMessageButton();
}, },
@ -226,10 +228,12 @@ var messageHeaderSink = {
ClearHeaderView(gCollapsedHeaderView); ClearHeaderView(gCollapsedHeaderView);
ClearHeaderView(gExpandedHeaderView); ClearHeaderView(gExpandedHeaderView);
EnsureSubjectValue(); // make sure there is a subject even if it's empty so we'll show the subject and the twisty
ShowMessageHeaderPane(); ShowMessageHeaderPane();
UpdateMessageHeaders(); UpdateMessageHeaders();
// if (gIsEditableMsgFolder) if (gIsEditableMsgFolder)
// ShowEditMessageButton(); ShowEditMessageButton();
}, },
handleHeader: function(headerName, headerValue, dontCollectAddress) handleHeader: function(headerName, headerValue, dontCollectAddress)
@ -296,6 +300,17 @@ var messageHeaderSink = {
} }
}; };
function EnsureSubjectValue()
{
if (!('subject' in currentHeaderData))
{
var foo = new Object;
foo.headerValue = "";
foo.headerName = 'subject';
currentHeaderData[foo.headerName] = foo;
}
}
// flush out any local state being held by a header entry for a given // flush out any local state being held by a header entry for a given
// table // table
function ClearHeaderView(headerTable) function ClearHeaderView(headerTable)
@ -725,24 +740,73 @@ function openAttachment(contentType, url, displayName, messageUri)
messenger.openAttachment(contentType, url, displayName, messageUri); messenger.openAttachment(contentType, url, displayName, messageUri);
} }
function printAttachmentAttachment(contentType, url, displayName, messageUri)
{
// we haven't implemented the ability to print attachments yet...
// messenger.printAttachment(contentType, url, displayName, messageUri);
}
// this is our onclick handler for the attachment tree.
// A double click in a tree cell simulates "opening" the attachment....
function attachmentTreeClick(event)
{
if(event.detail == 2) // double click
{
var target = event.originalTarget;
item = target.parentNode.parentNode;
if (item.localName == "treeitem")
{
var commandStringSuffix = item.getAttribute("commandSuffix");
var openString = 'openAttachment' + commandStringSuffix;
eval(openString);
}
}
}
// on command handlers for the attachment tree context menu...
// commandPrefix matches one of our existing functions (openAttachment, saveAttachment, etc.) which we'll add to the command suffix
// found on the tree item....
function handleAttachmentSelection(commandPrefix)
{
// get the selected attachment...and call openAttachment on it...
var attachmentTree = document.getElementById('attachmentTree');
var selectedAttachments = attachmentTree.selectedItems;
var treeItem = selectedAttachments[0];
var commandStringSuffix = treeItem.getAttribute("commandSuffix");
var openString = commandPrefix + commandStringSuffix;
eval(openString);
}
function generateCommandSuffixForAttachment(attachment)
{
return "('" + attachment.contentType + "', '" + attachment.url + "', '" + escape(attachment.displayName) + "', '" + attachment.uri + "')";
}
function displayAttachmentsForExpandedView() function displayAttachmentsForExpandedView()
{ {
var numAttachments = currentAttachments.length; var numAttachments = currentAttachments.length;
if (numAttachments > 0 && !gBuildAttachmentsForCurrentMsg) if (numAttachments > 0 && !gBuildAttachmentsForCurrentMsg)
{ {
var attachmentList = document.getElementById('attachmentsBody');
var row, cell, item;
for (index in currentAttachments) for (index in currentAttachments)
{ {
var attachment = currentAttachments[index]; var attachment = currentAttachments[index];
// be sure to escape the display name before we insert it into the method // we need to create a tree item, a tree row and a tree cell to insert the attachment
var commandStringPrefix = "('" + attachment.contentType + "', '" + attachment.url + "', '" + escape(attachment.displayName) + "', '" + attachment.uri + "')"; // into the attachment tree..
var screenDisplayName = attachment.displayName;
if (attachment.notDownloaded)
{
screenDisplayName += " " + gMessengerBundle.getString("notDownloaded");
}
AddAttachmentToMenu(screenDisplayName, commandStringPrefix); item = document.createElement("treeitem");
} row = document.createElement("treerow");
cell = document.createElement("treecell");
cell.setAttribute('class', "treecell-iconic");
cell.setAttribute("label", attachment.displayName);
item.setAttribute("commandSuffix", generateCommandSuffixForAttachment(attachment)); // set the command suffix on the tree item...
setApplicationIconForAttachment(attachment, cell);
row.appendChild(cell);
item.appendChild(row);
attachmentList.appendChild(item);
} // for each attachment
gBuildAttachmentsForCurrentMsg = true; gBuildAttachmentsForCurrentMsg = true;
} }
@ -753,6 +817,14 @@ function displayAttachmentsForExpandedView()
attachmentNode.setAttribute('collapsed', true); attachmentNode.setAttribute('collapsed', true);
} }
// attachment --> the attachment struct containing all the information on the attachment
// treeCell --> the tree cell currently showing the attachment.
function setApplicationIconForAttachment(attachment, treeCell)
{
// generate a moz-icon url for the attachment so we'll show a nice icon next to it.
treeCell.setAttribute('src', "moz-icon:" + "//" + attachment.displayName + "?size=16&contentType=" + attachment.contentType);
}
function displayAttachmentsForCollapsedView() function displayAttachmentsForCollapsedView()
{ {
var numAttachments = currentAttachments.length; var numAttachments = currentAttachments.length;
@ -767,16 +839,59 @@ function displayAttachmentsForCollapsedView()
} }
} }
function AddAttachmentToMenu(name, oncommandPrefix) // Public method called when we create the attachments file menu
function FillAttachmentListPopup(popup)
{
// the FE sometimes call this routie 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);
for (index in currentAttachments)
{
addAttachmentToPopup(popup, currentAttachments[index]);
}
gBuildAttachmentPopupForCurrentMsg = false;
}
// Public method used to clear the file attachment menu
function ClearAttachmentMenu(popup)
{
if ( popup )
{
while ( popup.childNodes.length > 2 )
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)
{ {
var popup = document.getElementById("attachmentPopup");
if (popup) if (popup)
{ {
var item = document.createElement('menu'); var item = document.createElement('menu');
if ( item ) if ( item )
{ {
item = popup.appendChild(item); // insert the item just before the separator...the separator is the 2nd to last element in the popup.
item.setAttribute('label', name); item.setAttribute('class', 'menu-iconic');
setApplicationIconForAttachment(attachment,item);
var numItemsInPopup = popup.childNodes.length;
item = popup.insertBefore(item, popup.childNodes[length-2]);
item.setAttribute('label', attachment.displayName);
var oncommandPrefix = generateCommandSuffixForAttachment(attachment);
var openpopup = document.createElement('menupopup'); var openpopup = document.createElement('menupopup');
openpopup = item.appendChild(openpopup); openpopup = item.appendChild(openpopup);
@ -793,24 +908,30 @@ function AddAttachmentToMenu(name, oncommandPrefix)
menuitementry.setAttribute('oncommand', 'saveAttachment' + oncommandPrefix); menuitementry.setAttribute('oncommand', 'saveAttachment' + oncommandPrefix);
menuitementry.setAttribute('label', "Save"); menuitementry.setAttribute('label', "Save");
menuitementry = openpopup.appendChild(menuitementry); menuitementry = openpopup.appendChild(menuitementry);
} } // if we created a menu item for this attachment...
} // if we have a popup
var button = document.getElementById("attachmentButton");
if (button)
{
button.setAttribute("label", popup.childNodes.length);
}
}
} }
function SaveAllAttachments() function SaveAllAttachments()
{ {
try try
{ {
messenger.saveAllAttachments(attachmentUrlArray.length, // convert our attachment data into some c++ friendly structs
attachmentUrlArray, var attachmentUrlArray = new Array();
attachmentDisplayNameArray, var attachmentDisplayNameArray = new Array();
attachmentMessageUriArray); var attachmentMessageUriArray = new Array();
// populate these arrays..
for (index in currentAttachments)
{
var attachment = currentAttachments[index];
attachmentUrlArray[index] = attachment.url;
attachmentDisplayNameArray[index] = escape(attachment.displayName);
attachmentMessageUriArray[index] = attachment.uri;
}
// okay the list has been built...now call our save all attachments code...
messenger.saveAllAttachments(attachmentUrlArray.length, attachmentUrlArray, attachmentDisplayNameArray, attachmentMessageUriArray);
} }
catch (ex) catch (ex)
{ {
@ -818,38 +939,18 @@ function SaveAllAttachments()
} }
} }
function AddSaveAllAttachmentsMenu() function ClearAttachmentTreeList()
{ {
return; var attachmentTreebody = document.getElementById("attachmentsBody");
var popup = document.getElementById("attachmentPopup"); if ( attachmentTreebody )
if (popup && popup.childNodes.length > 1)
{ {
var separator = document.createElement('menuseparator'); while ( attachmentTreebody.childNodes.length )
var item = document.createElement('menuitem'); attachmentTreebody.removeChild(attachmentTreebody.childNodes[0]);
if (separator && item)
{
popup.appendChild(separator);
popup.appendChild(item);
item.setAttribute('label', "Save All...");
item.setAttribute('oncommand', "SaveAllAttachments()");
}
}
}
function ClearAttachmentMenu()
{
var popup = document.getElementById("attachmentPopup");
if ( popup )
{
while ( popup.childNodes.length )
popup.removeChild(popup.childNodes[0]);
} }
} }
function ShowEditMessageButton() function ShowEditMessageButton()
{ {
return;
var editBox = document.getElementById("editMessageBox"); var editBox = document.getElementById("editMessageBox");
if (editBox) if (editBox)
editBox.removeAttribute("collapsed"); editBox.removeAttribute("collapsed");
@ -857,7 +958,6 @@ function ShowEditMessageButton()
function ClearEditMessageButton() function ClearEditMessageButton()
{ {
return;
var editBox = document.getElementById("editMessageBox"); var editBox = document.getElementById("editMessageBox");
if (editBox) if (editBox)
editBox.setAttribute("collapsed", "true"); editBox.setAttribute("collapsed", "true");

View file

@ -30,8 +30,24 @@ Rights Reserved.
<script src="chrome://messenger/content/msgHdrViewOverlay.js"/> <script src="chrome://messenger/content/msgHdrViewOverlay.js"/>
<script src="chrome://messenger/content/mime.js"/> <script src="chrome://messenger/content/mime.js"/>
<box id="msgHeaderView">
<popup id="attachmentTreeContext">
<menuitem id="context-openAttachment" label="&openAttachmentCmd.label;" accesskey="&openAttachmentCmd.accesskey;"
oncommand="handleAttachmentSelection('openAttachment');"/>
<menuitem id="context-saveAttachment" label="&saveAsAttachmentCmd.label;" accesskey="&saveAsAttachmentCmd.accesskey;"
oncommand="handleAttachmentSelection('saveAttachment');"/>
<menuitem id="context-printAttachment" disabled="true" label="&printAttachmentCmd.label;" accesskey="&printAttachmentCmd.accesskey;"
oncommand="handleAttachmentSelection('printAttachment');"/>
<menuseparator/>
<menuitem id="context-saveAllAttachments" oncommand="SaveAllAttachments();" label="&saveAllAttachmentsCmd.label;" accesskey="&saveAllAttachmentsCmd.accesskey;"/>
</popup>
<popup id="attachmentMenuList">
<menuseparator/>
<menuitem label="&saveAllAttachmentsCmd.label;" oncommand="SaveAllAttachments();"/>
</popup>
<box id="msgHeaderView">
<grid id="collapsedHeaderView" class="header-part1" flex="1" collapsed="true"> <grid id="collapsedHeaderView" class="header-part1" flex="1" collapsed="true">
<columns> <columns>
<column class="collapsedToggleHdrBox" autostretch="never" > <column class="collapsedToggleHdrBox" autostretch="never" >
@ -141,18 +157,21 @@ Rights Reserved.
</vbox> </vbox>
<hbox id="expandedAttachmentBox" class="header-part1" collapsed = 'true'> <vbox id="editMessageBox" class="header-part1" collapsed="true">
<spring class="buttonSpacer"/>
<button id="editMessageButton" label="&editMessage.label;" orient="right" onclick="MsgComposeDraftMessage()"/>
<spring class="buttonSpacer"/> <spring class="buttonSpacer"/>
<vbox>
<spring class="buttonTopSpacer"/>
<menu id="attachmentMenu" class="attachment-menu">
<button id="attachmentButton" value="1" orient="right"/>
<menupopup id="attachmentPopup" popupanchor="bottomright" popupalign="topright">
</menupopup>
</menu>
<spring flex="1"/>
</vbox> </vbox>
<spring class="buttonSpacer"/>
<hbox id="expandedAttachmentBox" class="header-part1">
<text class="label" id="attachmentText" value="&attachmentsTree.label;" crop="right"/>
<tree id="attachmentTree" class="inset" flex="2" onclick="attachmentTreeClick(event);" context="attachmentTreeContext">
<treecolgroup>
<treecol flex="1"/>
</treecolgroup>
<treechildren id="attachmentsBody" flex="1">
</treechildren>
</tree>
</hbox> </hbox>
</hbox> </hbox>