X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1b447793ea73455bcec70ee39db841b28e6fc7cf..7e4952db837344e369ff9ccc7ece1f7b8c207cf1:/src/osx/cocoa/filedlg.mm diff --git a/src/osx/cocoa/filedlg.mm b/src/osx/cocoa/filedlg.mm index c212ecea36..0b34682a72 100644 --- a/src/osx/cocoa/filedlg.mm +++ b/src/osx/cocoa/filedlg.mm @@ -30,6 +30,7 @@ #endif #include "wx/filename.h" +#include "wx/tokenzr.h" #include "wx/osx/private.h" @@ -37,6 +38,10 @@ // implementation // ============================================================================ +// Open Items: +// - support for old style MacOS creator / type combos +// - parameter support for descending into packages as directories (setTreatsFilePackagesAsDirectories) + IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase) wxFileDialog::wxFileDialog( @@ -47,7 +52,6 @@ wxFileDialog::wxFileDialog( { } - NSArray* GetTypesFromFilter( const wxString filter ) { NSMutableArray* types = nil; @@ -99,34 +103,38 @@ NSArray* GetTypesFromFilter( const wxString filter ) const size_t extCount = extensions.GetCount(); for ( size_t i = 0 ; i < extCount; i++ ) { - wxString extension = extensions[i]; - - // Remove leading '*' - if (extension.length() && (extension.GetChar(0) == '*')) - extension = extension.Mid( 1 ); - - // Remove leading '.' - if (extension.length() && (extension.GetChar(0) == '.')) - extension = extension.Mid( 1 ); - - if ( extension.IsEmpty() ) + wxString extensiongroup = extensions[i]; + wxStringTokenizer tokenizer( extensiongroup , wxT(";") ) ; + while ( tokenizer.HasMoreTokens() ) { - if ( types != nil ) - [types release]; - return nil; - } + wxString extension = tokenizer.GetNextToken() ; + // Remove leading '*' + if (extension.length() && (extension.GetChar(0) == '*')) + extension = extension.Mid( 1 ); + // Remove leading '.' + if (extension.length() && (extension.GetChar(0) == '.')) + extension = extension.Mid( 1 ); - if ( types == nil ) - types = [[NSMutableArray alloc] init]; + if ( extension.IsEmpty() ) + { + if ( types != nil ) + [types release]; + return nil; + } - wxCFStringRef cfext(extension); - [types addObject: (NSString*)cfext.AsNSString() ]; -#if 0 - wxUint32 fileType, creator; + if ( types == nil ) + types = [[NSMutableArray alloc] init]; - // extension -> mactypes + wxCFStringRef cfext(extension); + [types addObject: (NSString*)cfext.AsNSString() ]; +#if 0 + // add support for classic fileType / creator here + wxUint32 fileType, creator; + // extension -> mactypes #endif + } + } } return types; @@ -145,6 +153,14 @@ int wxFileDialog::ShowModal() m_path = wxEmptyString; m_fileNames.Clear(); + + wxNonOwnedWindow* parentWindow = NULL; + int returnCode = -1; + + if (GetParent()) + { + parentWindow = dynamic_cast(wxGetTopLevelParent(GetParent())); + } if (HasFlag(wxFD_SAVE)) { @@ -152,13 +168,35 @@ int wxFileDialog::ShowModal() // makes things more convenient: [sPanel setCanCreateDirectories:YES]; [sPanel setMessage:cf.AsNSString()]; + // if we should be able to descend into pacakges we must somehow + // be able to pass this in [sPanel setTreatsFilePackagesAsDirectories:NO]; + [sPanel setCanSelectHiddenExtension:YES]; if ( HasFlag(wxFD_OVERWRITE_PROMPT) ) { } - if ( [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ] == NSOKButton ) +/* + if (parentWindow) + { + NSWindow* nativeParent = parentWindow->GetWXWindow(); + ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; + [sPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString() + modalForWindow: nativeParent modalDelegate: sheetDelegate + didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo: nil]; + [sheetDelegate waitForSheetToFinish]; + returnCode = [sheetDelegate code]; + [sheetDelegate release]; + } + else +*/ + { + returnCode = [sPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() ]; + } + + if (returnCode == NSOKButton ) { panel = sPanel; result = wxID_OK; @@ -180,7 +218,27 @@ int wxFileDialog::ShowModal() [oPanel setCanChooseFiles:YES]; [oPanel setMessage:cf.AsNSString()]; - if ( [oPanel runModalForDirectory:dir.AsNSString() file:file.AsNSString() types:types] == NSOKButton ) +/* + if (parentWindow) + { + NSWindow* nativeParent = parentWindow->GetWXWindow(); + ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; + [oPanel beginSheetForDirectory:dir.AsNSString() file:file.AsNSString() + types: types modalForWindow: nativeParent + modalDelegate: sheetDelegate + didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo: nil]; + [sheetDelegate waitForSheetToFinish]; + returnCode = [sheetDelegate code]; + [sheetDelegate release]; + } + else +*/ + { + returnCode = [oPanel runModalForDirectory:dir.AsNSString() + file:file.AsNSString() types:types]; + } + if (returnCode == NSOKButton ) { panel = oPanel; result = wxID_OK; @@ -206,181 +264,4 @@ int wxFileDialog::ShowModal() return result; } -#if 0 - - wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr)); - - if ( parent ) - parent->AddChild(this); - - m_cocoaNSWindow = nil; - m_cocoaNSView = nil; - - //Init the wildcard array - m_wildcards = [[NSMutableArray alloc] initWithCapacity:0]; - - //If the user requests to save - use a NSSavePanel - //else use a NSOpenPanel - if (HasFlag(wxFD_SAVE)) - { - SetNSPanel([NSSavePanel savePanel]); - - [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)]; - - [GetNSSavePanel() setPrompt:@"Save"]; - [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES]; - [GetNSSavePanel() setCanSelectHiddenExtension:YES]; - -// Cached as per-app in obj-c -// [GetNSSavePanel() setExtensionHidden:YES]; - - // - // NB: Note that only Panther supports wildcards - // with save dialogs - not that wildcards in save - // dialogs are all that useful, anyway :) - // - } - else //m_dialogStyle & wxFD_OPEN - { - SetNSPanel([NSOpenPanel openPanel]); - [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)]; - - [(NSOpenPanel*)m_cocoaNSWindow setAllowsMultipleSelection:(HasFlag(wxFD_MULTIPLE))]; - [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES]; - [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:YES]; - [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:NO]; - [GetNSSavePanel() setPrompt:@"Open"]; - - //convert wildcards - open panel only takes file extensions - - //no actual wildcards here :) - size_t lastwcpos = 0; - bool bDescription = true; - size_t i; - for(i = wildCard.find('|'); - i != wxString::npos; - i = wildCard.find('|', lastwcpos+1)) - { - size_t oldi = i; - - if(!bDescription) - { - bDescription = !bDescription; - - //work backwards looking for a period - while(i != lastwcpos && wildCard[--i] != '.') {} - - if(i == lastwcpos) - { - //no extension - can't use this wildcard - lastwcpos = oldi; - continue; - } - - [m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))]; - } - else - bDescription = !bDescription; - lastwcpos = oldi; - } - - if (!bDescription) - { - //get last wildcard - size_t oldi = wildCard.length(); - i = oldi; - - //work backwards looking for a period - while(i != lastwcpos && wildCard[--i] != '.') {} - - if(i != lastwcpos) - [m_wildcards addObject:wxNSStringWithWxString(wildCard.substr(i+1, oldi-i-1))]; - } - - if ([m_wildcards count] == 0) - { - [m_wildcards release]; - m_wildcards = nil; - } - } -} - -wxFileDialog::~wxFileDialog() -{ - [m_wildcards release]; -} - -void wxFileDialog::GetPaths(wxArrayString& paths) const -{ - paths.Empty(); - - wxString dir(m_dir); - if ( m_dir.Last() != _T('\\') ) - dir += _T('\\'); - - size_t count = m_fileNames.GetCount(); - for ( size_t n = 0; n < count; n++ ) - { - if (wxFileName(m_fileNames[n]).IsAbsolute()) - paths.Add(m_fileNames[n]); - else - paths.Add(dir + m_fileNames[n]); - } -} - -void wxFileDialog::GetFilenames(wxArrayString& files) const -{ - files = m_fileNames; -} - -void wxFileDialog::SetPath(const wxString& path) -{ - wxString ext; - wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext); - if ( !ext.empty() ) - m_fileName << _T('.') << ext; -} - -int wxFileDialog::ShowModal() -{ - wxAutoNSAutoreleasePool thePool; - - m_fileNames.Empty(); - - int nResult; - - if (HasFlag(wxFD_SAVE)) - { - nResult = [GetNSSavePanel() - runModalForDirectory:wxNSStringWithWxString(m_dir) - file:wxNSStringWithWxString(m_fileName)]; - - if (nResult == NSOKButton) - { - m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename])); - m_path = m_fileNames[0]; - } - } - else //m_dialogStyle & wxFD_OPEN - { - nResult = [(NSOpenPanel*)m_cocoaNSWindow - runModalForDirectory:wxNSStringWithWxString(m_dir) - file:wxNSStringWithWxString(m_fileName) - types:m_wildcards]; - - if (nResult == NSOKButton) - { - for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i) - { - m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)])); - } - - m_path = m_fileNames[0]; - } - } - - return nResult == NSOKButton ? wxID_OK : wxID_CANCEL; -} - -#endif - #endif // wxUSE_FILEDLG