From 17be036ff885928d01b31672278610e3b9eaa804 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 09:45:35 -0800 Subject: [PATCH 1/6] Move window.setUpEnvironment to Atom class --- spec/spec-helper.coffee | 2 +- src/atom.coffee | 4 ++++ src/window-bootstrap.coffee | 2 +- src/window.coffee | 5 ----- 4 files changed, 6 insertions(+), 7 deletions(-) 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/src/atom.coffee b/src/atom.coffee index 65a764747..7fc0c9665 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -53,6 +53,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}") diff --git a/src/window-bootstrap.coffee b/src/window-bootstrap.coffee index 6d94e4dc0..e9d066a78 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') +atom.setUpEnvironment('editor') window.startEditorWindow() console.log "Window load time: #{Date.now() - startTime}ms" diff --git a/src/window.coffee b/src/window.coffee index 2da308cfd..19b1db7b8 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -8,11 +8,6 @@ WindowEventHandler = require './window-event-handler' 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 From 79b84b2433f2285dd67f4dfcf794e401c9310d7c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 09:48:57 -0800 Subject: [PATCH 2/6] Move window.deserializeEditorWindow to Atom class --- spec/window-spec.coffee | 2 +- src/atom.coffee | 5 +++++ src/window.coffee | 7 +------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 3633caf4a..d1a798ef5 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 -> diff --git a/src/atom.coffee b/src/atom.coffee index 7fc0c9665..052e70066 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -132,6 +132,11 @@ class Atom @packages.packageStates = state.getObject('packageStates') ? {} state.remove('packageStates') + deserializeEditorWindow: -> + @deserializePackageStates() + @deserializeProject() + @deserializeRootView() + loadThemes: -> @themes.load() diff --git a/src/window.coffee b/src/window.coffee index 19b1db7b8..eec4f62a8 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -33,7 +33,7 @@ window.startEditorWindow = -> atom.keymap.loadBundledKeymaps() atom.themes.loadBaseStylesheets() atom.packages.loadPackages() - deserializeEditorWindow() + atom.deserializeEditorWindow() atom.packages.activate() atom.keymap.loadUserKeymap() atom.requireUserInitScript() @@ -68,11 +68,6 @@ installApmCommand = (callback) -> 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() From 754b5a6004b4efca9d95e2ea78553c379180d4f4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 09:49:35 -0800 Subject: [PATCH 3/6] Remove unused requires --- src/window.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/window.coffee b/src/window.coffee index eec4f62a8..a6326087a 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -1,7 +1,5 @@ path = require 'path' {$} = require './space-pen-extensions' -_ = require 'underscore-plus' -ipc = require 'ipc' WindowEventHandler = require './window-event-handler' ### Internal ### From 3320176a0a80d20e9df2442508fbaf4b9b1774c7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 09:51:21 -0800 Subject: [PATCH 4/6] Move atom/apm install helpers to CommandInstaller --- src/command-installer.coffee | 10 ++++++++++ src/window.coffee | 15 +++------------ 2 files changed, 13 insertions(+), 12 deletions(-) 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.coffee b/src/window.coffee index a6326087a..8c1f54327 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -20,8 +20,9 @@ window.setUpDefaultEvents = -> # This method is only called when opening a real application window window.startEditorWindow = -> if process.platform is 'darwin' - installAtomCommand() - installApmCommand() + CommandInstaller = require './command-installer' + CommandInstaller.installAtomCommand() + CommandInstaller.installApmCommand() windowEventHandler = new WindowEventHandler atom.restoreDimensions() @@ -56,16 +57,6 @@ window.unloadEditorWindow = -> 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.onerror = -> atom.openDevTools() From f21727800193751db5c2b2f567fc7897f4696de6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 09:58:23 -0800 Subject: [PATCH 5/6] Move editor window helpers to Atom class --- spec/window-spec.coffee | 4 +-- src/atom.coffee | 54 +++++++++++++++++++++++++++++++++ src/window-bootstrap.coffee | 2 +- src/window.coffee | 59 ------------------------------------- 4 files changed, 57 insertions(+), 62 deletions(-) diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index d1a798ef5..9285068d5 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -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 052e70066..5d352d446 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -14,6 +14,7 @@ app = remote.require 'app' DeserializerManager = require './deserializer-manager' {Subscriber} = require 'emissary' SiteShim = require './site-shim' +WindowEventHandler = require './window-event-handler' # Public: Atom global for dealing with packages, themes, menus, and the window. # @@ -137,6 +138,59 @@ class Atom @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/window-bootstrap.coffee b/src/window-bootstrap.coffee index e9d066a78..c7cd6b190 100644 --- a/src/window-bootstrap.coffee +++ b/src/window-bootstrap.coffee @@ -6,5 +6,5 @@ require './window' Atom = require './atom' window.atom = new Atom() atom.setUpEnvironment('editor') -window.startEditorWindow() +atom.startEditorWindow() console.log "Window load time: #{Date.now() - startTime}ms" diff --git a/src/window.coffee b/src/window.coffee index 8c1f54327..3aa23069e 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -1,62 +1,3 @@ -path = require 'path' -{$} = require './space-pen-extensions' -WindowEventHandler = require './window-event-handler' - -### Internal ### - -windowEventHandler = null - -# 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' - CommandInstaller = require './command-installer' - CommandInstaller.installAtomCommand() - CommandInstaller.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() - atom.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() - window.onerror = -> atom.openDevTools() From 45b65cd3aa1735c83008eb820a3db44c114ea012 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 10:01:31 -0800 Subject: [PATCH 6/6] Organize imports --- src/atom.coffee | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 5d352d446..f9071a013 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -1,18 +1,20 @@ -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'