Build StyleManager in Atom environment constructor

This commit is contained in:
Nathan Sobo 2015-09-28 15:30:06 -06:00
parent 33e7af611e
commit c4bbd2bbf2
4 changed files with 17 additions and 15 deletions

View File

@ -4,7 +4,7 @@ describe "StyleManager", ->
[manager, addEvents, removeEvents, updateEvents] = []
beforeEach ->
manager = new StyleManager
manager = new StyleManager(configDirPath: atom.getConfigDirPath())
addEvents = []
removeEvents = []
updateEvents = []

View File

@ -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})

View File

@ -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()

View File

@ -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')