Bug 514494 - Make the Windows XP save as filepicker change the file's extension when the filter is changed. r=jimm, sr=vlad

This commit is contained in:
Siddharth Agarwal 2010-03-24 15:11:48 +05:30
Родитель 4c5a4c96cd
Коммит b7ebaf9f38
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -96,7 +96,8 @@ interface nsIFilePicker : nsISupports
in AString filter);
/**
* The filename that should be suggested to the user as a default.
* The filename that should be suggested to the user as a default. This should
* include the extension.
*
* @throws NS_ERROR_FAILURE on attempts to get
*/

Просмотреть файл

@ -209,6 +209,8 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
ofn.Flags = OFN_NOCHANGEDIR | OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
PRInt32 extIndex = mDefault.RFind(".");
if (!mDefaultExtension.IsEmpty()) {
ofn.lpstrDefExt = mDefaultExtension.get();
}
@ -216,7 +218,6 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
// Get file extension from suggested filename
// to detect if we are saving an html file
//XXX: nsIFile SHOULD HAVE A GetExtension() METHOD!
PRInt32 extIndex = mDefault.RFind(".");
if ( extIndex >= 0) {
nsAutoString ext;
mDefault.Right(ext, mDefault.Length() - extIndex);
@ -260,6 +261,12 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
StringEndsWith(ext, NS_LITERAL_CSTRING(".url")))
ofn.Flags |= OFN_NODEREFERENCELINKS;
// The save-as filepicker on XP doesn't appreciate the default filename
// having an extension. Vista and up don't mind either way. If
// lpstrDefExt is already defined, strip the .ext from the file name.
if (ofn.lpstrDefExt && extIndex >= 0 && extIndex < FILE_BUFFER_SIZE)
fileBuffer[extIndex] = '\0';
result = ::GetSaveFileNameW(&ofn);
if (!result) {
// Error, find out what kind.