diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index db769dcc3..b0632ebd3 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -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. diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index b844bc519..618ed06ef 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -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()