Move command handling to AtomWindow

This commit is contained in:
Corey Johnson & Nathan Sobo
2013-08-20 11:58:08 -07:00
parent fc60ba682c
commit 85626383ee
2 changed files with 23 additions and 20 deletions

View File

@@ -141,26 +141,8 @@ class AtomApplication
@emit(command)
sendCommand: (command, args...) ->
return if @emit(command, args...)
return if @interceptAlternativeWindowCommands(command)
@focusedWindow()?.sendCommand(command, args...)
interceptAlternativeWindowCommands: (command) ->
return if not @focusedWindow()?.isSpecWindow() and @focusedWindow()?.isWebViewFocused()
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:')
when 'window:reload' then @focusedWindow()?.reload()
when 'window:toggle-dev-tools' then @focusedWindow()?.toggleDevTools()
when 'window:close' then @focusedWindow()?.close()
else return false
return true
unless @emit(command, args...)
@focusedWindow()?.sendCommand(command, args...)
windowForPath: (pathToOpen) ->
for atomWindow in @windows

View File

@@ -115,12 +115,33 @@ class AtomWindow
@contextMenu.append(@inspectElementMenuItem)
sendCommand: (command, args...) ->
if @handlesAtomCommands()
@sendAtomCommand(command, args...)
else
@sendNativeCommand(command)
sendAtomCommand: (command, args...) ->
ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), 'command', command, args...
sendNativeCommand: (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:')
when 'window:reload' then @reload()
when 'window:toggle-dev-tools' then @toggleDevTools()
when 'window:close' then @close()
close: -> @browserWindow.close()
focus: -> @browserWindow.focus()
handlesAtomCommands: ->
not @isSpecWindow() and @isWebViewFocused()
isFocused: -> @browserWindow.isFocused()
isWebViewFocused: -> @browserWindow.isWebViewFocused()