Bug 662261 - Fix open dialog on MacOS X when mSelectedTypeIndex is out-of-range. r=joshmoz

This is done in two steps:
1. Remove "filepicker.lastTypeIndex" preference which was actually the cause
of the described bug.
2. Don't fail if the value is out-of-range but fallback to a default value.
This commit is contained in:
Mounir Lamouri 2011-06-14 16:14:56 +02:00
parent 060ad9ef4a
commit 3cf77b825a

View File

@ -61,7 +61,6 @@ using namespace mozilla;
const float kAccessoryViewPadding = 5;
const int kSaveTypeControlTag = 1;
const char kLastTypeIndexPref[] = "filepicker.lastTypeIndex";
static PRBool gCallSecretHiddenFileAPI = PR_FALSE;
const char kShowHiddenFilesPref[] = "filepicker.showHiddenFiles";
@ -143,10 +142,6 @@ nsFilePicker::InitNative(nsIWidget *aParent, const nsAString& aTitle,
{
mTitle = aTitle;
mMode = aMode;
// read in initial type index from prefs
mSelectedTypeIndex =
Preferences::GetInt(kLastTypeIndexPref, mSelectedTypeIndex);
}
NSView* nsFilePicker::GetAccessoryView()
@ -511,8 +506,6 @@ nsFilePicker::PutLocalFile(const nsString& inTitle, const nsString& inDefaultNam
NSPopUpButton* popupButton = [accessoryView viewWithTag:kSaveTypeControlTag];
if (popupButton) {
mSelectedTypeIndex = [popupButton indexOfSelectedItem];
// save out to prefs for initializing other file picker instances
Preferences::SetInt(kLastTypeIndexPref, mSelectedTypeIndex);
}
NSURL* fileURL = [thePanel URL];
@ -542,10 +535,15 @@ nsFilePicker::GetFilterList()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
if (mFilters.Length() <= (PRUint32)mSelectedTypeIndex) {
if (!mFilters.Length()) {
return nil;
}
if (mFilters.Length() <= (PRUint32)mSelectedTypeIndex) {
NS_WARNING("An out of range index has been selected. Using the first index instead.");
mSelectedTypeIndex = 0;
}
const nsString& filterWide = mFilters[mSelectedTypeIndex];
if (!filterWide.Length()) {
return nil;