Bug 92726 Save As should default to the message subject r=me moa=glazou sr=bienvenu a=asa

This commit is contained in:
neil%parkwaycc.co.uk 2003-10-24 12:13:46 +00:00
parent 685116577a
commit c3f084c87b
9 changed files with 39 additions and 21 deletions

View File

@ -807,18 +807,8 @@ function GetSuggestedFileName(aDocumentURLString, aMIMEType)
// check if there is a title we can use
var title = GetDocumentTitle();
if (title) // we have a title; let's see if it's usable
{
// clean up the title to make it a usable filename
title = title.replace(/\"/g, ""); // Strip out quote character: "
title = TrimString(title); // trim whitespace from beginning and end
title = title.replace(/[ \.\\@\/:]/g, "_"); //Replace "bad" filename characters with "_"
if (title.length > 0)
return title + extension;
}
// if we still don't have a file name, let's just go with "untitled"
return GetString("untitled") + extension;
// generate a valid filename, if we can't just go with "untitled"
return GenerateValidFilename(title, extension) || GetString("untitled") + extension;
}
// returns file picker result

View File

@ -60,7 +60,6 @@
<script type="application/x-javascript" src="chrome://editor/content/EditorCommandsDebug.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsTransferable.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/XPCNativeWrapper.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaDD.js"/>
<!--
editor.xul has these - do we need them?

View File

@ -70,7 +70,6 @@
<script type="application/x-javascript" src="chrome://editor/content/StructBarContextMenu.js"/>
<script type="application/x-javascript" src="chrome://editor/content/editorApplicationOverlay.js"/>
<script type="application/x-javascript" src="chrome://editor/content/publishprefs.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/XPCNativeWrapper.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaDD.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaClick.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/printing.js"/>

View File

@ -32,6 +32,7 @@
<script type="application/x-javascript" src="chrome://editor/content/editorUtilities.js"/>
<script type="application/x-javascript" src="chrome://editor/content/ComposerCommands.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/XPCNativeWrapper.js"/>
<keyset id="editorKeys">
<!-- defined in globalOverlay -->

View File

@ -100,7 +100,7 @@ interface nsIMessenger : nsISupports {
void Redo(in nsIMsgWindow msgWindow);
void sendUnsentMessages(in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow);
void SetDocumentCharset(in string characterSet);
void saveAs(in string aURI, in boolean aAsFile, in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow);
void saveAs(in string aURI, in boolean aAsFile, in nsIMsgIdentity aIdentity, in wstring aMsgFilename);
void openAttachment(in string contentTpe, in string url, in string displayName, in string messageUri);
void saveAttachment(in string contentTpe, in string url, in string displayName, in string messageUri);
void saveAllAttachments(in unsigned long count, [array, size_is(count)] in string contentTypeArray,

View File

@ -334,14 +334,23 @@ function SubscribeOKCallback(changeTable)
function SaveAsFile(uri)
{
if (uri) messenger.saveAs(uri, true, null, msgWindow);
if (uri) {
var filename = null;
try {
var subject = messenger.messageServiceFromURI(uri)
.messageURIToMsgHdr(uri).subject;
filename = GenerateValidFilename(subject, ".eml");
}
catch (ex) {}
messenger.saveAs(uri, true, null, filename);
}
}
function SaveAsTemplate(uri, folder)
{
if (uri) {
var identity = getIdentityForServer(folder.server);
messenger.saveAs(uri, false, identity, msgWindow);
messenger.saveAs(uri, false, identity, null);
}
}
@ -656,4 +665,4 @@ function deleteJunkInFolder()
SetNextMessageAfterDelete();
view.doCommand(nsMsgViewCommandType.deleteMsg);
treeSelection.clearSelection();
}
}

View File

@ -883,7 +883,7 @@ enum MESSENGER_SAVEAS_FILE_TYPE
#define EML_FILE_EXTENSION ".eml"
NS_IMETHODIMP
nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity, nsIMsgWindow *aMsgWindow)
nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity, const PRUnichar *aMsgFilename)
{
NS_ENSURE_ARG_POINTER(aURI);
@ -905,8 +905,12 @@ nsMessenger::SaveAs(const char *aURI, PRBool aAsFile, nsIMsgIdentity *aIdentity,
goto done;
filePicker->Init(nsnull, GetString(NS_LITERAL_STRING("SaveMailAs").get()), nsIFilePicker::modeSave);
filePicker->SetDefaultString(GetString(NS_LITERAL_STRING("defaultSaveMessageAsFileName").get()));
// if we have a non-null filename use it, otherwise use default save message one
if (aMsgFilename)
filePicker->SetDefaultString(aMsgFilename);
else
filePicker->SetDefaultString(GetString(NS_LITERAL_STRING("defaultSaveMessageAsFileName").get()));
// because we will be using GetFilterIndex()
// we must call AppendFilters() one at a time,

View File

@ -1735,6 +1735,8 @@ function Save()
function SaveAsFile(saveAs)
{
dump("SaveAsFile from XUL\n");
var subject = document.getElementById('msgSubject').value;
GetCurrentEditor().setDocumentTitle(subject);
if (gMsgCompose.bodyConvertible() == nsIMsgCompConvertible.Plain)
SaveDocument(saveAs, false, "text/plain");
else

View File

@ -408,3 +408,17 @@ function utilityOnUnload(aEvent)
}
addEventListener("load", utilityOnLoad, false);
function GenerateValidFilename(filename, extension)
{
if (filename) // we have a title; let's see if it's usable
{
// clean up the filename to make it usable
filename = filename.replace(/\"/g, ""); // Strip out quote character: "
filename = filename.replace(/(^\s+)|(\s+$)/g, ''); // trim whitespace from beginning and end
filename = filename.replace(/[ \.\\@\/:]/g, "_"); //Replace "bad" filename characters with "_"
if (filename.length > 0)
return filename + extension;
}
return null;
}