Implemented OpenFile() on Mac OS X.

This commit is contained in:
Pietro Gagliardi 2014-08-19 12:44:42 -04:00
parent bed2a4eeb5
commit fa3dff4d46
4 changed files with 53 additions and 0 deletions

19
redo/dialog_darwin.go Normal file
View File

@ -0,0 +1,19 @@
// 19 august 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
func openFile() string {
fname := C.openFile()
if fname == nil {
return ""
}
defer C.free(unsafe.Pointer(fname))
return C.GoString(fname)
}

29
redo/dialog_darwin.m Normal file
View File

@ -0,0 +1,29 @@
// 19 august 2014
#import "objc_darwin.h"
#import <Cocoa/Cocoa.h>
char *openFile(void)
{
NSOpenPanel *op;
NSInteger ret;
op = [NSOpenPanel openPanel];
[op setCanChooseFiles:YES];
[op setCanChooseDirectories:NO];
[op setResolvesAliases:NO];
[op setAllowsMultipleSelection:NO];
[op setShowsHiddenFiles:YES];
[op setCanSelectHiddenExtension:NO];
[op setExtensionHidden:NO];
[op setAllowsOtherFileTypes:YES];
[op setTreatsFilePackagesAsDirectories:YES];
// disable custom events
// TODO doesn't seem to work
dispatch_suspend(dispatch_get_main_queue());
ret = [op runModal];
dispatch_resume(dispatch_get_main_queue());
if (ret != NSFileHandlingPanelOKButton)
return NULL;
return strdup([[[op URL] path] UTF8String]);
}

View File

@ -1,3 +1,5 @@
// +build !windows,!darwin
// 19 august 2014
package ui

View File

@ -128,4 +128,7 @@ extern void disableAutocorrect(id);
/* imagerep_darwin.m */
extern id toImageListImage(void *, intptr_t, intptr_t, intptr_t);
/* dialog_darwin.m */
extern char *openFile(void);
#endif