Skip to content

Commit

Permalink
Merge pull request #71 from mralexgray/scripting
Browse files Browse the repository at this point in the history
Additional built-in framework search paths.
  • Loading branch information
trevorlinton committed Oct 11, 2015
2 parents abd4c9a + 75df3aa commit e4e3e2f
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 32 deletions.
180 changes: 148 additions & 32 deletions examples/NodeCocoaHelloWorld.app/Contents/MacOS/app.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,177 @@
// // This example adapted from Matt Gallagher's "Minimalist Cocoa Programming"
// // blog article:
// // http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
// var $ = require('../../../../')
// var EventLoop = require('../../../EventLoop')
// EventLoop.initObjC($)
//
// $.import('Cocoa')
//
// var pool = $.NSAutoreleasePool('alloc')('init')
// , app = $.NSApplication('sharedApplication')
// , evtLoop = new EventLoop()
//
// app('setActivationPolicy', $.NSApplicationActivationPolicyRegular)
//
// var menuBar = $.NSMenu('alloc')('init')
// , appMenuItem = $.NSMenuItem('alloc')('init')
//
// menuBar('addItem', appMenuItem)
// app('setMainMenu', menuBar)
//
// var appMenu = $.NSMenu('alloc')('init')
// , appName = $('Hello NodeJS!')
// , quitTitle = $('Quit "' + appName + '"')
// , quitMenuItem = $.NSMenuItem('alloc')('initWithTitle', quitTitle
// ,'action', 'terminate:'
// ,'keyEquivalent', $('q'))
// 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)
// window('setAlphaValue', 0)
// window('cascadeTopLeftFromPoint', $.NSMakePoint(20,20))
// window('setTitle', appName)
// window('makeKeyAndOrderFront', window)
// window('center')
// window('setBackgroundColor', $.NSColor('greenColor'))
// window('animator')('setAlphaValue',1)
//
//
//
//
// var textV = $.NSTextView('alloc')('initWithFrame', $.NSMakeRect(0,100,100,100));
// textV('setAutoresizingMask', $.NSViewWidthSizable | $.NSViewMinYMargin)
// window('contentView')('addSubview', textV)
//
// // AppDelegate.addMethod('textDidChange:', 'v@:@', function (self, _cmd, notif) {
// // $.playTrumpet()
// // })
//
//
// // 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.addMethod('applicationWillTerminate:', 'v@:@', function (self, _cmd, notif) {
// console.log('got applicationWillTerminate')
// console.log(notif)
// })
// AppDelegate.register()
//
// var delegate = AppDelegate('alloc')('init')
// app('setDelegate', delegate)
//
// app('activateIgnoringOtherApps', true)
// app('finishLaunching')
//
// evtLoop.start()



// This example adapted from Matt Gallagher's "Minimalist Cocoa Programming"
// blog article:
// http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
var $ = require('../../../../')
var EventLoop = require('../../../EventLoop')
EventLoop.initObjC($)

$.import('Cocoa')
$.framework('Cocoa')
// $.framework('AtoZ')
// $.import('AppKit')
// $.import('AtoZ')

var pool = $.NSAutoreleasePool('alloc')('init')
, app = $.NSApplication('sharedApplication')
, evtLoop = new EventLoop()
var pool = $.NSAutoreleasePool('alloc')('init'),
app = $.NSApplication('sharedApplication')
// atoz = $.AtoZ

// var z = atoz.methods()
// $.NSLog(atoz('class')('globalPalette')('stringValue'))

app('setActivationPolicy', $.NSApplicationActivationPolicyRegular)

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

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

var appMenu = $.NSMenu('alloc')('init')
, appName = $('Hello NodeJS!')
, quitTitle = $('Quit "' + appName + '"')
, quitMenuItem = $.NSMenuItem('alloc')('initWithTitle', quitTitle
,'action', 'terminate:'
,'keyEquivalent', $('q'))
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)
var appMenu = $.NSMenu('new'),
appName = $('Hello NodeJS!'),
quitTitle = $('Quit "' + appName + '"'),
quitMenuItem = $.NSMenuItem('alloc')('initWithTitle', quitTitle, 'action', 'terminate:', 'keyEquivalent', $('q')),
AppDelegate = $.NSObject.extend('AppDelegate') // set up the app delegate

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)
window('setAlphaValue', 0)
window('cascadeTopLeftFromPoint', $.NSMakePoint(20,20))
window('setTitle', appName)
window('makeKeyAndOrderFront', window)
window('center')
window('setBackgroundColor', $.NSColor('greenColor'))
window('animator')('setAlphaValue',1)

var textV = $.NSTextView('alloc')('initWithFrame', $.NSMakeRect(0,100,100,100));
textV('setAutoresizingMask', $.NSViewWidthSizable | $.NSViewMinYMargin)
window('contentView')('addSubview', textV)

AppDelegate.addMethod('textDidChange:', 'v@:@', function (self, _cmd, notif) {
$.playTrumpet()
})


// 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)
// console.log('got applicationDidFinishLauching')
// console.log(notif)
})
AppDelegate.addMethod('applicationWillTerminate:', 'v@:@', function (self, _cmd, notif) {
console.log('got applicationWillTerminate')
console.log(notif)
})
AppDelegate.addMethod('windowDidMove:', 'v@:@', function (self, _cmd, notif) {
var x = window('backgroundColor')
window('setBackgroundColor', x == $.NSColor('purpleColor') ? $.NSColor('redColor') : $.NSColor('blueColor'))
})
AppDelegate.addMethod('windowDidResize:', 'v@:@', function (self, _cmd, notif) {
if ((notif('object')('width') % 100) < 10) {
window('animator')('setBackgroundColor', $.AtoZ('globalPalette')('nextNormalObject'))
// $.AZTalker('randomDicksonism')
// ($.NSString('randomDicksonism'))
}
})


AppDelegate.register()

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

textV('setDelegate',delegate)
app('setDelegate', delegate)
window('setDelegate', delegate)
app('activateIgnoringOtherApps', true)
app('finishLaunching')
// var azb = $.getenv('AZBUILD')
// $.NSLog('%@','vageem')
// console.error('vageem')
// var array = $.NSMutableArray('alloc')('init')
// array('addObject', $('Hello World!'))
// console.log(array)

// var jsString = 'a javascript String'
// var nsString = $(jsString)
// $.NSLog(nsString)

evtLoop.start()
// window('setBackgroundColor', $.NSColor('purpleColor')
app('run')
2 changes: 2 additions & 0 deletions lib/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = (function() {
, PATH = [
'/System/Library/Frameworks'
, '/System/Library/PrivateFrameworks'
, '/Library/Frameworks'
, process.env['HOME'] + '/Library/Frameworks'
]
, join = path.join
, exists = fs.existsSync || path.existsSync
Expand Down

0 comments on commit e4e3e2f

Please sign in to comment.