Use ApplicationDelegate in WindowEventHandler

Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
Nathan Sobo
2015-10-13 17:10:30 -06:00
parent f989ed65e1
commit 919571f328
4 changed files with 15 additions and 11 deletions

View File

@@ -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)

View File

@@ -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'

View File

@@ -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