-
Notifications
You must be signed in to change notification settings - Fork 68
/
fileDialogMac.m
54 lines (47 loc) · 1.41 KB
/
fileDialogMac.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#import <Foundation/Foundation.h>
#import <MacTypes.h>
#import <AppKit/AppKit.h>
#include "pharovm/fileDialog.h"
#include "pharovm/stringUtilities.h"
#include <string.h>
bool
vm_file_dialog_is_nop(void)
{
return false;
}
VMErrorCode
vm_file_dialog_run_modal_open(VMFileDialog *dialog)
{
NSString *allowedExtension = nil;
if(dialog->filterExtension && dialog->filterExtension[0] == '.')
{
allowedExtension = [NSString stringWithUTF8String: dialog->filterExtension + 1];
}
// No image file is specified. Display the file open dialog.
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.title = [NSString stringWithUTF8String: dialog->title];
panel.message = [NSString stringWithUTF8String: dialog->message];
panel.canChooseFiles = YES;
panel.canChooseDirectories = NO;
panel.allowsMultipleSelection = NO;
if(allowedExtension != nil)
{
panel.allowedFileTypes = [NSArray arrayWithObjects: allowedExtension, nil];
}
dialog->succeeded = false;
dialog->selectedFileName = NULL;
NSInteger clickedButton = [panel runModal];
if(clickedButton == NSModalResponseOK)
{
for (NSURL *url in [panel URLs])
{
if([url isFileURL])
{
dialog->succeeded = true;
dialog->selectedFileName = strdup([url.path UTF8String]);
break;
}
}
}
return VM_SUCCESS;
}