From c4bbd2bbf273cadb321bff1ba1486ec5e7e53a05 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 28 Sep 2015 15:30:06 -0600 Subject: [PATCH] Build StyleManager in Atom environment constructor --- spec/style-manager-spec.coffee | 2 +- src/atom.coffee | 12 +++++++----- src/package-manager.coffee | 12 ++++++------ src/style-manager.coffee | 6 +++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/spec/style-manager-spec.coffee b/spec/style-manager-spec.coffee index 7e601bcc1..d0a1cfe13 100644 --- a/spec/style-manager-spec.coffee +++ b/spec/style-manager-spec.coffee @@ -4,7 +4,7 @@ describe "StyleManager", -> [manager, addEvents, removeEvents, updateEvents] = [] beforeEach -> - manager = new StyleManager + manager = new StyleManager(configDirPath: atom.getConfigDirPath()) addEvents = [] removeEvents = [] updateEvents = [] diff --git a/src/atom.coffee b/src/atom.coffee index 6154a33ef..e7b35b3b2 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -152,7 +152,7 @@ class Atom extends Model # Call .loadOrCreate instead constructor: (@state) -> {@mode} = @state - {resourcePath} = @getLoadSettings() + {devMode, safeMode, resourcePath} = @getLoadSettings() configDirPath = @getConfigDirPath() @emitter = new Emitter @@ -180,6 +180,12 @@ class Atom extends Model ViewRegistry = require './view-registry' @views = new ViewRegistry + PackageManager = require './package-manager' + @packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode, @config}) + + StyleManager = require './style-manager' + @styles = new StyleManager({configDirPath}) + reset: -> @config.reset() @@ -216,11 +222,9 @@ class Atom extends Model @loadTime = null - PackageManager = require './package-manager' Clipboard = require './clipboard' GrammarRegistry = require './grammar-registry' ThemeManager = require './theme-manager' - StyleManager = require './style-manager' ContextMenuManager = require './context-menu-manager' MenuManager = require './menu-manager' {devMode, safeMode, resourcePath} = @getLoadSettings() @@ -238,8 +242,6 @@ class Atom extends Model @keymaps.subscribeToFileReadFailure() @registerViewProviders() - @packages = new PackageManager({devMode, configDirPath, resourcePath, safeMode}) - @styles = new StyleManager document.head.appendChild(new StylesElement) @themes = new ThemeManager({packageManager: @packages, configDirPath, resourcePath, safeMode}) @contextMenu = new ContextMenuManager({resourcePath, devMode}) diff --git a/src/package-manager.coffee b/src/package-manager.coffee index 7e4a19470..f36a0c389 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -26,7 +26,7 @@ ThemePackage = require './theme-package' # settings and also by calling `enablePackage()/disablePackage()`. module.exports = class PackageManager - constructor: ({configDirPath, @devMode, safeMode, @resourcePath}) -> + constructor: ({configDirPath, @devMode, safeMode, @resourcePath, @config}) -> @emitter = new Emitter @activationHookEmitter = new Emitter @packageDirPaths = [] @@ -185,7 +185,7 @@ class PackageManager # # Returns a {Boolean}. isPackageDisabled: (name) -> - _.include(atom.config.get('core.disabledPackages') ? [], name) + _.include(@config.get('core.disabledPackages') ? [], name) ### Section: Accessing active packages @@ -300,7 +300,7 @@ class PackageManager @disabledPackagesSubscription = null observeDisabledPackages: -> - @disabledPackagesSubscription ?= atom.config.onDidChange 'core.disabledPackages', ({newValue, oldValue}) => + @disabledPackagesSubscription ?= @config.onDidChange 'core.disabledPackages', ({newValue, oldValue}) => packagesToEnable = _.difference(oldValue, newValue) packagesToDisable = _.difference(newValue, oldValue) @@ -313,7 +313,7 @@ class PackageManager @packagesWithKeymapsDisabledSubscription = null observePackagesWithKeymapsDisabled: -> - @packagesWithKeymapsDisabledSubscription ?= atom.config.onDidChange 'core.packagesWithKeymapsDisabled', ({newValue, oldValue}) => + @packagesWithKeymapsDisabledSubscription ?= @config.onDidChange 'core.packagesWithKeymapsDisabled', ({newValue, oldValue}) => keymapsToEnable = _.difference(oldValue, newValue) keymapsToDisable = _.difference(newValue, oldValue) @@ -392,7 +392,7 @@ class PackageManager activatePackages: (packages) -> promises = [] - atom.config.transact => + @config.transact => for pack in packages promise = @activatePackage(pack.name) promises.push(promise) unless pack.hasActivationCommands() @@ -423,7 +423,7 @@ class PackageManager # Deactivate all packages deactivatePackages: -> - atom.config.transact => + @config.transact => @deactivatePackage(pack.name) for pack in @getLoadedPackages() return @unobserveDisabledPackages() diff --git a/src/style-manager.coffee b/src/style-manager.coffee index cfe86b3fe..11dc4b97f 100644 --- a/src/style-manager.coffee +++ b/src/style-manager.coffee @@ -9,7 +9,7 @@ path = require 'path' # which clone and attach style elements in different contexts. module.exports = class StyleManager - constructor: -> + constructor: ({@configDirPath}) -> @emitter = new Emitter @styleElements = [] @styleElementsBySourcePath = {} @@ -162,8 +162,8 @@ class StyleManager # # Returns a {String}. getUserStyleSheetPath: -> - stylesheetPath = fs.resolve(path.join(atom.getConfigDirPath(), 'styles'), ['css', 'less']) + stylesheetPath = fs.resolve(path.join(@configDirPath, 'styles'), ['css', 'less']) if fs.isFileSync(stylesheetPath) stylesheetPath else - path.join(atom.getConfigDirPath(), 'styles.less') + path.join(@configDirPath, 'styles.less')