mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
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:
parent
a1e0039890
commit
ad024bc1e6
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user