Merge pull request #1151 from atom/ks-remove-global-functions

Remove global functions
This commit is contained in:
Kevin Sawicki
2013-11-22 10:26:35 -08:00
6 changed files with 89 additions and 94 deletions

View File

@@ -1,5 +1,5 @@
require '../src/window'
window.setUpEnvironment('spec')
atom.setUpEnvironment('spec')
atom.restoreDimensions()
require '../vendor/jasmine-jquery'

View File

@@ -11,7 +11,7 @@ describe "Window", ->
atom.loadSettings.initialPath = atom.project.getPath()
atom.project.destroy()
windowEventHandler = new WindowEventHandler()
window.deserializeEditorWindow()
atom.deserializeEditorWindow()
projectPath = atom.project.getPath()
afterEach ->
@@ -86,7 +86,7 @@ describe "Window", ->
rootViewState = atom.rootView.serialize()
syntaxState = atom.syntax.serialize()
window.unloadEditorWindow()
atom.unloadEditorWindow()
expect(atom.getWindowState().getObject('rootView')).toEqual rootViewState.toObject()
expect(atom.getWindowState().getObject('syntax')).toEqual syntaxState
@@ -99,7 +99,7 @@ describe "Window", ->
pane.splitRight(pane.copyActiveItem())
expect(atom.rootView.find('.editor').length).toBe 2
window.unloadEditorWindow()
atom.unloadEditorWindow()
expect(buffer.getSubscriptionCount()).toBe 0

View File

@@ -1,19 +1,22 @@
fs = require 'fs-plus'
{$} = require './space-pen-extensions'
_ = require 'underscore-plus'
Package = require './package'
crypto = require 'crypto'
ipc = require 'ipc'
os = require 'os'
path = require 'path'
remote = require 'remote'
shell = require 'shell'
crypto = require 'crypto'
path = require 'path'
os = require 'os'
dialog = remote.require 'dialog'
app = remote.require 'app'
_ = require 'underscore-plus'
{Document} = require 'telepath'
DeserializerManager = require './deserializer-manager'
fs = require 'fs-plus'
{Subscriber} = require 'emissary'
{$} = require './space-pen-extensions'
DeserializerManager = require './deserializer-manager'
Package = require './package'
SiteShim = require './site-shim'
WindowEventHandler = require './window-event-handler'
# Public: Atom global for dealing with packages, themes, menus, and the window.
#
@@ -53,6 +56,10 @@ class Atom
@pasteboard = new Pasteboard()
@syntax = @deserializers.deserialize(@getWindowState('syntax')) ? new Syntax()
# Private: This method is called in any window needing a general environment, including specs
setUpEnvironment: (@windowMode) ->
@initialize()
# Private:
setBodyPlatformClass: ->
document.body.classList.add("platform-#{process.platform}")
@@ -128,6 +135,64 @@ class Atom
@packages.packageStates = state.getObject('packageStates') ? {}
state.remove('packageStates')
deserializeEditorWindow: ->
@deserializePackageStates()
@deserializeProject()
@deserializeRootView()
# Private: This method is only called when opening a real application window
startEditorWindow: ->
if process.platform is 'darwin'
CommandInstaller = require './command-installer'
CommandInstaller.installAtomCommand()
CommandInstaller.installApmCommand()
@windowEventHandler = new WindowEventHandler
@restoreDimensions()
@config.load()
@config.setDefaults('core', require('./root-view').configDefaults)
@config.setDefaults('editor', require('./editor-view').configDefaults)
@keymap.loadBundledKeymaps()
@themes.loadBaseStylesheets()
@packages.loadPackages()
@deserializeEditorWindow()
@packages.activate()
@keymap.loadUserKeymap()
@requireUserInitScript()
@menu.update()
$(window).on 'unload', =>
$(document.body).hide()
@unloadEditorWindow()
false
@displayWindow()
unloadEditorWindow: ->
return if not @project and not @rootView
windowState = @getWindowState()
windowState.set('project', @project)
windowState.set('syntax', @syntax.serialize())
windowState.set('rootView', @rootView.serialize())
@packages.deactivatePackages()
windowState.set('packageStates', @packages.packageStates)
@saveWindowState()
@rootView.remove()
@project.destroy()
@windowEventHandler?.unsubscribe()
# Set up the default event handlers and menus for a non-editor window.
#
# This can be used by packages to have a minimum level of keybindings and
# menus available when not using the standard editor window.
#
# This should only be called after setUpEnvironment() has been called.
setUpDefaultEvents: ->
@windowEventHandler = new WindowEventHandler
@keymap.loadBundledKeymaps()
@menu.update()
loadThemes: ->
@themes.load()

View File

@@ -47,3 +47,13 @@ module.exports =
symlinkCommand(commandPath, destinationPath, installCallback)
else
installCallback(new Error("No destination directory exists to install"))
installAtomCommand: (callback) ->
{resourcePath} = atom.getLoadSettings()
commandPath = path.join(resourcePath, 'atom.sh')
@install(commandPath, callback)
installApmCommand: (callback) ->
{resourcePath} = atom.getLoadSettings()
commandPath = path.join(resourcePath, 'node_modules', '.bin', 'apm')
@install(commandPath, callback)

View File

@@ -5,6 +5,6 @@ require './window'
Atom = require './atom'
window.atom = new Atom()
window.setUpEnvironment('editor')
window.startEditorWindow()
atom.setUpEnvironment('editor')
atom.startEditorWindow()
console.log "Window load time: #{Date.now() - startTime}ms"

View File

@@ -1,83 +1,3 @@
path = require 'path'
{$} = require './space-pen-extensions'
_ = require 'underscore-plus'
ipc = require 'ipc'
WindowEventHandler = require './window-event-handler'
### Internal ###
windowEventHandler = null
# This method is called in any window needing a general environment, including specs
window.setUpEnvironment = (windowMode) ->
atom.windowMode = windowMode
atom.initialize()
# Set up the default event handlers and menus for a non-editor windows.
#
# This can be used by packages to have a minimum level of keybindings and
# menus available when not using the standard editor window.
#
# This should only be called after setUpEnvironment() has been called.
window.setUpDefaultEvents = ->
windowEventHandler = new WindowEventHandler
atom.keymap.loadBundledKeymaps()
atom.menu.update()
# This method is only called when opening a real application window
window.startEditorWindow = ->
if process.platform is 'darwin'
installAtomCommand()
installApmCommand()
windowEventHandler = new WindowEventHandler
atom.restoreDimensions()
atom.config.load()
atom.config.setDefaults('core', require('./root-view').configDefaults)
atom.config.setDefaults('editor', require('./editor-view').configDefaults)
atom.keymap.loadBundledKeymaps()
atom.themes.loadBaseStylesheets()
atom.packages.loadPackages()
deserializeEditorWindow()
atom.packages.activate()
atom.keymap.loadUserKeymap()
atom.requireUserInitScript()
atom.menu.update()
$(window).on 'unload', ->
$(document.body).hide()
unloadEditorWindow()
false
atom.displayWindow()
window.unloadEditorWindow = ->
return if not atom.project and not atom.rootView
windowState = atom.getWindowState()
windowState.set('project', atom.project)
windowState.set('syntax', atom.syntax.serialize())
windowState.set('rootView', atom.rootView.serialize())
atom.packages.deactivatePackages()
windowState.set('packageStates', atom.packages.packageStates)
atom.saveWindowState()
atom.rootView.remove()
atom.project.destroy()
windowEventHandler?.unsubscribe()
installAtomCommand = (callback) ->
{resourcePath} = atom.getLoadSettings()
commandPath = path.join(resourcePath, 'atom.sh')
require('./command-installer').install(commandPath, callback)
installApmCommand = (callback) ->
{resourcePath} = atom.getLoadSettings()
commandPath = path.join(resourcePath, 'node_modules', '.bin', 'apm')
require('./command-installer').install(commandPath, callback)
window.deserializeEditorWindow = ->
atom.deserializePackageStates()
atom.deserializeProject()
atom.deserializeRootView()
window.onerror = ->
atom.openDevTools()