Add global config object. Config#load loads user's atom.coffee.

This commit is contained in:
Nathan Sobo
2012-12-12 11:40:09 -08:00
parent ab96129ef6
commit 9c31ab3a79
5 changed files with 17 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ $ = require 'jquery'
_ = require 'underscore'
Keymap = require 'keymap'
Point = require 'point'
RootView = require 'root-view'
Config = require 'config'
Project = require 'project'
TextMateBundle = require 'text-mate-bundle'
TextMateTheme = require 'text-mate-theme'
@@ -11,7 +11,9 @@ TextMateTheme = require 'text-mate-theme'
require 'window'
requireStylesheet "jasmine.css"
RootView.prototype.loadUserConfiguration = ->
beforeEach ->
# don't load user configuration
spyOn(config, 'load')
keymap = new Keymap
keymap.bindDefaultKeys()

View File

@@ -20,6 +20,8 @@ beforeEach ->
window.fixturesProject = new Project(require.resolve('fixtures'))
window.resetTimeouts()
# don't load user configuration
spyOn(config, 'load')
# make editor display updates synchronous
spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()
spyOn(RootView.prototype, 'updateWindowTitle').andCallFake ->
@@ -42,9 +44,6 @@ window.keymap.bindKeys '*', 'meta-w': 'close'
$(document).on 'close', -> window.close()
$('html,body').css('overflow', 'auto')
# Don't load user configuration in specs, because it's variable
RootView.prototype.loadUserConfiguration = ->
ensureNoPathSubscriptions = ->
watchedPaths = $native.getWatchedPaths()
$native.unwatchAllPaths()

7
src/app/config.coffee Normal file
View File

@@ -0,0 +1,7 @@
module.exports =
class Config
load: ->
try
require atom.configFilePath if fs.exists(atom.configFilePath)
catch error
console.error "Failed to load `#{atom.configFilePath}`", error.stack, error

View File

@@ -36,6 +36,8 @@ class RootView extends View
initialize: (pathToOpen, { @extensionStates, suppressOpen } = {}) ->
window.rootView = this
config.load()
TextMateTheme.activate('IR_Black')
@invisibles =
@@ -47,7 +49,6 @@ class RootView extends View
@extensions = {}
@project = new Project(pathToOpen)
@handleEvents()
@loadUserConfiguration()
if pathToOpen
@open(pathToOpen) if fs.isFile(pathToOpen) and not suppressOpen
@@ -263,11 +264,5 @@ class RootView extends View
getInvisibles: -> @invisibles
loadUserConfiguration: ->
try
require atom.configFilePath if fs.exists(atom.configFilePath)
catch error
console.error "Failed to load `#{atom.configFilePath}`", error.stack, error
saveAll: ->
editor.save() for editor in @getEditors()

View File

@@ -8,6 +8,7 @@ fs = require 'fs'
_ = require 'underscore'
$ = require 'jquery'
{CoffeeScript} = require 'coffee-script'
Config = require 'config'
RootView = require 'root-view'
Pasteboard = require 'pasteboard'
require 'jquery-extensions'
@@ -26,6 +27,7 @@ windowAdditions =
TextMateTheme.loadAll()
@setUpKeymap()
@pasteboard = new Pasteboard
@config = new Config
$(window).on 'core:close', => @close()
# This method is intended only to be run when starting a normal application