From: Dimitri Schoolwerth Date: Mon, 25 Apr 2011 13:18:45 +0000 (+0000) Subject: Fixed filename in wxOSX-Cocoa's file dialog using extension of wrong file type. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/cbbb1f548962b30c43849e29fd64eceb4d8720e8 Fixed filename in wxOSX-Cocoa's file dialog using extension of wrong file type. When using SetFilterIndex to indicate a different initial file type the dialog would still use the extension of the first file type (if the filename had no extension then unchecking "Hide extension" would append the first file type's extension). Fixed this by calling code, that formerly got called only from OnFilterSelected, to notify OS X of the file type change. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67598 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/filedlg.h b/include/wx/osx/filedlg.h index 5ddc524e76..170795379e 100644 --- a/include/wx/osx/filedlg.h +++ b/include/wx/osx/filedlg.h @@ -70,6 +70,7 @@ protected: #if wxOSX_USE_COCOA virtual wxWindow* CreateFilterPanel(wxWindow *extracontrol); + void DoOnFilterSelected(int index); virtual void OnFilterSelected(wxCommandEvent &event); wxArrayString m_filterExtensions; diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index 1aa5828bda..c0b6185d34 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -381,11 +381,8 @@ wxWindow* wxFileDialog::CreateFilterPanel(wxWindow *extracontrol) 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 ) @@ -394,6 +391,12 @@ void wxFileDialog::OnFilterSelected( wxCommandEvent &WXUNUSED(event) ) [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 ) @@ -548,6 +551,19 @@ int wxFileDialog::ShowModal() { } + /* + 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); }