From b6f85e9b5626898e364c18a8eb885d5780c48494 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Thu, 30 Jul 2015 17:32:21 -0700 Subject: [PATCH] fix(T2338): You can now use keyboard shortcuts on focused BrowserWindows Fixes T2338, and also removes a bit of dead code --- src/browser/application-menu.coffee | 3 ++- src/browser/application.coffee | 9 +++++++++ src/browser/atom-window.coffee | 23 ----------------------- src/browser/window-manager.coffee | 4 ---- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/browser/application-menu.coffee b/src/browser/application-menu.coffee index 15157fe39..02342bb26 100644 --- a/src/browser/application-menu.coffee +++ b/src/browser/application-menu.coffee @@ -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. # diff --git a/src/browser/application.coffee b/src/browser/application.coffee index 90ae9bde7..43b146f85 100644 --- a/src/browser/application.coffee +++ b/src/browser/application.coffee @@ -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 diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index fe1a47b09..95061b50f 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -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() diff --git a/src/browser/window-manager.coffee b/src/browser/window-manager.coffee index 16ec8f37e..15cc1fd4c 100644 --- a/src/browser/window-manager.coffee +++ b/src/browser/window-manager.coffee @@ -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