diff --git a/src/app/config.coffee b/src/app/config.coffee index 02d719a9a..8d4d38afc 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -88,7 +88,19 @@ class Config @watchSubscription?.close() @watchSubscription = null - # Public: Retrieves the setting for the given key. + setDefaults: (keyPath, defaults) -> + keys = keyPath.split('.') + hash = @defaultSettings + for key in keys + hash[key] ?= {} + hash = hash[key] + + _.extend hash, defaults + @update() + + ### Public ### + + # Retrieves the setting for the given key. # # keyPath - The {String} name of the key to retrieve # @@ -98,25 +110,28 @@ class Config _.valueForKeyPath(@settings, keyPath) ? _.valueForKeyPath(@defaultSettings, keyPath) - # Public: Retrieves the setting for the given key as an integer number. + + # Retrieves the setting for the given key as an integer. # # keyPath - The {String} name of the key to retrieve + # # Returns the value from Atom's default settings, the user's configuration file, # or `NaN` if the key doesn't exist in either. getInt: (keyPath, defaultValueWhenFalsy) -> parseInt(@get(keyPath)) - # Public: Retrieves the setting for the given key as a positive integer number. + # Retrieves the setting for the given key as a positive integer. # # keyPath - The {String} name of the key to retrieve # defaultValue - The integer {Number} to fall back to if the value isn't # positive + # # Returns the value from Atom's default settings, the user's configuration file, # or `defaultValue` if the key value isn't greater than zero. getPositiveInt: (keyPath, defaultValue) -> Math.max(@getInt(keyPath), 0) or defaultValue - - # Public: Sets the value for a configuration setting. + + # Sets the value for a configuration setting. # # This value is stored in Atom's internal configuration file. # @@ -129,17 +144,7 @@ class Config @update() value - setDefaults: (keyPath, defaults) -> - keys = keyPath.split('.') - hash = @defaultSettings - for key in keys - hash[key] ?= {} - hash = hash[key] - - _.extend hash, defaults - @update() - - # Public: Establishes an event listener for a given key. + # Establishes an event listener for a given key. # # Whenever the value of the key is changed, a callback is fired. # @@ -160,6 +165,18 @@ class Config callback(value) subscription + ### Internal ### + + setDefaults: (keyPath, defaults) -> + keys = keyPath.split('.') + hash = @defaultSettings + for key in keys + hash[key] ?= {} + hash = hash[key] + + _.extend hash, defaults + @update() + update: -> return if @configFileHasErrors @save()