Move window-global key bindings from window object to RootView.

This makes it simpler to discard bindings between specs: just throw away the RootView. It's also more straightforward to call @bindKey on self in the initialization of RootView, rather than binding to document on window.startup.
This commit is contained in:
Nathan Sobo 2011-12-30 13:26:48 -06:00
parent a1e0039890
commit ad024bc1e6
3 changed files with 6 additions and 12 deletions

View File

@ -46,8 +46,3 @@ describe "Window", ->
it "adds a Save item to the main menu after startup", ->
expect(OSX.NSApp.mainMenu.itemWithTitle('File').submenu.itemWithTitle('Save')).not.toBeNull()
describe 'meta+s', ->
it 'saves the buffer', ->
spyOn(window.rootView.editor, 'save')
window.keydown 'meta+s'
expect(window.rootView.editor.save).toHaveBeenCalled()

View File

@ -20,6 +20,11 @@ class RootView extends Template
@subview 'editor', Editor.build()
viewProperties:
initialize: ->
@bindKey 'meta+s', => @editor.save()
@bindKey 'meta+w', => window.close()
@bindKey 'meta+t', => @toggleFileFinder()
addPane: (view) ->
pane = $('<div class="pane">')
pane.append(view)

View File

@ -16,7 +16,6 @@ windowAdditions =
@rootView = RootView.attach()
@rootView.editor.open $atomController.url?.toString()
@registerEventHandlers()
@bindKeys()
@bindMenuItems()
$(window).focus()
@ -24,12 +23,6 @@ windowAdditions =
@rootView.remove()
$(window).unbind('focus')
$(window).unbind('blur')
$(window).unbind('keydown')
bindKeys: ->
$(document).bindKey 'meta+s', => @rootView.editor.save()
$(document).bindKey 'meta+w', => @close()
$(document).bindKey 'meta+t', => @rootView.toggleFileFinder()
bindMenuItems: ->
@bindMenuItem "File > Save", "meta+s", => @rootView.editor.save()
@ -57,3 +50,4 @@ windowAdditions =
for key, value of windowAdditions
console.warn "DOMWindow already has a key named `#{key}`" if window[key]
window[key] = value