atom.keybinder

This commit is contained in:
Chris Wanstrath
2011-11-09 12:26:37 -08:00
parent 27f4736fd3
commit 6f1d4a8cc8
8 changed files with 25 additions and 31 deletions

View File

@@ -1,11 +1,10 @@
KeyBinder = require 'key-binder'
fs = require 'fs'
require 'window'
module.exports =
class App
constructor: ->
KeyBinder.register "app", @
atom.keybinder.register "app", @
window.startup()
open: (path) ->

View File

@@ -3,7 +3,6 @@ _ = require 'underscore'
fs = require 'fs'
ace = require 'ace/ace'
KeyBinder = require 'key-binder'
Storage = require 'storage'
Pane = require 'pane'
@@ -25,7 +24,7 @@ class Editor extends Pane
position: "main"
constructor: ->
KeyBinder.register "editor", @
atom.keybinder.register "editor", @
@show()

View File

@@ -5,14 +5,14 @@ Watcher = require 'watcher'
module.exports =
class KeyBinder
@bindings: {}
bindings: {}
@scopes: {}
scopes: {}
@register: (name, scope) ->
register: (name, scope) ->
@scopes[name] = scope
@load: (path) ->
load: (path) ->
try
Watcher.watch path, =>
# Should we keep track of which file bindings are associated with? That
@@ -27,7 +27,7 @@ class KeyBinder
catch error
console.error "#{@name}: Could not load key bindings at `#{path}`. #{error}"
@create: (scope, binding, method) ->
create: (scope, binding, method) ->
if typeof scope is "string"
throw "#{@name}: Unknown scope `#{scope}`" unless @scopes[scope]
scope = @scopes[scope]
@@ -43,7 +43,7 @@ class KeyBinder
callbacks.push callback
@handleEvent: (event) ->
handleEvent: (event) ->
keys = []
keys.push @modifierKeys.command if event.modifierFlags & OSX.NSCommandKeyMask
keys.push @modifierKeys.shift if event.modifierFlags & OSX.NSShiftKeyMask
@@ -67,7 +67,7 @@ class KeyBinder
true
@bindingParser: (binding) ->
bindingParser: (binding) ->
keys = binding.trim().split '-'
modifiers = []
@@ -88,7 +88,7 @@ class KeyBinder
modifiers.concat(key).sort().join "-"
@bindingFromAscii: (binding) ->
bindingFromAscii: (binding) ->
inverseModifierKeys = {}
inverseModifierKeys[number] = label for label, number of @modifierKeys
@@ -106,7 +106,7 @@ class KeyBinder
keys.join '-'
@modifierKeys:
modifierKeys:
'': 16
'': 91
'': 18
@@ -118,7 +118,7 @@ class KeyBinder
command: 91
cmd: 91
@namedKeys:
namedKeys:
backspace: 8
tab: 9
clear: 12

View File

@@ -3,8 +3,11 @@
App = require 'app'
Event = require 'event'
Native = require 'native'
KeyBinder = require 'key-binder'
window.atom = {}
window.atom.native = new Native
window.atom.event = new Event
window.atom.keybinder = new KeyBinder
window.atom.app = new App

View File

@@ -1,8 +1,6 @@
Browser = require 'browser'
Editor = require 'editor'
Extension = require 'extension'
KeyBinder = require 'key-binder'
Native = require 'native'
Storage = require 'storage'
fs = require 'fs'
@@ -22,7 +20,7 @@ windowAdditions =
path: null
startup: () ->
KeyBinder.register "window", window
atom.keybinder.register "window", window
@path = $atomController.path
@setTitle _.last @path.split '/'
@@ -79,9 +77,9 @@ windowAdditions =
atom.event.trigger 'extensions:loaded'
loadKeyBindings: ->
KeyBinder.load "#{@appRoot}/static/key-bindings.coffee"
atom.keybinder.load "#{@appRoot}/static/key-bindings.coffee"
if fs.isFile "~/.atomicity/key-bindings.coffee"
KeyBinder.load "~/.atomicity/key-bindings.coffee"
atom.keybinder.load "~/.atomicity/key-bindings.coffee"
loadSettings: ->
if fs.isFile "~/.atomicity/settings.coffee"
@@ -108,7 +106,7 @@ windowAdditions =
atom.event.trigger 'window:close', path
handleKeyEvent: ->
KeyBinder.handleEvent.apply KeyBinder, arguments
atom.keybinder.handleEvent.apply atom.keybinder, arguments
triggerEvent: ->
atom.event.trigger arguments...