Skip to content

Instantly share code, notes, and snippets.

@abhibeckert
Created August 7, 2015 03:58
Show Gist options
  • Save abhibeckert/dbeae1ea7716e2f49506 to your computer and use it in GitHub Desktop.
Save abhibeckert/dbeae1ea7716e2f49506 to your computer and use it in GitHub Desktop.
/* example usage in Cocoa Script:
// create a window
var window = [[NSWindow alloc] init]
// create an OK button
var okButton = [[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 100, 100)]
[okButton setTitle:"Continue"]
[okButton sizeToFit]
[okButton setKeyEquivalent:"\r"]
[[window contentView] addSubview:okButton]
//// put more stuff in the window here; text fields, etc ////
// show window, and wait for the OK button to be pressed
var okButtonTarget = [COTarget targetWithAction:function(sender) {
[window orderOut:nil];
[NSApp stopModal];
}]
[okButton setTarget:okButtonTarget]
[okButton setAction:"callAction:"]
// run modal
[NSApp runModalForWindow:window];
*/
#import <Foundation/Foundation.h>
#import "MOJavaScriptObject.h"
#import <CocoaScript/COScript.h>
@interface COTarget : NSObject
@property MOJavaScriptObject *action;
+ (instancetype)targetWithAction:(MOJavaScriptObject *)action;
- (instancetype)initWithAction:(MOJavaScriptObject *)action;
- (void)callAction:(id)sender;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment