mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Load user configuration as part of RootView initialization, before any editors are created
This commit is contained in:
@@ -3,7 +3,6 @@ fs = require 'fs'
|
||||
|
||||
describe "Window", ->
|
||||
beforeEach ->
|
||||
spyOn(window, 'loadUserConfiguration')
|
||||
window.startup()
|
||||
|
||||
afterEach ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user