@@ -204,48 +204,6 @@ static MCPlatformDialogResult MCPlatformEndOpenSaveDialog(void)
204204
205205// //////////////////////////////////////////////////////////////////////////////
206206
207- void MCPlatformBeginFolderDialog (MCPlatformWindowRef p_owner, MCStringRef p_title, MCStringRef p_prompt, MCStringRef p_initial)
208- {
209- MCAutoStringRef t_initial_folder;
210-
211- if (p_initial != nil )
212- /* UNCHECKED */ folder_path_from_initial_path (p_initial, &t_initial_folder);
213-
214- NSOpenPanel *t_panel;
215- t_panel = [NSOpenPanel openPanel ];
216- // If we have both a title and a message, then 'title' is used on setTitle, and 'prompt' is used for message.
217- // If there is no title, then on 10.11+ we must use the message field of the dialog; on <10.11 we must use the title field
218- if (p_title != nil && MCStringGetLength (p_title) != 0 )
219- {
220- [t_panel setTitle: [NSString stringWithMCStringRef: p_title]];
221- [t_panel setMessage: [NSString stringWithMCStringRef: p_prompt]];
222- }
223- else
224- {
225- extern uint4 MCmajorosversion;
226- if (MCmajorosversion >= 0x10B0 )
227- [t_panel setMessage: [NSString stringWithMCStringRef: p_prompt]];
228- else
229- [t_panel setTitle: [NSString stringWithMCStringRef: p_prompt]];
230-
231- }
232- [t_panel setPrompt: @" Choose" ];
233- [t_panel setCanChooseFiles: NO ];
234- [t_panel setCanChooseDirectories: YES ];
235- [t_panel setAllowsMultipleSelection: NO ];
236-
237- // MM-2012-03-01: [[ BUG 10046]] Make sure the "new folder" button is enabled for folder dialogs
238- [t_panel setCanCreateDirectories: YES ];
239-
240- if ([t_panel respondsToSelector: @selector (isAccessoryViewDisclosed )])
241- {
242- // show accessory view when dialog opens
243- [t_panel setAccessoryViewDisclosed: YES ];
244- }
245-
246- MCMacPlatformBeginOpenSaveDialog (p_owner, t_panel, *t_initial_folder, nil );
247- }
248-
249207MCPlatformDialogResult MCPlatformEndFolderDialog (MCStringRef& r_selected_folder)
250208{
251209 if (s_dialog_nesting -> result == kMCPlatformDialogResultContinue )
@@ -605,70 +563,82 @@ - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
605563
606564// //////////////////////////////////////////////////////////////////////////////
607565
608- void MCPlatformBeginFileDialog (MCPlatformFileDialogKind p_kind, MCPlatformWindowRef p_owner, MCStringRef p_title, MCStringRef p_prompt, MCStringRef *p_types, uint4 p_type_count, MCStringRef p_initial)
566+ void MCPlatformBeginFolderOrFileDialog (MCPlatformFileDialogKind p_kind, MCPlatformWindowRef p_owner, MCStringRef p_title, MCStringRef p_prompt, MCStringRef *p_types, uint4 p_type_count, MCStringRef p_initial, bool p_is_file )
609567{
610- MCAutoStringRef t_initial_folder;
611- if (p_initial != nil )
612- /* UNCHECKED */ folder_path_from_initial_path (p_initial, &t_initial_folder);
613-
614- MCAutoStringRef t_initial_file;
615- if ((p_kind == kMCPlatformFileDialogKindSave ) && p_initial != nil && !MCS_exists (p_initial, false ))
616- {
617- uindex_t t_last_slash;
568+ MCAutoStringRef t_initial_folder;
569+ if (p_initial != nil )
570+ /* UNCHECKED */ folder_path_from_initial_path (p_initial, &t_initial_folder);
571+
572+ MCAutoStringRef t_initial_file;
573+ if ((p_kind == kMCPlatformFileDialogKindSave ) && p_initial != nil && !MCS_exists (p_initial, false ))
574+ {
575+ uindex_t t_last_slash;
618576 if (MCStringLastIndexOfChar (p_initial, ' /' , UINT32_MAX, kMCStringOptionCompareExact , t_last_slash))
619577 // SN-2014-08-11: [[ Bug 13143 ]] Take the right part: after the last slash, not before
620578 MCStringCopySubstring (p_initial, MCRangeMake (t_last_slash + 1 , MCStringGetLength (p_initial) - t_last_slash - 1 ), &t_initial_file);
621579 else
622580 t_initial_file = p_initial;
623- }
624-
625- NSSavePanel *t_panel;
626- t_panel = (p_kind == kMCPlatformFileDialogKindSave ) ? [NSSavePanel savePanel ] : [NSOpenPanel openPanel ] ;
627-
628- if (p_title != nil && !MCStringIsEmpty (p_title))
629- {
630- [t_panel setTitle: [NSString stringWithMCStringRef: p_title]];
631- [t_panel setMessage: [NSString stringWithMCStringRef: p_prompt]];
632- }
633- else
634- {
635- extern uint4 MCmajorosversion;
636- if (MCmajorosversion >= 0x10B0 && p_kind != kMCPlatformFileDialogKindSave )
637- [t_panel setMessage: [NSString stringWithMCStringRef: p_prompt]];
638- else
639- [t_panel setTitle: [NSString stringWithMCStringRef: p_prompt]];
640- }
641-
642- // MW-2014-07-17: [[ Bug 12826 ]] If we have at least one type, add a delegate. Only add as
643- // an accessory view if more than one type.
644- MCFileDialogAccessoryView *t_accessory;
645- if (p_type_count > 0 )
581+ }
582+
583+ NSSavePanel *t_panel;
584+ t_panel = (p_kind == kMCPlatformFileDialogKindSave ) ? [NSSavePanel savePanel ] : [NSOpenPanel openPanel ] ;
585+
586+ // If we have both a title and a message, then 'title' is used on setTitle, and 'prompt' is used for message.
587+ // If there is no title, then on 10.11+ we must use the message field of the dialog; on <10.11 we must use the title field
588+ if (p_title != nil && !MCStringIsEmpty (p_title))
646589 {
647- t_accessory = [[MCFileDialogAccessoryView alloc ] initWithPanel: t_panel];
648- [t_accessory setTypes: p_types length: p_type_count];
649- [t_accessory setLabel: @" Format:" ];
650- if (p_type_count > 1 )
651- [t_panel setAccessoryView: t_accessory];
652- [t_panel setDelegate: t_accessory];
653- }
590+ [t_panel setTitle: [NSString stringWithMCStringRef: p_title]];
591+ [t_panel setMessage: [NSString stringWithMCStringRef: p_prompt]];
592+ }
593+ else
594+ {
595+ extern uint4 MCmajorosversion;
596+ if (MCmajorosversion >= 0x10B0 && p_kind != kMCPlatformFileDialogKindSave )
597+ [t_panel setMessage: [NSString stringWithMCStringRef: p_prompt]];
598+ else
599+ [t_panel setTitle: [NSString stringWithMCStringRef: p_prompt]];
600+ }
654601
655- if (p_kind != kMCPlatformFileDialogKindSave )
656- {
657- [(NSOpenPanel *)t_panel setCanChooseFiles: YES ];
658- [(NSOpenPanel *)t_panel setCanChooseDirectories: NO ];
659- [(NSOpenPanel *)t_panel setAllowsMultipleSelection: p_kind == kMCPlatformFileDialogKindOpenMultiple ? YES : NO ];
660- }
661- // MM-2012-03-01: [[ BUG 10046]] Make sure the "new folder" button is enabled for save dialogs
662- else
663- [t_panel setCanCreateDirectories: YES ];
664-
665- if ([t_panel respondsToSelector: @selector (isAccessoryViewDisclosed )])
666- {
667- // show accessory view when dialog opens
668- [t_panel setAccessoryViewDisclosed: YES ];
669- }
670-
671- MCMacPlatformBeginOpenSaveDialog (p_owner, t_panel, *t_initial_folder, *t_initial_file);
602+ if (p_is_file)
603+ {
604+ // MW-2014-07-17: [[ Bug 12826 ]] If we have at least one type, add a delegate. Only add as
605+ // an accessory view if more than one type.
606+ MCFileDialogAccessoryView *t_accessory;
607+ if (p_type_count > 0 )
608+ {
609+ t_accessory = [[MCFileDialogAccessoryView alloc ] initWithPanel: t_panel];
610+ [t_accessory setTypes: p_types length: p_type_count];
611+ [t_accessory setLabel: @" Format:" ];
612+ if (p_type_count > 1 )
613+ [t_panel setAccessoryView: t_accessory];
614+ [t_panel setDelegate: t_accessory];
615+ }
616+
617+ if (p_kind != kMCPlatformFileDialogKindSave )
618+ {
619+ [(NSOpenPanel *)t_panel setCanChooseFiles: YES ];
620+ [(NSOpenPanel *)t_panel setCanChooseDirectories: NO ];
621+ [(NSOpenPanel *)t_panel setAllowsMultipleSelection: p_kind == kMCPlatformFileDialogKindOpenMultiple ? YES : NO ];
622+ }
623+ // MM-2012-03-01: [[ BUG 10046]] Make sure the "new folder" button is enabled for save dialogs
624+ else
625+ [t_panel setCanCreateDirectories: YES ];
626+ }
627+ else
628+ {
629+ [t_panel setPrompt: @" Choose" ];
630+ [t_panel setCanChooseFiles: NO ];
631+ [t_panel setCanChooseDirectories: YES ];
632+ [t_panel setAllowsMultipleSelection: NO ];
633+ }
634+
635+ if ([t_panel respondsToSelector: @selector (isAccessoryViewDisclosed )])
636+ {
637+ // show accessory view when dialog opens
638+ [t_panel setAccessoryViewDisclosed: YES ];
639+ }
640+
641+ MCMacPlatformBeginOpenSaveDialog (p_owner, t_panel, *t_initial_folder, p_is_file ? *t_initial_file : nil );
672642}
673643
674644MCPlatformDialogResult MCPlatformEndFileDialog (MCPlatformFileDialogKind p_kind, MCStringRef &r_paths, MCStringRef &r_type)
0 commit comments