Pass explicit window global into AtomEnvironment on construction

This commit is contained in:
Nathan Sobo
2015-10-13 19:35:51 -06:00
parent c8407167ee
commit 65ae175e72
6 changed files with 17 additions and 17 deletions

View File

@@ -213,7 +213,7 @@ describe "AtomEnvironment", ->
describe "::unloadEditorWindow()", ->
it "saves the serialized state of the window so it can be deserialized after reload", ->
atomEnvironment = new AtomEnvironment(applicationDelegate: atom.applicationDelegate)
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window})
spyOn(atomEnvironment, 'saveStateSync')
workspaceState = atomEnvironment.workspace.serialize()
@@ -231,7 +231,7 @@ describe "AtomEnvironment", ->
describe "::destroy()", ->
it "unsubscribes from all buffers", ->
atomEnvironment = new AtomEnvironment(applicationDelegate: atom.applicationDelegate)
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window})
waitsForPromise ->
atomEnvironment.workspace.open("sample.js")

View File

@@ -18,7 +18,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
applicationDelegate = new ApplicationDelegate()
applicationDelegate.setRepresentedFilename = ->
applicationDelegate.setWindowDocumentEdited = ->
window.atom = buildAtomEnvironment({applicationDelegate})
window.atom = buildAtomEnvironment({applicationDelegate, window})
require './spec-helper'
disableFocusMethods() if process.env.JANKY_SHA1 or process.env.CI

View File

@@ -18,7 +18,7 @@ describe "WindowEventHandler", ->
loadSettings.initialPath = initialPath
loadSettings
atom.project.destroy()
windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate})
windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window})
projectPath = atom.project.getPaths()[0]
afterEach ->

View File

@@ -101,7 +101,7 @@ class AtomEnvironment extends Model
# Call .loadOrCreate instead
constructor: (params={}) ->
{@applicationDelegate} = params
{@applicationDelegate, @window} = params
@state = {version: @constructor.version}
@@ -652,7 +652,7 @@ class AtomEnvironment extends Model
window.onerror = @previousWindowErrorHandler
installWindowEventHandler: ->
@windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate})
@windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window})
uninstallWindowEventHandler: ->
@windowEventHandler?.unsubscribe()

View File

@@ -16,7 +16,7 @@ process.env.NODE_ENV ?= 'production' unless devMode
AtomEnvironment = require './atom-environment'
ApplicationDelegate = require './application-delegate'
window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate})
window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window})
atom.displayWindow()
atom.loadStateSync()

View File

@@ -3,17 +3,17 @@ path = require 'path'
fs = require 'fs-plus'
listen = require './delegated-listener'
# Handles low-level events related to the window.
# Handles low-level events related to the @window.
module.exports =
class WindowEventHandler
constructor: ({@atomEnvironment, @applicationDelegate}) ->
constructor: ({@atomEnvironment, @applicationDelegate, @window}) ->
@reloadRequested = false
@subscriptions = new CompositeDisposable
@previousOnbeforeunloadHandler = window.onbeforeunload
window.onbeforeunload = @handleWindowBeforeunload
@addEventListener(window, 'focus', @handleWindowFocus)
@addEventListener(window, 'blur', @handleWindowBlur)
@previousOnbeforeunloadHandler = @window.onbeforeunload
@window.onbeforeunload = @handleWindowBeforeunload
@addEventListener(@window, 'focus', @handleWindowFocus)
@addEventListener(@window, 'blur', @handleWindowBlur)
@addEventListener(document, 'keydown', @handleDocumentKeydown)
@addEventListener(document, 'drop', @handleDocumentDrop)
@@ -22,15 +22,15 @@ class WindowEventHandler
@subscriptions.add listen(document, 'click', 'a', @handleLinkClick)
@subscriptions.add listen(document, 'submit', 'form', @handleFormSubmit)
@subscriptions.add @atomEnvironment.commands.add window,
@subscriptions.add @atomEnvironment.commands.add @window,
'window:toggle-full-screen': @handleWindowToggleFullScreen
'window:close': @handleWindowClose
'window:reload': @handleWindowReload
'window:toggle-dev-tools': @handleWindowToggleDevTools
if process.platform in ['win32', 'linux']
@subscriptions.add @atomEnvironment.commands.add window,
'window:toggle-menu-bar': @handleWindowToggleMenuBar
@subscriptions.add @atomEnvironment.commands.add @window,
'@window:toggle-menu-bar': @handleWindowToggleMenuBar
@subscriptions.add @atomEnvironment.commands.add document,
'core:focus-next': @handleFocusNext
@@ -54,7 +54,7 @@ class WindowEventHandler
bindCommandToAction('core:cut', 'cut')
unsubscribe: ->
window.onbeforeunload = @previousOnbeforeunloadHandler
@window.onbeforeunload = @previousOnbeforeunloadHandler
@subscriptions.dispose()
on: (target, eventName, handler) ->