Some Objective-C Code Cleanup

This commit is contained in:
LRFLEW 2015-12-17 22:06:07 -06:00
parent 88e67bbae0
commit 8b63080aeb
1 changed files with 30 additions and 39 deletions

View File

@ -79,12 +79,11 @@ void platform_show_messagebox(char *message)
{ {
@autoreleasepool @autoreleasepool
{ {
NSAlert *alert = [[NSAlert alloc] init]; NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"]; [alert addButtonWithTitle:@"OK"];
[alert setMessageText:[NSString stringWithUTF8String:message]]; alert.messageText = [NSString stringWithUTF8String:message];
[alert setAlertStyle:NSWarningAlertStyle]; alert.alertStyle = NSWarningAlertStyle;
[alert runModal]; [alert runModal];
[alert release];
} }
} }
@ -99,8 +98,8 @@ utf8 *platform_open_directory_browser(utf8 *title)
utf8 *url = NULL; utf8 *url = NULL;
if ([panel runModal] == NSFileHandlingPanelOKButton) if ([panel runModal] == NSFileHandlingPanelOKButton)
{ {
NSString *selectedPath = [[[panel URLs] firstObject] path]; NSString *selectedPath = panel.URL.path;
const char *path = [selectedPath UTF8String]; const char *path = selectedPath.UTF8String;
url = (utf8*)malloc(strlen(path) + 1); url = (utf8*)malloc(strlen(path) + 1);
strcpy(url,path); strcpy(url,path);
} }
@ -112,48 +111,40 @@ int platform_open_common_file_dialog(int type, utf8 *title, utf8 *filename, utf8
{ {
@autoreleasepool @autoreleasepool
{ {
NSArray *extensions = [ NSString *fillPatternNS = [NSString stringWithUTF8String:filterPattern];
[ fillPatternNS = [fillPatternNS stringByReplacingOccurrencesOfString:@"*." withString:@""];
[NSString stringWithUTF8String:filterPattern] NSArray *extensions = [fillPatternNS componentsSeparatedByString:@";"];
stringByReplacingOccurrencesOfString:@"*." withString:@""
]
componentsSeparatedByString:@";"
];
NSString *filePath = [NSString stringWithUTF8String:filename]; NSString *filePath = [NSString stringWithUTF8String:filename];
NSString *directory = [filePath stringByDeletingLastPathComponent]; NSString *directory = filePath.stringByDeletingLastPathComponent;
NSString *basename = [filePath lastPathComponent]; NSString *basename = filePath.lastPathComponent;
NSSavePanel *panel;
if (type == 0) if (type == 0)
{ {
NSSavePanel *panel = [NSSavePanel savePanel]; panel = [NSSavePanel savePanel];
panel.title = [NSString stringWithUTF8String:title]; panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject];
panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@",basename,[extensions firstObject]];
panel.allowedFileTypes = extensions;
panel.directoryURL = [NSURL fileURLWithPath:directory];
if ([panel runModal] == NSFileHandlingPanelCancelButton){
return 0;
} else {
strcpy(filename,[[[panel URL] path] UTF8String]);
return 1;
}
} }
else if (type == 1) else if (type == 1)
{ {
NSOpenPanel *panel = [NSOpenPanel openPanel]; NSOpenPanel *open = [NSOpenPanel openPanel];
panel.title = [NSString stringWithUTF8String:title]; open.canChooseDirectories = false;
panel.allowedFileTypes = extensions; open.canChooseFiles = true;
panel.canChooseDirectories = false; open.allowsMultipleSelection = false;
panel.canChooseFiles = true; panel = open;
panel.allowsMultipleSelection = false;
panel.directoryURL = [NSURL fileURLWithPath:filePath];
if ([panel runModal] == NSFileHandlingPanelCancelButton){
return 0;
} else {
strcpy(filename,[[[[panel URLs] firstObject] path] UTF8String]);
return 1;
}
} else { } else {
return 0; return 0;
} }
panel.title = [NSString stringWithUTF8String:title];
panel.allowedFileTypes = extensions;
panel.directoryURL = [NSURL fileURLWithPath:directory];
if ([panel runModal] == NSFileHandlingPanelCancelButton){
return 0;
} else {
strcpy(filename, panel.URL.path.UTF8String);
return 1;
}
} }
} }