mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Save config changes on update
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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('.')
|
||||
|
||||
Reference in New Issue
Block a user