bindkey takes a scope, keycap is a method

This commit is contained in:
Corey Johnson
2011-09-20 15:25:36 -07:00
parent 9eee6ad9ad
commit 664fa5b06f
8 changed files with 29 additions and 30 deletions

View File

@@ -16,8 +16,8 @@ class Filefinder extends Pane
html: require "filefinder/filefinder.html"
keymap:
'Command-T': 'toggle'
keymap: ->
'Command-T': @toggle
# really wish i could put up/down keyboad shortcuts here
# and have them activated when the filefinder is open

View File

@@ -13,7 +13,7 @@ class Project extends Pane
html: $ require "project/project.html"
keymap:
keymap: ->
'Command-Ctrl-N': 'toggle'
initialize: ->

View File

@@ -13,7 +13,7 @@ class Tabs extends Pane
# The Editor pane we're managing.
editor: null
keymap:
keymap: ->
'Command-W': 'closeActiveTab'
'Command-Shift-[': 'prevTab'
'Command-Shift-]': 'nextTab'

View File

@@ -9,7 +9,7 @@ File = require 'fs'
module.exports =
class TinyTest extends Pane
keymap:
keymap: ->
'Command-Ctrl-T': 'runTests'
runTests: ->

View File

@@ -16,7 +16,7 @@ class Editor extends Pane
position: 'main'
html: '<div id="editor"></div>'
keymap:
keymap: ->
'Command-S' : 'save'
'Command-Shift-S' : 'saveAs'
'Command-C' : 'copy'

View File

@@ -1,17 +1,26 @@
_ = require 'underscore'
ace = require 'ace/ace'
canon = require 'pilot/canon'
key = require 'keymaster'
exports.bindKey = (name, shortcut, callback) ->
key shortcut, -> callback(); false
exports.bindKey = (scope, shortcut, method) ->
key shortcut, ->
if _.isFunction method
method.apply scope
else
if scope[method]
scope[method]()
else
console.error "keymap: no '#{method}' method found"
false
window.handleKeyEvent = (event) ->
false
# if (event.modifierFlags & OSX.NSCommandKeyMask) and event.keyCode == 50
# console.log "Got Cmd-`"
# true
# else
# false

View File

@@ -1,5 +1,3 @@
_ = require 'underscore'
{bindKey} = require 'keybinder'
module.exports =
@@ -8,22 +6,14 @@ class Pane
html: null
keymap: {}
keymap: ->
constructor: (options={}) ->
for option, value of options
@[option] = value
for shortcut, method of @keymap then do (shortcut, method) =>
bindKey method, shortcut, (args...) =>
console.log "#{shortcut}: #{method}"
if _.isFunction method
method.call this
else
if @[method]
@[method]()
else
console.error "keymap: no '#{method}' method found"
for shortcut, method of @keymap()
bindKey @, shortcut, method
@initialize options

View File

@@ -10,12 +10,12 @@ class Window extends Pane
nswindow: null
panes: []
keymap:
'Command-N' : 'new'
'Command-O' : 'open'
'Command-Shift-O' : 'openURL'
'Command-Ctrl-K' : 'showConsole'
'Command-Ctrl-R' : 'reload'
keymap: ->
'Command-N' : @new
'Command-O' : @open
'Command-Shift-O' : @openURL
'Command-Ctrl-K' : @showConsole
'Command-Ctrl-R' : @reload
constructor: (options={}) ->
super options