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 55 56 57 58 59 60 61 62 63 64 65 66
|
#import <AppKit/AppKit.h>
#include "open_dialog.h"
char *do_open_rom_dialog(void)
{
@autoreleasepool {
int stderr_fd = dup(STDERR_FILENO);
close(STDERR_FILENO);
NSWindow *key = [NSApp keyWindow];
NSOpenPanel *dialog = [NSOpenPanel openPanel];
dialog.title = @"Open ROM";
dialog.allowedFileTypes = @[@"gb", @"gbc", @"sgb", @"isx"];
if ([dialog runModal] != NSModalResponseOK) return nil;
[key makeKeyAndOrderFront:nil];
NSString *ret = [[[dialog URLs] firstObject] path];
dup2(stderr_fd, STDERR_FILENO);
if (ret) {
return strdup(ret.UTF8String);
}
return NULL;
}
}
char *do_open_folder_dialog(void)
{
@autoreleasepool {
int stderr_fd = dup(STDERR_FILENO);
close(STDERR_FILENO);
NSWindow *key = [NSApp keyWindow];
NSOpenPanel *dialog = [NSOpenPanel openPanel];
dialog.title = @"Select Boot ROMs Folder";
dialog.canChooseDirectories = true;
dialog.canChooseFiles = false;
if ([dialog runModal] != NSModalResponseOK) return nil;
[key makeKeyAndOrderFront:nil];
NSString *ret = [[[dialog URLs] firstObject] path];
dup2(stderr_fd, STDERR_FILENO);
if (ret) {
return strdup(ret.UTF8String);
}
return NULL;
}
}
/* The Cocoa variant of this function isn't as fully featured as the GTK and Windows ones, as Mac users would use
the fully featured Cocoa port of SameBoy anyway*/
char *do_save_recording_dialog(unsigned frequency)
{
@autoreleasepool {
int stderr_fd = dup(STDERR_FILENO);
close(STDERR_FILENO);
NSWindow *key = [NSApp keyWindow];
NSSavePanel *dialog = [NSSavePanel savePanel];
dialog.title = @"Audio recording save location";
dialog.allowedFileTypes = @[@"aiff", @"aif", @"aifc", @"wav", @"raw", @"pcm"];
if ([dialog runModal] != NSModalResponseOK) return nil;
[key makeKeyAndOrderFront:nil];
NSString *ret = [[dialog URL] path];
dup2(stderr_fd, STDERR_FILENO);
if (ret) {
return strdup(ret.UTF8String);
}
return NULL;
}
}
|