Files
atom/HTML/osx.coffee
2011-08-19 01:09:47 -07:00

61 lines
1.6 KiB
CoffeeScript

# This is the CoffeeScript API that wraps all of Cocoa.
canon = require 'pilot/canon'
# Handles the UI chrome
Chrome =
# Returns null or a file path.
openPanel: ->
panel = OSX.NSOpenPanel.openPanel
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
return null
panel.filenames.lastObject
# Returns null or a file path.
savePanel: ->
panel = OSX.NSSavePanel.savePane
if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
return null
panel.filenames.lastObject
writeToPasteboard: (text) ->
pb = OSX.NSPasteboard.generalPasteboard
pb.declareTypes_owner [OSX.NSStringPboardType], null
pb.setString_forType text, OSX.NSStringPboardType
# name - Command name, like "Find in file"
# shortcut - String command name, e.g.
# "Command-T"
# "Command-Shift-F"
# "Ctrl-I"
# callback - (env, args, request)
#
# Returns nothing.
bindKey: (name, shortcut, callback) ->
canon.addCommand
name: name
exec: callback
bindKey:
win: null
mac: shortcut
sender: 'editor'
title: (text) ->
App.mainWindow.title = text
fullscreen: ->
OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
App.mainWindow.orderOut(null)
#if mainWindow.screen.isEqual(OSX.NSScreen.screens.objectAtIndex(0)
# Handles the file system
File =
read: (path) ->
OSX.NSString.stringWithContentsOfFile path
write: (path, contents) ->
str = OSX.NSString.stringWithString contents
str.writeToFile_atomically path, true
this.Chrome = Chrome
this.File = File