Implemented OpenFile() on Mac OS X.
This commit is contained in:
parent
bed2a4eeb5
commit
fa3dff4d46
|
@ -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)
|
||||
}
|
|
@ -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]);
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// +build !windows,!darwin
|
||||
|
||||
// 19 august 2014
|
||||
|
||||
package ui
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue