diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 63fe2b58b..270ab8f96 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -3,7 +3,6 @@ fs = require 'fs' describe "Window", -> beforeEach -> - spyOn(window, 'loadUserConfiguration') window.startup() afterEach -> diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 6415aceba..c8dc5d733 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -4,6 +4,7 @@ _ = require 'underscore' Keymap = require 'keymap' Point = require 'point' Directory = require 'directory' +RootView = require 'root-view' require 'window' window.showConsole() @@ -17,6 +18,7 @@ beforeEach -> directoriesWithSubscriptions = [] afterEach -> + delete window.rootView if window.rootView $('#jasmine-content').empty() document.title = defaultTitle ensureNoDirectorySubscriptions() @@ -24,6 +26,9 @@ afterEach -> window.keymap.bindKeys '*', 'meta-w': 'close' $(document).on 'close', -> window.close() +# Don't load user configuration in specs, because it's variable +RootView.prototype.loadUserConfiguration = -> + Directory.prototype.originalOn = Directory.prototype.on Directory.prototype.on = (args...) -> directoriesWithSubscriptions.push(this) if @subscriptionCount() == 0 diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index b04ae057d..eadf7bc7a 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -21,23 +21,24 @@ class RootView extends View @div id: 'panes', outlet: 'panes' @deserialize: ({ projectPath, panesViewState, extensionStates }) -> - rootView = new RootView(projectPath) + rootView = new RootView(projectPath, extensionStates: extensionStates, suppressOpen: true) rootView.setRootPane(rootView.deserializeView(panesViewState)) if panesViewState - rootView.extensionStates = extensionStates if extensionStates rootView extensions: null extensionStates: null fontSize: 20 - initialize: (pathToOpen) -> - @extensions = {} - @extensionStates = {} - @project = new Project(pathToOpen) + initialize: (pathToOpen, { @extensionStates, suppressOpen } = {}) -> + window.rootView = this + @extensionStates ?= {} + @extensions = {} + @project = new Project(pathToOpen) @handleEvents() @setTitle() - @open(pathToOpen) if fs.isFile(pathToOpen) + @loadUserConfiguration() + @open(pathToOpen) if fs.isFile(pathToOpen) unless suppressOpen serialize: -> projectPath: @project?.getPath() @@ -170,3 +171,11 @@ class RootView extends View @trigger 'font-size-change' if oldFontSize != newFontSize getFontSize: -> @fontSize + + loadUserConfiguration: -> + try + require atom.userConfigurationPath if fs.exists(atom.userConfigurationPath) + catch error + console.error "Failed to load `#{atom.userConfigurationPath}`", error.message, error + window.showConsole() + diff --git a/src/app/window.coffee b/src/app/window.coffee index 05b7854d6..97031bf8a 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -5,6 +5,7 @@ Native = require 'native' fs = require 'fs' _ = require 'underscore' $ = require 'jquery' +{CoffeeScript} = require 'coffee-script' windowAdditions = rootViewParentSelector: 'body' @@ -23,7 +24,6 @@ windowAdditions = startup: (path) -> @attachRootView(path) - @loadUserConfiguration() $(window).on 'close', => @close() $(window).on 'beforeunload', => @shutdown() @@ -38,23 +38,17 @@ windowAdditions = $(window).off('before') atom.windowClosed this + # Note: RootView assigns itself on window on initialization so that + # window.rootView is available when loading user configuration attachRootView: (pathToOpen) -> - rootViewState = atom.rootViewStates[$windowNumber] - if rootViewState - @rootView = RootView.deserialize(JSON.parse(rootViewState)) + if rootViewState = atom.rootViewStates[$windowNumber] + RootView.deserialize(JSON.parse(rootViewState)) else - @rootView = new RootView(pathToOpen) + new RootView(pathToOpen) @rootView.open() unless pathToOpen $(@rootViewParentSelector).append @rootView - loadUserConfiguration: -> - try - require atom.userConfigurationPath if fs.exists(atom.userConfigurationPath) - catch error - console.error "Failed to load `#{atom.userConfigurationPath}`", error.message, error - @showConsole() - requireStylesheet: (path) -> fullPath = require.resolve(path) content = fs.read(fullPath)