mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Parameterize document on AtomEnvironment
This commit is contained in:
parent
5941d9464a
commit
903ecca1f7
@ -213,7 +213,7 @@ describe "AtomEnvironment", ->
|
|||||||
|
|
||||||
describe "::unloadEditorWindow()", ->
|
describe "::unloadEditorWindow()", ->
|
||||||
it "saves the serialized state of the window so it can be deserialized after reload", ->
|
it "saves the serialized state of the window so it can be deserialized after reload", ->
|
||||||
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window})
|
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window, document})
|
||||||
spyOn(atomEnvironment, 'saveStateSync')
|
spyOn(atomEnvironment, 'saveStateSync')
|
||||||
|
|
||||||
workspaceState = atomEnvironment.workspace.serialize()
|
workspaceState = atomEnvironment.workspace.serialize()
|
||||||
@ -231,7 +231,7 @@ describe "AtomEnvironment", ->
|
|||||||
|
|
||||||
describe "::destroy()", ->
|
describe "::destroy()", ->
|
||||||
it "unsubscribes from all buffers", ->
|
it "unsubscribes from all buffers", ->
|
||||||
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window})
|
atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window, document})
|
||||||
|
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
atomEnvironment.workspace.open("sample.js")
|
atomEnvironment.workspace.open("sample.js")
|
||||||
|
@ -18,7 +18,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
|
|||||||
applicationDelegate = new ApplicationDelegate()
|
applicationDelegate = new ApplicationDelegate()
|
||||||
applicationDelegate.setRepresentedFilename = ->
|
applicationDelegate.setRepresentedFilename = ->
|
||||||
applicationDelegate.setWindowDocumentEdited = ->
|
applicationDelegate.setWindowDocumentEdited = ->
|
||||||
window.atom = buildAtomEnvironment({applicationDelegate, window})
|
window.atom = buildAtomEnvironment({applicationDelegate, window, document})
|
||||||
|
|
||||||
require './spec-helper'
|
require './spec-helper'
|
||||||
disableFocusMethods() if process.env.JANKY_SHA1 or process.env.CI
|
disableFocusMethods() if process.env.JANKY_SHA1 or process.env.CI
|
||||||
|
@ -18,7 +18,7 @@ describe "WindowEventHandler", ->
|
|||||||
loadSettings.initialPath = initialPath
|
loadSettings.initialPath = initialPath
|
||||||
loadSettings
|
loadSettings
|
||||||
atom.project.destroy()
|
atom.project.destroy()
|
||||||
windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window})
|
windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window, document})
|
||||||
projectPath = atom.project.getPaths()[0]
|
projectPath = atom.project.getPaths()[0]
|
||||||
|
|
||||||
afterEach ->
|
afterEach ->
|
||||||
|
@ -101,7 +101,7 @@ class AtomEnvironment extends Model
|
|||||||
|
|
||||||
# Call .loadOrCreate instead
|
# Call .loadOrCreate instead
|
||||||
constructor: (params={}) ->
|
constructor: (params={}) ->
|
||||||
{@applicationDelegate, @window} = params
|
{@applicationDelegate, @window, @document} = params
|
||||||
|
|
||||||
@state = {version: @constructor.version}
|
@state = {version: @constructor.version}
|
||||||
|
|
||||||
@ -472,9 +472,9 @@ class AtomEnvironment extends Model
|
|||||||
setFullScreen: (fullScreen=false) ->
|
setFullScreen: (fullScreen=false) ->
|
||||||
@applicationDelegate.setWindowFullScreen(fullScreen)
|
@applicationDelegate.setWindowFullScreen(fullScreen)
|
||||||
if fullScreen
|
if fullScreen
|
||||||
document.body.classList.add("fullscreen")
|
@document.body.classList.add("fullscreen")
|
||||||
else
|
else
|
||||||
document.body.classList.remove("fullscreen")
|
@document.body.classList.remove("fullscreen")
|
||||||
|
|
||||||
# Extended: Toggle the full screen state of the current window.
|
# Extended: Toggle the full screen state of the current window.
|
||||||
toggleFullScreen: ->
|
toggleFullScreen: ->
|
||||||
@ -587,13 +587,13 @@ class AtomEnvironment extends Model
|
|||||||
@themes.loadBaseStylesheets()
|
@themes.loadBaseStylesheets()
|
||||||
@setBodyPlatformClass()
|
@setBodyPlatformClass()
|
||||||
|
|
||||||
document.head.appendChild(@styles.buildStylesElement())
|
@document.head.appendChild(@styles.buildStylesElement())
|
||||||
|
|
||||||
@packages.loadPackages()
|
@packages.loadPackages()
|
||||||
|
|
||||||
workspaceElement = @views.getView(@workspace)
|
workspaceElement = @views.getView(@workspace)
|
||||||
@keymaps.defaultTarget = workspaceElement
|
@keymaps.defaultTarget = workspaceElement
|
||||||
document.querySelector(@workspaceParentSelectorctor).appendChild(workspaceElement)
|
@document.querySelector(@workspaceParentSelectorctor).appendChild(workspaceElement)
|
||||||
|
|
||||||
@watchProjectPath()
|
@watchProjectPath()
|
||||||
|
|
||||||
@ -652,7 +652,7 @@ class AtomEnvironment extends Model
|
|||||||
window.onerror = @previousWindowErrorHandler
|
window.onerror = @previousWindowErrorHandler
|
||||||
|
|
||||||
installWindowEventHandler: ->
|
installWindowEventHandler: ->
|
||||||
@windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window})
|
@windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window, @document})
|
||||||
|
|
||||||
uninstallWindowEventHandler: ->
|
uninstallWindowEventHandler: ->
|
||||||
@windowEventHandler?.unsubscribe()
|
@windowEventHandler?.unsubscribe()
|
||||||
@ -817,16 +817,16 @@ class AtomEnvironment extends Model
|
|||||||
@disposables.add(@applicationDelegate.onUpdateAvailable(@updateAvailable.bind(this)))
|
@disposables.add(@applicationDelegate.onUpdateAvailable(@updateAvailable.bind(this)))
|
||||||
|
|
||||||
setBodyPlatformClass: ->
|
setBodyPlatformClass: ->
|
||||||
document.body.classList.add("platform-#{process.platform}")
|
@document.body.classList.add("platform-#{process.platform}")
|
||||||
|
|
||||||
setAutoHideMenuBar: (autoHide) ->
|
setAutoHideMenuBar: (autoHide) ->
|
||||||
@applicationDelegate.setAutoHideWindowMenuBar(autoHide)
|
@applicationDelegate.setAutoHideWindowMenuBar(autoHide)
|
||||||
@applicationDelegate.setWindowMenuBarVisibility(not autoHide)
|
@applicationDelegate.setWindowMenuBarVisibility(not autoHide)
|
||||||
|
|
||||||
dispatchApplicationMenuCommand: (command, arg) ->
|
dispatchApplicationMenuCommand: (command, arg) ->
|
||||||
activeElement = document.activeElement
|
activeElement = @document.activeElement
|
||||||
# Use the workspace element if body has focus
|
# Use the workspace element if body has focus
|
||||||
if activeElement is document.body and workspaceElement = @views.getView(@workspace)
|
if activeElement is @document.body and workspaceElement = @views.getView(@workspace)
|
||||||
activeElement = workspaceElement
|
activeElement = workspaceElement
|
||||||
@commands.dispatch(activeElement, command, arg)
|
@commands.dispatch(activeElement, command, arg)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ process.env.NODE_ENV ?= 'production' unless devMode
|
|||||||
|
|
||||||
AtomEnvironment = require './atom-environment'
|
AtomEnvironment = require './atom-environment'
|
||||||
ApplicationDelegate = require './application-delegate'
|
ApplicationDelegate = require './application-delegate'
|
||||||
window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window})
|
window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window, document})
|
||||||
|
|
||||||
atom.displayWindow()
|
atom.displayWindow()
|
||||||
atom.loadStateSync()
|
atom.loadStateSync()
|
||||||
|
@ -6,7 +6,7 @@ listen = require './delegated-listener'
|
|||||||
# Handles low-level events related to the @window.
|
# Handles low-level events related to the @window.
|
||||||
module.exports =
|
module.exports =
|
||||||
class WindowEventHandler
|
class WindowEventHandler
|
||||||
constructor: ({@atomEnvironment, @applicationDelegate, @window}) ->
|
constructor: ({@atomEnvironment, @applicationDelegate, @window, @document}) ->
|
||||||
@reloadRequested = false
|
@reloadRequested = false
|
||||||
@subscriptions = new CompositeDisposable
|
@subscriptions = new CompositeDisposable
|
||||||
|
|
||||||
@ -15,12 +15,12 @@ class WindowEventHandler
|
|||||||
@addEventListener(@window, 'focus', @handleWindowFocus)
|
@addEventListener(@window, 'focus', @handleWindowFocus)
|
||||||
@addEventListener(@window, 'blur', @handleWindowBlur)
|
@addEventListener(@window, 'blur', @handleWindowBlur)
|
||||||
|
|
||||||
@addEventListener(document, 'keydown', @handleDocumentKeydown)
|
@addEventListener(@document, 'keydown', @handleDocumentKeydown)
|
||||||
@addEventListener(document, 'drop', @handleDocumentDrop)
|
@addEventListener(@document, 'drop', @handleDocumentDrop)
|
||||||
@addEventListener(document, 'dragover', @handleDocumentDragover)
|
@addEventListener(@document, 'dragover', @handleDocumentDragover)
|
||||||
@addEventListener(document, 'contextmenu', @handleDocumentContextmenu)
|
@addEventListener(@document, 'contextmenu', @handleDocumentContextmenu)
|
||||||
@subscriptions.add listen(document, 'click', 'a', @handleLinkClick)
|
@subscriptions.add listen(@document, 'click', 'a', @handleLinkClick)
|
||||||
@subscriptions.add listen(document, 'submit', 'form', @handleFormSubmit)
|
@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:toggle-full-screen': @handleWindowToggleFullScreen
|
||||||
@ -32,7 +32,7 @@ class WindowEventHandler
|
|||||||
@subscriptions.add @atomEnvironment.commands.add @window,
|
@subscriptions.add @atomEnvironment.commands.add @window,
|
||||||
'@window:toggle-menu-bar': @handleWindowToggleMenuBar
|
'@window:toggle-menu-bar': @handleWindowToggleMenuBar
|
||||||
|
|
||||||
@subscriptions.add @atomEnvironment.commands.add document,
|
@subscriptions.add @atomEnvironment.commands.add @document,
|
||||||
'core:focus-next': @handleFocusNext
|
'core:focus-next': @handleFocusNext
|
||||||
'core:focus-previous': @handleFocusPrevious
|
'core:focus-previous': @handleFocusPrevious
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class WindowEventHandler
|
|||||||
# `.native-key-bindings` class.
|
# `.native-key-bindings` class.
|
||||||
handleNativeKeybindings: ->
|
handleNativeKeybindings: ->
|
||||||
bindCommandToAction = (command, action) =>
|
bindCommandToAction = (command, action) =>
|
||||||
@addEventListener document, command, (event) =>
|
@addEventListener @document, command, (event) =>
|
||||||
if event.target.webkitMatchesSelector('.native-key-bindings')
|
if event.target.webkitMatchesSelector('.native-key-bindings')
|
||||||
@applicationDelegate.getCurrentWindow().webContents[action]()
|
@applicationDelegate.getCurrentWindow().webContents[action]()
|
||||||
|
|
||||||
@ -81,14 +81,14 @@ class WindowEventHandler
|
|||||||
event.dataTransfer.dropEffect = 'none'
|
event.dataTransfer.dropEffect = 'none'
|
||||||
|
|
||||||
eachTabIndexedElement: (callback) ->
|
eachTabIndexedElement: (callback) ->
|
||||||
for element in document.querySelectorAll('[tabindex]')
|
for element in @document.querySelectorAll('[tabindex]')
|
||||||
continue if element.disabled
|
continue if element.disabled
|
||||||
continue unless element.tabIndex >= 0
|
continue unless element.tabIndex >= 0
|
||||||
callback(element, element.tabIndex)
|
callback(element, element.tabIndex)
|
||||||
return
|
return
|
||||||
|
|
||||||
handleFocusNext: =>
|
handleFocusNext: =>
|
||||||
focusedTabIndex = document.activeElement.tabIndex ? -Infinity
|
focusedTabIndex = @document.activeElement.tabIndex ? -Infinity
|
||||||
|
|
||||||
nextElement = null
|
nextElement = null
|
||||||
nextTabIndex = Infinity
|
nextTabIndex = Infinity
|
||||||
@ -109,7 +109,7 @@ class WindowEventHandler
|
|||||||
lowestElement.focus()
|
lowestElement.focus()
|
||||||
|
|
||||||
handleFocusPrevious: =>
|
handleFocusPrevious: =>
|
||||||
focusedTabIndex = document.activeElement.tabIndex ? Infinity
|
focusedTabIndex = @document.activeElement.tabIndex ? Infinity
|
||||||
|
|
||||||
previousElement = null
|
previousElement = null
|
||||||
previousTabIndex = -Infinity
|
previousTabIndex = -Infinity
|
||||||
@ -130,10 +130,10 @@ class WindowEventHandler
|
|||||||
highestElement.focus()
|
highestElement.focus()
|
||||||
|
|
||||||
handleWindowFocus: ->
|
handleWindowFocus: ->
|
||||||
document.body.classList.remove('is-blurred')
|
@document.body.classList.remove('is-blurred')
|
||||||
|
|
||||||
handleWindowBlur: =>
|
handleWindowBlur: =>
|
||||||
document.body.classList.add('is-blurred')
|
@document.body.classList.add('is-blurred')
|
||||||
@atomEnvironment.storeDefaultWindowDimensions()
|
@atomEnvironment.storeDefaultWindowDimensions()
|
||||||
|
|
||||||
handleWindowBeforeunload: =>
|
handleWindowBeforeunload: =>
|
||||||
|
Loading…
Reference in New Issue
Block a user