mirror of
https://github.com/atom/atom.git
synced 2026-02-09 06:05:11 -05:00
Save config changes on update
This commit is contained in:
@@ -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