Mercurial > dwindows
comparison mac/dw.m @ 1296:40d62db77c90
Added some defpath support and extension support to the Mac dw_file_browse().
Also switched to using URLs instead of deprecated filenames method.
Filename support does not currently work on the open dialog.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 01 Nov 2011 11:55:18 +0000 |
parents | b99b0b2c2826 |
children | 79db0563c7c2 |
comparison
equal
deleted
inserted
replaced
1295:d0c9d4d0ff3b | 1296:40d62db77c90 |
---|---|
3128 { | 3128 { |
3129 if(flags == DW_FILE_OPEN || flags == DW_DIRECTORY_OPEN) | 3129 if(flags == DW_FILE_OPEN || flags == DW_DIRECTORY_OPEN) |
3130 { | 3130 { |
3131 /* Create the File Open Dialog class. */ | 3131 /* Create the File Open Dialog class. */ |
3132 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; | 3132 NSOpenPanel* openDlg = [NSOpenPanel openPanel]; |
3133 struct stat buf; | |
3134 | |
3135 if(defpath && stat(defpath, &buf) == 0) | |
3136 { | |
3137 if(buf.st_mode & S_IFDIR) | |
3138 [openDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:defpath]]]; | |
3139 } | |
3133 | 3140 |
3134 /* Enable the selection of files in the dialog. */ | 3141 /* Enable the selection of files in the dialog. */ |
3135 if(flags == DW_FILE_OPEN) | 3142 if(flags == DW_FILE_OPEN) |
3136 { | 3143 { |
3137 [openDlg setCanChooseFiles:YES]; | 3144 [openDlg setCanChooseFiles:YES]; |
3139 } | 3146 } |
3140 else | 3147 else |
3141 { | 3148 { |
3142 [openDlg setCanChooseFiles:NO]; | 3149 [openDlg setCanChooseFiles:NO]; |
3143 [openDlg setCanChooseDirectories:YES]; | 3150 [openDlg setCanChooseDirectories:YES]; |
3151 } | |
3152 | |
3153 /* Handle file types */ | |
3154 if(ext) | |
3155 { | |
3156 NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; | |
3157 [openDlg setAllowedFileTypes:fileTypes]; | |
3144 } | 3158 } |
3145 | 3159 |
3146 /* Disable multiple selection */ | 3160 /* Disable multiple selection */ |
3147 [openDlg setAllowsMultipleSelection:NO]; | 3161 [openDlg setAllowsMultipleSelection:NO]; |
3148 | 3162 |
3152 if([openDlg runModal] == NSOKButton) | 3166 if([openDlg runModal] == NSOKButton) |
3153 { | 3167 { |
3154 /* Get an array containing the full filenames of all | 3168 /* Get an array containing the full filenames of all |
3155 * files and directories selected. | 3169 * files and directories selected. |
3156 */ | 3170 */ |
3157 NSArray* files = [openDlg filenames]; | 3171 NSArray *files = [openDlg URLs]; |
3158 NSString* fileName = [files objectAtIndex:0]; | 3172 NSString *fileName = [[files objectAtIndex:0] path]; |
3159 return strdup([ fileName UTF8String ]); | 3173 if(fileName) |
3174 return strdup([ fileName UTF8String ]); | |
3160 } | 3175 } |
3161 } | 3176 } |
3162 else | 3177 else |
3163 { | 3178 { |
3164 /* Create the File Save Dialog class. */ | 3179 /* Create the File Save Dialog class. */ |
3165 NSSavePanel* saveDlg = [NSSavePanel savePanel]; | 3180 NSSavePanel* saveDlg = [NSSavePanel savePanel]; |
3181 struct stat buf; | |
3182 | |
3183 if(defpath && stat(defpath, &buf) == 0) | |
3184 { | |
3185 if(buf.st_mode & S_IFDIR) | |
3186 [saveDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:defpath]]]; | |
3187 else | |
3188 [saveDlg setNameFieldStringValue:[NSString stringWithUTF8String:defpath]]; | |
3189 } | |
3166 | 3190 |
3167 /* Enable the creation of directories in the dialog. */ | 3191 /* Enable the creation of directories in the dialog. */ |
3168 [saveDlg setCanCreateDirectories:YES]; | 3192 [saveDlg setCanCreateDirectories:YES]; |
3169 | 3193 |
3194 /* Handle file types */ | |
3195 if(ext) | |
3196 { | |
3197 NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil]; | |
3198 [saveDlg setAllowedFileTypes:fileTypes]; | |
3199 } | |
3200 | |
3170 /* Display the dialog. If the OK button was pressed, | 3201 /* Display the dialog. If the OK button was pressed, |
3171 * process the files. | 3202 * process the files. |
3172 */ | 3203 */ |
3173 if([saveDlg runModal] == NSFileHandlingPanelOKButton) | 3204 if([saveDlg runModal] == NSFileHandlingPanelOKButton) |
3174 { | 3205 { |
3175 /* Get an array containing the full filenames of all | 3206 /* Get an array containing the full filenames of all |
3176 * files and directories selected. | 3207 * files and directories selected. |
3177 */ | 3208 */ |
3178 NSString* fileName = [saveDlg filename]; | 3209 NSString* fileName = [[saveDlg URL] path]; |
3179 return strdup([ fileName UTF8String ]); | 3210 if(fileName) |
3211 return strdup([ fileName UTF8String ]); | |
3180 } | 3212 } |
3181 } | 3213 } |
3182 | 3214 |
3183 return NULL; | 3215 return NULL; |
3184 } | 3216 } |