Load user configuration as part of RootView initialization, before any editors are created

This commit is contained in:
Nathan Sobo
2012-06-20 16:06:45 -06:00
parent c97d78a31d
commit b4d77fd107
4 changed files with 27 additions and 20 deletions

View File

@@ -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()

View File

@@ -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)