Save config changes on update

This commit is contained in:
Nathan Sobo
2012-12-12 15:46:30 -08:00
parent 3c2b84a46d
commit c19c9e0d1f
4 changed files with 21 additions and 9 deletions

View File

@@ -502,7 +502,7 @@ describe "Editor", ->
editor.getBuffer().saveAs("/tmp/atom-new.txt")
expect(eventHandler).toHaveBeenCalled()
fdescribe "font size", ->
describe "font size", ->
it "sets the initial font size based on the value from config", ->
config.editor.fontSize = 20
config.update()

View File

@@ -20,9 +20,10 @@ beforeEach ->
window.fixturesProject = new Project(require.resolve('fixtures'))
window.resetTimeouts()
# don't load user configuration
# don't load or save user configuration
spyOn(config, 'load')
config.loadDefaults()
spyOn(config, 'save')
config.assignDefaults()
# make editor display updates synchronous
spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()

View File

@@ -4,10 +4,9 @@ EventEmitter = require 'event-emitter'
module.exports =
class Config
constructor: ->
@configDirPath = fs.absolute("~/.atom")
@configJsonPath = fs.join(@configDirPath, "config.json")
@userInitScriptPath = fs.join(@configDirPath, "atom.coffee")
configDirPath: fs.absolute("~/.atom")
configJsonPath: fs.absolute("~/.atom/config.json")
userInitScriptPath: fs.absolute("~/.atom/atom.coffe")
load: ->
if fs.exists(@configJsonPath)
@@ -23,8 +22,18 @@ class Config
_.defaults(@editor, require('editor').configDefaults)
update: ->
@save()
@trigger 'update'
save: ->
keysToWrite = _.clone(this)
delete keysToWrite.eventHandlersByEventName
delete keysToWrite.eventHandlersByNamespace
delete keysToWrite.configDirPath
delete keysToWrite.configJsonPath
delete keysToWrite.userInitScriptPath
fs.write(@configJsonPath, JSON.stringify(keysToWrite, undefined, 2) + "\n")
requireUserInitScript: ->
try
require @userInitScriptPath if fs.exists(@userInitScriptPath)

View File

@@ -31,9 +31,11 @@ module.exports =
[eventName, namespace] = eventName.split('.')
if namespace
@eventHandlersByNamespace?[namespace]?[eventName]?.forEach (handler) -> handler(args...)
if handlers = @eventHandlersByNamespace?[namespace]?[eventName]
new Array(handlers...).forEach (handler) -> handler(args...)
else
@eventHandlersByEventName?[eventName]?.forEach (handler) -> handler(args...)
if handlers = @eventHandlersByEventName?[eventName]
handlers.forEach (handler) -> handler(args...)
off: (eventName='', handler) ->
[eventName, namespace] = eventName.split('.')