long style, const wxPoint& pos, const wxSize& sz, const wxString& name)
: wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name)
{
+ m_filterIndex = -1;
}
bool wxFileDialog::SupportsExtraControl() const
return extrapanel;
}
-// An item has been selected in the file filter wxChoice:
-void wxFileDialog::OnFilterSelected( wxCommandEvent &WXUNUSED(event) )
+void wxFileDialog::DoOnFilterSelected(int index)
{
- int index = m_filterChoice->GetSelection();
-
NSArray* types = GetTypesFromExtension(m_filterExtensions[index],m_currentExtensions);
NSSavePanel* panel = (NSSavePanel*) GetWXWindow();
if ( m_delegate )
[panel setAllowedFileTypes:types];
}
+// An item has been selected in the file filter wxChoice:
+void wxFileDialog::OnFilterSelected( wxCommandEvent &WXUNUSED(event) )
+{
+ DoOnFilterSelected( m_filterChoice->GetSelection() );
+}
+
bool wxFileDialog::CheckFile( const wxString& filename )
{
if ( m_currentExtensions.GetCount() == 0 )
m_path = wxEmptyString;
m_fileNames.Clear();
m_paths.Clear();
- // since we don't support retrieving the matching filter
- m_filterIndex = -1;
wxNonOwnedWindow* parentWindow = NULL;
int returnCode = -1;
}
m_firstFileTypeFilter = -1;
-
- if ( m_useFileTypeFilter )
+
+ if ( m_useFileTypeFilter
+ && m_filterIndex >= 0 && m_filterIndex < m_filterExtensions.GetCount() )
+ {
+ m_firstFileTypeFilter = m_filterIndex;
+ }
+ else if ( m_useFileTypeFilter )
{
types = nil;
bool useDefault = true;
{
}
+ /*
+ Let the file dialog know what file type should be used initially.
+ If this is not done then when setting the filter index
+ programmatically to 1 the file will still have the extension
+ of the first file type instead of the second one. E.g. when file
+ types are foo and bar, a filename "myletter" with SetDialogIndex(1)
+ would result in saving as myletter.foo, while we want myletter.bar.
+ */
+ if(m_firstFileTypeFilter > 0)
+ {
+ DoOnFilterSelected(m_firstFileTypeFilter);
+ }
+
returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ];
ModalFinishedCallback(sPanel, returnCode);
}