Skip to content

Instantly share code, notes, and snippets.

@indexzero
Forked from TooTallNate/cocoa-hello-world2.js
Created September 8, 2011 18:33

Revisions

  1. @TooTallNate TooTallNate revised this gist Sep 8, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cocoa-hello-world2.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // This example adapted from Matt Gallagher's "Minimalist Cocoa Programming"
    // blog article:
    // http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
    var $ = require('./NodObjC')
    var $ = require('NodObjC')

    $.import('Cocoa')

  2. @TooTallNate TooTallNate created this gist Sep 8, 2011.
    51 changes: 51 additions & 0 deletions cocoa-hello-world2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    // This example adapted from Matt Gallagher's "Minimalist Cocoa Programming"
    // blog article:
    // http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
    var $ = require('./NodObjC')

    $.import('Cocoa')

    var pool = $.NSAutoreleasePool('alloc')('init')
    , app = $.NSApplication('sharedApplication')

    app('setActivationPolicy', $.NSApplicationActivationPolicyRegular)

    var menuBar = $.NSMenu('alloc')('init')('autorelease')
    , appMenuItem = $.NSMenuItem('alloc')('init')('autorelease')

    menuBar('addItem', appMenuItem)
    app('setMainMenu', menuBar)

    var appMenu = $.NSMenu('alloc')('init')('autorelease')
    , appName = $._('Hello NodeJS!')
    , quitTitle = $._('Quit ')('stringByAppendingString', appName)
    , quitMenuItem = $.NSMenuItem('alloc')('initWithTitle', quitTitle
    ,'action', 'terminate:'
    ,'keyEquivalent', $._('q'))('autorelease')
    appMenu('addItem', quitMenuItem)
    appMenuItem('setSubmenu', appMenu)

    var styleMask = $.NSTitledWindowMask
    | $.NSResizableWindowMask
    | $.NSClosableWindowMask
    var window = $.NSWindow('alloc')('initWithContentRect', $.NSMakeRect(0,0,200,200)
    ,'styleMask', styleMask
    ,'backing', $.NSBackingStoreBuffered
    ,'defer', false)('autorelease')
    window('cascadeTopLeftFromPoint', $.NSMakePoint(20,20))
    window('setTitle', appName)
    window('makeKeyAndOrderFront', window)

    // set up the app delegate
    var AppDelegate = $.NSObject.extend('AppDelegate')
    AppDelegate.addMethod('applicationDidFinishLaunching:', 'v@:@', function (self, _cmd, notif) {
    console.log('got applicationDidFinishLauching')
    console.log(notif)
    })
    AppDelegate.register()

    var delegate = AppDelegate('alloc')('init')
    app('setDelegate', delegate)

    app('activateIgnoringOtherApps', true)
    app('run')