From 60c5293b5e2040e31bc0e283304b35f1b63a400f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 23 Dec 2014 11:14:09 -0800 Subject: [PATCH] Add Config::getSources The settings-view needs this so that it can display snippets associated with packages --- spec/config-spec.coffee | 15 +++++++++++++++ src/config.coffee | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 9640fae3e..cba506dd8 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -335,6 +335,21 @@ describe "Config", -> expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 10 + describe ".getSources()", -> + it "returns an array of all of the config's source names", -> + expect(atom.config.getSources()).toEqual([]) + + atom.config.set("a.b", 1, scopeSelector: ".x1", source: "source-1") + atom.config.set("a.c", 1, scopeSelector: ".x1", source: "source-1") + atom.config.set("a.b", 2, scopeSelector: ".x2", source: "source-2") + atom.config.set("a.b", 1, scopeSelector: ".x3", source: "source-3") + + expect(atom.config.getSources()).toEqual([ + "source-1" + "source-2" + "source-3" + ]) + describe ".getSettings()", -> it "returns all settings including defaults", -> atom.config.setDefaults("foo", bar: baz: 10) diff --git a/src/config.coffee b/src/config.coffee index d0d8f7d2f..953136627 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -605,6 +605,11 @@ class Config else @set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath)) + # Extended: Get an {Array} of all of the `source` {String}s with which + # settings have been added via {::set}. + getSources: -> + _.uniq(_.pluck(@scopedSettingsStore.propertySets, 'source')).sort() + # Deprecated: Restore the global setting at `keyPath` to its default value. # # Returns the new value.