mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Only show menu items for a window/document when it is the key window.
Also add "File > Save" menu item. When document is focused, all menu items associated with its window are added to the main menu. When it is blurred, main menu is reset.
This commit is contained in:
@@ -19,19 +19,26 @@ windowAdditions =
|
||||
@menuItemActions = {}
|
||||
@layout = Layout.attach()
|
||||
@editor = new Editor $atomController.url?.toString()
|
||||
@registerKeydownHandler()
|
||||
@registerEventHandlers()
|
||||
@bindKeys()
|
||||
@bindMenuItems()
|
||||
$(document).focus()
|
||||
|
||||
shutdown: ->
|
||||
@layout.remove()
|
||||
@editor.shutdown()
|
||||
$(document).unbind('focus')
|
||||
$(document).unbind('focus')
|
||||
$(window).unbind('keydown')
|
||||
|
||||
bindKeys: ->
|
||||
@bindKey 'meta+s', => @editor.save()
|
||||
|
||||
bindMenuItems: ->
|
||||
@bindMenuItem "File > Save", => @editor.save()
|
||||
|
||||
bindMenuItem: (path, action) ->
|
||||
@menuItemActions[path] = action
|
||||
atom.native.addMenuItem(path)
|
||||
|
||||
bindKey: (pattern, action) ->
|
||||
@keyBindings[pattern] = action
|
||||
@@ -50,11 +57,18 @@ windowAdditions =
|
||||
patternModifiers.metaKey == event.metaKey and
|
||||
event.which == key.toUpperCase().charCodeAt 0
|
||||
|
||||
registerKeydownHandler: ->
|
||||
registerEventHandlers: ->
|
||||
$(document).bind 'keydown', (event) =>
|
||||
for pattern, action of @keyBindings
|
||||
action() if @keyEventMatchesPattern(event, pattern)
|
||||
|
||||
$(document).focus => @registerMenuItems()
|
||||
$(document).blur -> atom.native.resetMainMenu()
|
||||
|
||||
registerMenuItems: ->
|
||||
for path of @menuItemActions
|
||||
atom.native.addMenuItem(path)
|
||||
|
||||
performActionForMenuItemPath: (path) ->
|
||||
@menuItemActions[path]()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user