mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Move command handling to AtomWindow
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user