Merge pull request #1741 from atom/cz-first-responder-menu

Send command to first responder when no window is focused
This commit is contained in:
Nathan Sobo
2014-03-11 11:10:36 -06:00
2 changed files with 22 additions and 15 deletions

View File

@@ -246,7 +246,26 @@ class AtomApplication
# The optional arguments to pass along.
sendCommand: (command, args...) ->
unless @emit(command, args...)
@focusedWindow()?.sendCommand(command, args...)
focusedWindow = @focusedWindow()
if focusedWindow?
focusedWindow.sendCommand(command, args...)
else
@sendCommandToFirstResponder(command)
# Translates the command into OS X action and sends it to application's first
# responder.
sendCommandToFirstResponder: (command) ->
return false unless process.platform is 'darwin'
switch command
when 'core:undo' then Menu.sendActionToFirstResponder('undo:')
when 'core:redo' then Menu.sendActionToFirstResponder('redo:')
when 'core:copy' then Menu.sendActionToFirstResponder('copy:')
when 'core:cut' then Menu.sendActionToFirstResponder('cut:')
when 'core:paste' then Menu.sendActionToFirstResponder('paste:')
when 'core:select-all' then Menu.sendActionToFirstResponder('selectAll:')
else return false
true
# Public: Open the given path in the focused window when the event is
# triggered.

View File

@@ -1,5 +1,4 @@
BrowserWindow = require 'browser-window'
Menu = require 'menu'
ContextMenu = require './context-menu'
app = require 'app'
dialog = require 'dialog'
@@ -126,7 +125,7 @@ class AtomWindow
sendCommand: (command, args...) ->
if @isSpecWindow()
unless @sendCommandToFirstResponder(command)
unless global.atomApplication.sendCommandToFirstResponder(command)
switch command
when 'window:reload' then @reload()
when 'window:toggle-dev-tools' then @toggleDevTools()
@@ -134,24 +133,13 @@ class AtomWindow
else if @isWebViewFocused()
@sendCommandToBrowserWindow(command, args...)
else
unless @sendCommandToFirstResponder(command)
unless global.atomApplication.sendCommandToFirstResponder(command)
@sendCommandToBrowserWindow(command, args...)
sendCommandToBrowserWindow: (command, args...) ->
action = if args[0]?.contextCommand then 'context-command' else 'command'
ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), action, command, args...
sendCommandToFirstResponder: (command) ->
switch command
when 'core:undo' then Menu.sendActionToFirstResponder('undo:')
when 'core:redo' then Menu.sendActionToFirstResponder('redo:')
when 'core:copy' then Menu.sendActionToFirstResponder('copy:')
when 'core:cut' then Menu.sendActionToFirstResponder('cut:')
when 'core:paste' then Menu.sendActionToFirstResponder('paste:')
when 'core:select-all' then Menu.sendActionToFirstResponder('selectAll:')
else return false
true
close: -> @browserWindow.close()
focus: -> @browserWindow.focus()