2011-08-19 10:07:34 +04:00
|
|
|
console.log = OSX.NSLog
|
|
|
|
|
|
|
|
editor = ace.edit "editor"
|
|
|
|
editor.setTheme "ace/theme/twilight"
|
|
|
|
JavaScriptMode = require("ace/mode/javascript").Mode
|
2011-08-19 10:19:53 +04:00
|
|
|
editor.getSession().setMode new JavaScriptMode
|
2011-08-19 10:07:34 +04:00
|
|
|
|
2011-08-19 10:19:10 +04:00
|
|
|
filename = null
|
|
|
|
save = ->
|
|
|
|
str = OSX.NSString.stringWithString editor.getSession().getValue()
|
|
|
|
str.writeToFile_atomically filename, true
|
|
|
|
|
|
|
|
saveAs = ->
|
|
|
|
panel = OSX.NSSavePanel.savePanel
|
|
|
|
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
|
|
|
|
return null
|
|
|
|
if file = panel.filenames.lastObject
|
|
|
|
filename = file
|
2011-08-19 10:28:14 +04:00
|
|
|
App.window.title = _.last filename.split('/')
|
2011-08-19 10:19:10 +04:00
|
|
|
save()
|
|
|
|
|
2011-08-19 10:07:34 +04:00
|
|
|
canon = require 'pilot/canon'
|
|
|
|
|
|
|
|
bindKey = (name, shortcut, callback) ->
|
|
|
|
canon.addCommand
|
|
|
|
name: name
|
|
|
|
exec: callback
|
|
|
|
bindKey:
|
|
|
|
win: null
|
|
|
|
mac: shortcut
|
|
|
|
sender: 'editor'
|
|
|
|
|
|
|
|
bindKey 'open', 'Command-O', (env, args, request) ->
|
|
|
|
panel = OSX.NSOpenPanel.openPanel
|
|
|
|
|
|
|
|
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
|
|
|
|
return null
|
|
|
|
|
|
|
|
if file = panel.filenames.lastObject
|
2011-08-19 10:19:10 +04:00
|
|
|
filename = file
|
2011-08-19 10:28:14 +04:00
|
|
|
App.window.title = _.last filename.split('/')
|
2011-08-19 10:19:10 +04:00
|
|
|
code = OSX.NSString.stringWithContentsOfFile file
|
|
|
|
env.editor.getSession().setValue code
|
|
|
|
|
|
|
|
bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
|
|
|
|
saveAs()
|
|
|
|
|
|
|
|
bindKey 'save', 'Command-S', (env, args, request) ->
|
|
|
|
if filename then save() else saveAs()
|
2011-08-19 10:07:34 +04:00
|
|
|
|
|
|
|
bindKey 'eval', 'Command-R', (env, args, request) ->
|
|
|
|
eval env.editor.getSession().getValue()
|
|
|
|
|
|
|
|
bindKey 'togglecomment', 'Command-/', (env) ->
|
|
|
|
env.editor.toggleCommentLines()
|
|
|
|
|
|
|
|
bindKey 'fullscreen', 'Command-Return', (env) ->
|
2011-08-19 10:28:14 +04:00
|
|
|
OSX.NSLog 'coming soon'
|