Skip to content

Instantly share code, notes, and snippets.

@shannah
Created October 6, 2012 21:02
Show Gist options
  • Save shannah/3846116 to your computer and use it in GitHub Desktop.
Save shannah/3846116 to your computer and use it in GitHub Desktop.
JNI method that crashes
JNIEXPORT jstring JNICALL Java_ca_weblite_mactools_Sandbox_saveDialog
(JNIEnv *env, jobject jthis, jstring title, jstring extension){
JNF_COCOA_ENTER(env);
jstring path;
//@autoreleasepool {
NSString *cocoaExtension = JNFJavaToNSString(env, extension);
NSSavePanel *panel = [NSSavePanel savePanel];
NSArray *types = [NSArray arrayWithObjects: cocoaExtension,nil];
[panel setAllowedFileTypes: types];
[panel setCanSelectHiddenExtension:TRUE];
[panel setExtensionHidden:TRUE];
[panel setTitle: JNFJavaToNSString(env, title)];
if ( [panel runModal] == NSFileHandlingPanelOKButton ){
NSURL * out = [[panel URL] filePathURL];
NSString *outStr = [out path];
const char *cString = [outStr UTF8String];
path = (*env)->NewStringUTF(env, cString);
} else {
path = NULL;
}
//}
return path;
JNF_COCOA_EXIT(env);
}
JNIEXPORT jstring JNICALL Java_ca_weblite_mactools_Sandbox_saveDialog
(JNIEnv *env, jobject jthis, jstring title, jstring extension){
//JNF_COCOA_ENTER(env);
jstring path;
@autoreleasepool {
NSString *cocoaExtension = JNFJavaToNSString(env, extension);
NSSavePanel *panel = [NSSavePanel savePanel];
NSArray *types = [NSArray arrayWithObjects: cocoaExtension,nil];
[panel setAllowedFileTypes: types];
[panel setCanSelectHiddenExtension:TRUE];
[panel setExtensionHidden:TRUE];
[panel setTitle: JNFJavaToNSString(env, title)];
if ( [panel runModal] == NSFileHandlingPanelOKButton ){
NSURL * out = [[panel URL] filePathURL];
NSString *outStr = [out path];
const char *cString = [outStr UTF8String];
path = (*env)->NewStringUTF(env, cString);
} else {
path = NULL;
}
}
return path;
//JNF_COCOA_EXIT(env);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment