diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 6181e9f7c..d3c4ef3e5 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -1,5 +1,5 @@ require '../src/window' -window.setUpEnvironment('spec') +atom.setUpEnvironment('spec') atom.restoreDimensions() require '../vendor/jasmine-jquery' diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 3633caf4a..9285068d5 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -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 diff --git a/src/atom.coffee b/src/atom.coffee index 65a764747..f9071a013 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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() diff --git a/src/command-installer.coffee b/src/command-installer.coffee index 77dacc934..339da0be6 100644 --- a/src/command-installer.coffee +++ b/src/command-installer.coffee @@ -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) diff --git a/src/window-bootstrap.coffee b/src/window-bootstrap.coffee index 6d94e4dc0..c7cd6b190 100644 --- a/src/window-bootstrap.coffee +++ b/src/window-bootstrap.coffee @@ -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" diff --git a/src/window.coffee b/src/window.coffee index 2da308cfd..3aa23069e 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -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()