2 ==============================================================================
\r
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
\r
5 Copyright 2004-11 by Raw Material Software Ltd.
\r
7 ------------------------------------------------------------------------------
\r
9 JUCE can be redistributed and/or modified under the terms of the GNU General
\r
10 Public License (Version 2), as published by the Free Software Foundation.
\r
11 A copy of the license is included in the JUCE distribution, or can be found
\r
12 online at www.gnu.org/licenses.
\r
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
\r
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
\r
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
\r
18 ------------------------------------------------------------------------------
\r
20 To release a closed-source product which uses JUCE, commercial licenses are
\r
21 available: visit www.rawmaterialsoftware.com/juce for more information.
\r
23 ==============================================================================
\r
26 // (This file gets included by juce_mac_NativeCode.mm, rather than being
\r
27 // compiled on its own).
\r
28 #if JUCE_INCLUDED_FILE
\r
32 //==============================================================================
\r
34 using namespace JUCE_NAMESPACE;
\r
36 #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
\r
38 #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
\r
39 @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
\r
41 @interface JuceFileChooserDelegate : NSObject
\r
44 StringArray* filters;
\r
47 - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
\r
49 - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
\r
53 @implementation JuceFileChooserDelegate
\r
54 - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
\r
67 - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
\r
70 const File f (nsStringToJuce (filename));
\r
72 for (int i = filters->size(); --i >= 0;)
\r
73 if (f.getFileName().matchesWildcard ((*filters)[i], true))
\r
76 return f.isDirectory() && ! [[NSWorkspace sharedWorkspace] isFilePackageAtPath: filename];
\r
80 BEGIN_JUCE_NAMESPACE
\r
82 //==============================================================================
\r
83 void FileChooser::showPlatformDialog (Array<File>& results,
\r
84 const String& title,
\r
85 const File& currentFileOrDirectory,
\r
86 const String& filter,
\r
87 bool selectsDirectory,
\r
89 bool isSaveDialogue,
\r
90 bool /*warnAboutOverwritingExistingFiles*/,
\r
91 bool selectMultipleFiles,
\r
92 FilePreviewComponent* /*extraInfoComponent*/)
\r
94 JUCE_AUTORELEASEPOOL
\r
96 StringArray* filters = new StringArray();
\r
97 filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
\r
99 filters->removeEmptyStrings();
\r
101 JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
\r
102 [delegate autorelease];
\r
104 NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
\r
105 : [NSOpenPanel openPanel];
\r
107 [panel setTitle: juceStringToNS (title)];
\r
109 if (! isSaveDialogue)
\r
111 NSOpenPanel* openPanel = (NSOpenPanel*) panel;
\r
112 [openPanel setCanChooseDirectories: selectsDirectory];
\r
113 [openPanel setCanChooseFiles: selectsFiles];
\r
114 [openPanel setAllowsMultipleSelection: selectMultipleFiles];
\r
117 [panel setDelegate: delegate];
\r
119 if (isSaveDialogue || selectsDirectory)
\r
120 [panel setCanCreateDirectories: YES];
\r
122 String directory, filename;
\r
124 if (currentFileOrDirectory.isDirectory())
\r
126 directory = currentFileOrDirectory.getFullPathName();
\r
130 directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
\r
131 filename = currentFileOrDirectory.getFileName();
\r
134 if ([panel runModalForDirectory: juceStringToNS (directory)
\r
135 file: juceStringToNS (filename)]
\r
138 if (isSaveDialogue)
\r
140 results.add (File (nsStringToJuce ([panel filename])));
\r
144 NSOpenPanel* openPanel = (NSOpenPanel*) panel;
\r
145 NSArray* urls = [openPanel filenames];
\r
146 for (unsigned int i = 0; i < [urls count]; ++i)
\r
148 NSString* f = [urls objectAtIndex: i];
\r
149 results.add (File (nsStringToJuce (f)));
\r
154 [panel setDelegate: nil];
\r
159 //==============================================================================
\r
160 void FileChooser::showPlatformDialog (Array<File>& results,
\r
161 const String& title,
\r
162 const File& currentFileOrDirectory,
\r
163 const String& filter,
\r
164 bool selectsDirectory,
\r
166 bool isSaveDialogue,
\r
167 bool warnAboutOverwritingExistingFiles,
\r
168 bool selectMultipleFiles,
\r
169 FilePreviewComponent* extraInfoComponent)
\r
171 JUCE_AUTORELEASEPOOL
\r
173 jassertfalse; //xxx to do
\r