diff --git a/benchmark/benchmark-helper.coffee b/benchmark/benchmark-helper.coffee index 18aedf44f..2fe689ecc 100644 --- a/benchmark/benchmark-helper.coffee +++ b/benchmark/benchmark-helper.coffee @@ -9,10 +9,7 @@ TextMateBundle = require 'text-mate-bundle' TextMateTheme = require 'text-mate-theme' require 'window' - requireStylesheet "jasmine.css" -TextMateBundle.loadAll() -TextMateTheme.loadAll() RootView.prototype.loadUserConfiguration = -> diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index c0b194a5a..4cca9d5e2 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -10,7 +10,7 @@ describe "editor.", -> beforeEach -> window.rootViewParentSelector = '#jasmine-content' - window.startup() + window.attachRootView() rootView.project.setPath(require.resolve('benchmark/fixtures')) editor = rootView.getActiveEditor() diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index d3703e857..6dcc5bf49 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -3,7 +3,7 @@ fs = require 'fs' describe "Window", -> beforeEach -> - window.startup(require.resolve('fixtures')) + window.attachRootView(require.resolve('fixtures')) afterEach -> window.shutdown() diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index dafe5de7e..9a89070d9 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -14,8 +14,6 @@ require 'window' atom.showDevTools() requireStylesheet "jasmine.css" -TextMateBundle.loadAll() -TextMateTheme.loadAll() defaultTitle = document.title pathsWithSubscriptions = null diff --git a/src/app/window.coffee b/src/app/window.coffee index 4d488234e..108e305e6 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -8,6 +8,9 @@ fs = require 'fs' _ = require 'underscore' $ = require 'jquery' {CoffeeScript} = require 'coffee-script' +RootView = require 'root-view' +require 'jquery-extensions' +require 'underscore-extensions' windowAdditions = rootViewParentSelector: 'body' @@ -15,16 +18,28 @@ windowAdditions = keymap: null platform: $native.getPlatform() - startup: (path) -> + # This method runs when the file is required. Any code here will run + # in all environments: spec, benchmark, and application + startup: -> TextMateBundle.loadAll() TextMateTheme.loadAll() + @setUpKeymap() + + # This method is intended only to be run when starting a normal application + # Note: RootView assigns itself on window on initialization so that + # window.rootView is available when loading user configuration + attachRootView: (pathToOpen) -> + if rootViewState = atom.getRootViewStateForPath(pathToOpen) + RootView.deserialize(rootViewState) + else + new RootView(pathToOpen) - @attachRootView(path) $(window).on 'close', => @close() + $(@rootViewParentSelector).append(@rootView) + $(window).focus() $(window).on 'beforeunload', => @shutdown() false - $(window).focus() shutdown: -> @rootView.deactivate() @@ -42,16 +57,6 @@ windowAdditions = @_handleKeyEvent = (e) => @keymap.handleKeyEvent(e) $(document).on 'keydown', @_handleKeyEvent - # Note: RootView assigns itself on window on initialization so that - # window.rootView is available when loading user configuration - attachRootView: (pathToOpen) -> - if rootViewState = atom.getRootViewStateForPath(pathToOpen) - RootView.deserialize(rootViewState) - else - new RootView(pathToOpen) - - $(@rootViewParentSelector).append @rootView - requireStylesheet: (path) -> unless fullPath = require.resolve(path) throw new Error("requireStylesheet could not find a file at path '#{path}'") @@ -91,12 +96,7 @@ windowAdditions = console.log description, result window[key] = value for key, value of windowAdditions -window.setUpKeymap() - -RootView = require 'root-view' - -require 'jquery-extensions' -require 'underscore-extensions' +window.startup() requireStylesheet 'reset.css' requireStylesheet 'atom.css' diff --git a/src/window-bootstrap.coffee b/src/window-bootstrap.coffee index 46d4750c9..86404bb98 100644 --- a/src/window-bootstrap.coffee +++ b/src/window-bootstrap.coffee @@ -1,5 +1,4 @@ # Like sands through the hourglass, so are the days of our lives. require 'atom' require 'window' -window.startup window.location.params.pathToOpen - +window.attachRootView(window.location.params.pathToOpen)