From 919571f328d165912a7bc2fef95ccc078b9ad181 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 13 Oct 2015 17:10:30 -0600 Subject: [PATCH] Use ApplicationDelegate in WindowEventHandler Signed-off-by: Max Brunsfeld --- spec/window-event-handler-spec.coffee | 4 ++-- src/application-delegate.coffee | 6 ++++++ src/browser/atom-application.coffee | 2 +- src/window-event-handler.coffee | 14 ++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/window-event-handler-spec.coffee b/spec/window-event-handler-spec.coffee index 76dd9ef6b..cc9e14a97 100644 --- a/spec/window-event-handler-spec.coffee +++ b/spec/window-event-handler-spec.coffee @@ -65,13 +65,13 @@ describe "WindowEventHandler", -> spyOn(atom.workspace, 'confirmClose').andReturn(true) window.dispatchEvent(new CustomEvent('beforeunload')) expect(atom.workspace.confirmClose).toHaveBeenCalled() - expect(ipc.send).not.toHaveBeenCalledWith('cancel-window-close') + expect(ipc.send).not.toHaveBeenCalledWith('did-cancel-window-unload') it "cancels the unload if the user selects cancel", -> spyOn(atom.workspace, 'confirmClose').andReturn(false) window.dispatchEvent(new CustomEvent('beforeunload')) expect(atom.workspace.confirmClose).toHaveBeenCalled() - expect(ipc.send).toHaveBeenCalledWith('cancel-window-close') + expect(ipc.send).toHaveBeenCalledWith('did-cancel-window-unload') describe "when a link is clicked", -> it "opens the http/https links in an external application", -> diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index 7cc76c50c..cbbd10a69 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -125,3 +125,9 @@ class ApplicationDelegate ipc.on('context-command', callback) new Disposable -> ipc.removeEventListener('context-command', callback) + + didCancelWindowUnload: -> + ipc.send('did-cancel-window-unload') + + openExternal: (url) -> + shell.openExternal(url) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 8ef056237..d63ee4e78 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -264,7 +264,7 @@ class AtomApplication @promptForPath "folder", (selectedPaths) -> event.sender.send(responseChannel, selectedPaths) - ipc.on 'cancel-window-close', => + ipc.on 'did-cancel-window-unload', => @quitting = false clipboard = require '../safe-clipboard' diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 5b25ff18f..f4b844405 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -1,14 +1,12 @@ path = require 'path' {Disposable, CompositeDisposable} = require 'event-kit' -ipc = require 'ipc' -shell = require 'shell' fs = require 'fs-plus' listen = require './delegated-listener' # Handles low-level events related to the window. module.exports = class WindowEventHandler - constructor: ({@atomEnvironment}) -> + constructor: ({@atomEnvironment, @applicationDelegate}) -> @reloadRequested = false @subscriptions = new CompositeDisposable @@ -46,7 +44,7 @@ class WindowEventHandler bindCommandToAction = (command, action) => @addEventListener document, command, (event) => if event.target.webkitMatchesSelector('.native-key-bindings') - @atomEnvironment.getCurrentWindow().webContents[action]() + @applicationDelegate.getCurrentWindow().webContents[action]() bindCommandToAction('core:copy', 'copy') bindCommandToAction('core:paste', 'paste') @@ -147,7 +145,7 @@ class WindowEventHandler if confirmed @atomEnvironment.unloadEditorWindow() else - ipc.send('cancel-window-close') + @applicationDelegate.didCancelWindowUnload() confirmed @@ -176,9 +174,9 @@ class WindowEventHandler handleLinkClick: (event) -> event.preventDefault() - location = event.currentTarget?.getAttribute('href') - if location and location[0] isnt '#' and /^https?:\/\//.test(location) - shell.openExternal(location) + uri = event.currentTarget?.getAttribute('href') + if uri and uri[0] isnt '#' and /^https?:\/\//.test(uri) + @applicationDelegate.openExternal(uri) handleFormSubmit: (event) -> # Prevent form submits from changing the current window's URL