pulsar/HTML/atomicity.coffee

124 lines
3.4 KiB
CoffeeScript
Raw Normal View History

2011-08-19 12:48:51 +04:00
Chrome.init()
2011-08-19 10:07:34 +04:00
editor = ace.edit "editor"
editor.setTheme "ace/theme/twilight"
JavaScriptMode = require("ace/mode/javascript").Mode
CoffeeMode = require("ace/mode/coffee").Mode
2011-08-23 10:48:51 +04:00
HTMLMode = require("ace/mode/html").Mode
2011-08-19 10:19:53 +04:00
editor.getSession().setMode new JavaScriptMode
2011-08-19 10:35:10 +04:00
editor.getSession().setUseSoftTabs true
editor.getSession().setTabSize 2
2011-08-19 10:07:34 +04:00
if css = File.read "~/.atomicity/twilight.css"
head = $('head')[0]
style = document.createElement 'style'
rules = document.createTextNode css
style.type = 'text/css'
style.appendChild rules
head.appendChild style
_.map Dir.list("~/.atomicity/"), (path) ->
if /\.js$/.test path
$.getScript path
else if /\.coffee/.test path
eval CoffeeScript.compile File.read path
2011-08-19 10:19:10 +04:00
filename = null
2011-08-23 08:24:56 +04:00
editor.getSession().on 'change', ->
Chrome.setDirty true
2011-08-19 10:19:10 +04:00
save = ->
2011-08-19 10:46:35 +04:00
File.write filename, editor.getSession().getValue()
setMode()
2011-08-23 08:24:56 +04:00
Chrome.setDirty false
open = ->
2011-08-23 21:34:56 +04:00
if /png|jpe?g|gif/i.test filename
Chrome.openURL filename
else
Chrome.title _.last filename.split('/')
editor.getSession().setValue File.read filename
setMode()
Chrome.setDirty false
setMode = ->
if /\.js$/.test filename
editor.getSession().setMode new JavaScriptMode
else if /\.coffee$/.test filename
editor.getSession().setMode new CoffeeMode
2011-08-23 10:48:51 +04:00
else if /\.html/.test filename
editor.getSession().setMode new HTMLMode
2011-08-19 10:19:10 +04:00
saveAs = ->
2011-08-19 10:46:35 +04:00
if file = Chrome.savePanel()
2011-08-19 10:19:10 +04:00
filename = file
2011-08-19 12:09:47 +04:00
Chrome.title _.last filename.split('/')
2011-08-19 10:19:10 +04:00
save()
2011-08-19 10:55:27 +04:00
Chrome.bindKey 'open', 'Command-O', (env, args, request) ->
2011-08-19 10:46:35 +04:00
if file = Chrome.openPanel()
2011-08-23 10:57:51 +04:00
filename = file
open()
2011-08-19 10:19:10 +04:00
2011-08-23 21:37:02 +04:00
Chrome.bindKey 'openURL', 'Command-Shift-O', (env, args, request) ->
if url = prompt "Enter URL:"
Chrome.openURL url
2011-08-19 10:55:27 +04:00
Chrome.bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
2011-08-19 10:19:10 +04:00
saveAs()
2011-08-19 10:55:27 +04:00
Chrome.bindKey 'save', 'Command-S', (env, args, request) ->
2011-08-19 10:19:10 +04:00
if filename then save() else saveAs()
2011-08-19 10:07:34 +04:00
2011-08-23 10:33:52 +04:00
Chrome.bindKey 'new', 'Command-N', (env, args, request) ->
Chrome.createWindow()
2011-08-19 10:55:27 +04:00
Chrome.bindKey 'copy', 'Command-C', (env, args, request) ->
2011-08-19 10:33:59 +04:00
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
2011-08-19 10:46:35 +04:00
Chrome.writeToPasteboard text
2011-08-19 10:33:59 +04:00
2011-08-19 13:34:17 +04:00
Chrome.bindKey 'cut', 'Command-X', (env, args, request) ->
text = editor.getSession().doc.getTextRange editor.getSelectionRange()
Chrome.writeToPasteboard text
editor.session.remove editor.getSelectionRange()
2011-08-19 10:55:27 +04:00
Chrome.bindKey 'eval', 'Command-R', (env, args, request) ->
2011-08-19 10:07:34 +04:00
eval env.editor.getSession().getValue()
# textmate
2011-08-19 10:55:27 +04:00
Chrome.bindKey 'togglecomment', 'Command-/', (env) ->
2011-08-19 10:07:34 +04:00
env.editor.toggleCommentLines()
2011-08-19 13:34:17 +04:00
Chrome.bindKey 'tmoutdent', 'Command-[', (env) ->
env.editor.blockOutdent()
2011-08-23 10:57:51 +04:00
2011-08-19 13:34:17 +04:00
Chrome.bindKey 'tmindent', 'Command-]', (env) ->
env.editor.indent()
# emacs > you
Chrome.bindKey 'moveforward', 'Alt-F', (env) ->
env.editor.navigateWordRight()
Chrome.bindKey 'moveback', 'Alt-B', (env) ->
env.editor.navigateWordLeft()
Chrome.bindKey 'deleteword', 'Alt-D', (env) ->
env.editor.removeWordRight()
Chrome.bindKey 'selectwordright', 'Alt-B', (env) ->
env.editor.navigateWordLeft()
2011-08-19 12:10:50 +04:00
Chrome.bindKey 'home', 'Alt-Shift-,', (env) ->
2011-08-19 12:09:47 +04:00
env.editor.navigateFileStart()
2011-08-19 12:10:50 +04:00
Chrome.bindKey 'end', 'Alt-Shift-.', (env) ->
2011-08-19 12:09:47 +04:00
env.editor.navigateFileEnd()
Chrome.bindKey 'fullscreen', 'Command-Shift-Return', (env) ->
2011-08-19 12:33:21 +04:00
Chrome.toggleFullscreen()
# HAX
# this should go in coffee.coffee or something
Chrome.bindKey 'consolelog', 'Ctrl-L', (env) ->
env.editor.insert 'console.log ""'
env.editor.navigateLeft()