X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/daa3165144c0a10a1303ec9215e4c36d89cf35a4..8a31648287be0ef976f133de2786b137f1e98340:/src/osx/cocoa/filedlg.mm?ds=sidebyside diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index 1aa5828bda..a1c79b7fc5 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -65,7 +65,7 @@ - (id) init { - [super init]; + self = [super init]; _dialog = NULL; return self; } @@ -164,6 +164,13 @@ wxFileDialog::wxFileDialog( : wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name) { m_filterIndex = -1; + m_sheetDelegate = [[ModalDialogDelegate alloc] init]; + [(ModalDialogDelegate*)m_sheetDelegate setImplementation: this]; +} + +wxFileDialog::~wxFileDialog() +{ + [m_sheetDelegate release]; } bool wxFileDialog::SupportsExtraControl() const @@ -308,10 +315,8 @@ void wxFileDialog::ShowWindowModal() [sPanel setAllowsOtherFileTypes:NO]; NSWindow* nativeParent = parentWindow->GetWXWindow(); - ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; - [sheetDelegate setImplementation: this]; [sPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString() - modalForWindow: nativeParent modalDelegate: sheetDelegate + modalForWindow: nativeParent modalDelegate: m_sheetDelegate didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) contextInfo: nil]; } @@ -329,11 +334,9 @@ void wxFileDialog::ShowWindowModal() [oPanel setAllowsMultipleSelection: (HasFlag(wxFD_MULTIPLE) ? YES : NO )]; NSWindow* nativeParent = parentWindow->GetWXWindow(); - ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; - [sheetDelegate setImplementation: this]; [oPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString() types: types modalForWindow: nativeParent - modalDelegate: sheetDelegate + modalDelegate: m_sheetDelegate didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) contextInfo: nil]; } @@ -381,11 +384,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 +394,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 ) @@ -430,7 +436,7 @@ void wxFileDialog::SetupExtraControls(WXWindow nativeWindow) accView = m_filterPanel->GetHandle(); if( HasFlag(wxFD_OPEN) ) { - if ( 1 /* UMAGetSystemVersion() < 0x1060 */ ) + if ( UMAGetSystemVersion() < 0x1060 ) { wxOpenPanelDelegate* del = [[wxOpenPanelDelegate alloc]init]; [del setFileDialog:this]; @@ -460,6 +466,8 @@ void wxFileDialog::SetupExtraControls(WXWindow nativeWindow) int wxFileDialog::ShowModal() { + wxMacAutoreleasePool autoreleasepool; + wxCFStringRef cf( m_message ); wxCFStringRef dir( m_dir ); @@ -548,7 +556,20 @@ int wxFileDialog::ShowModal() { } - returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ]; + /* + 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: m_dir.IsEmpty() ? nil : dir.AsNSString() file:file.AsNSString() ]; ModalFinishedCallback(sPanel, returnCode); } else @@ -566,13 +587,14 @@ int wxFileDialog::ShowModal() if ( UMAGetSystemVersion() < 0x1060 ) { - returnCode = [oPanel runModalForDirectory:dir.AsNSString() + returnCode = [oPanel runModalForDirectory:m_dir.IsEmpty() ? nil : dir.AsNSString() file:file.AsNSString() types:(m_delegate == nil ? types : nil)]; } else { [oPanel setAllowedFileTypes: (m_delegate == nil ? types : nil)]; - [oPanel setDirectoryURL:[NSURL fileURLWithPath:dir.AsNSString() + if ( !m_dir.IsEmpty() ) + [oPanel setDirectoryURL:[NSURL fileURLWithPath:dir.AsNSString() isDirectory:YES]]; returnCode = [oPanel runModal]; }