fix(T2338): You can now use keyboard shortcuts on focused BrowserWindows

Fixes T2338, and also removes a bit of dead code
This commit is contained in:
Ben Gotow 2015-07-30 17:32:21 -07:00
parent 772a18c05d
commit b6f85e9b56
4 changed files with 11 additions and 28 deletions

View file

@ -3,6 +3,7 @@ ipc = require 'ipc'
Menu = require 'menu'
_ = require 'underscore'
Utils = require '../flux/models/utils'
BrowserWindow = require 'browser-window'
# Used to manage the global application menu.
#
@ -126,7 +127,7 @@ class ApplicationMenu
]
focusedWindow: ->
global.application.windowManager.focusedWindow()
BrowserWindow.getFocusedWindow()
# Combines a menu template with the appropriate keystroke.
#

View file

@ -309,10 +309,19 @@ class Application
sendCommand: (command, args...) ->
unless @emit(command, args...)
focusedWindow = @windowManager.focusedWindow()
focusedBrowserWindow = BrowserWindow.getFocusedWindow()
mainWindow = @windowManager.mainWindow()
if focusedWindow?
focusedWindow.sendCommand(command, args...)
else if focusedBrowserWindow?
# Note: We sometimes display non-"AtomWindow" windows, for things like
# raw message contents. Ensure that these also get to run window commands
unless global.application.sendCommandToFirstResponder(command)
switch command
when 'window:reload' then focusedBrowserWindow.reload()
when 'window:toggle-dev-tools' then focusedBrowserWindow.toggleDevTools()
when 'window:close' then focusedBrowserWindow.close()
else if mainWindow?
mainWindow.sendCommand(command, args...)
else

View file

@ -130,11 +130,6 @@ class AtomWindow
slashes: true
query: {loadSettings: JSON.stringify(loadSettings)}
hasProjectPath: -> @projectPath?.length > 0
getInitialPath: ->
@browserWindow.loadSettings.initialPath
setupContextMenu: ->
ContextMenu = null
@ -142,21 +137,6 @@ class AtomWindow
ContextMenu ?= require './context-menu'
new ContextMenu(menuTemplate, this)
containsPath: (pathToCheck) ->
initialPath = @getInitialPath()
if not initialPath
false
else if not pathToCheck
false
else if pathToCheck is initialPath
true
else if fs.statSyncNoException(pathToCheck).isDirectory?()
false
else if pathToCheck.indexOf(path.join(initialPath, path.sep)) is 0
true
else
false
handleEvents: ->
@browserWindow.on 'close', (event) =>
if @neverClose and !global.application.quitting
@ -267,9 +247,6 @@ class AtomWindow
restore: -> @browserWindow.restore()
handlesAtomCommands: ->
not @isSpecWindow() and @isWebViewFocused()
isFocused: -> @browserWindow.isFocused()
isMinimized: -> @browserWindow.isMinimized()

View file

@ -395,14 +395,10 @@ class WindowManager
global.application.autoUpdateManager.emitUpdateAvailableEvent(window)
unless window.isSpec
focusHandler = => @lastFocusedWindow = window
closePreventedHandler = => @windowClosedOrHidden()
window.on 'window:close-prevented', closePreventedHandler
window.browserWindow.on 'focus', focusHandler
window.browserWindow.once 'closed', =>
@lastFocusedWindow = null if window is @lastFocusedWindow
window.removeListener('window:close-prevented', closePreventedHandler)
window.browserWindow.removeListener('focus', focusHandler)
windowClosedOrHidden: ->
# On Windows and Linux, we want to terminate the app after the last visible