mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Clean up theme check in PackageManager with PackageActivators
You can now call `PackageManager.registerPackageActivator` for specific package types. On `PackageManager.activate` it will call your `PackageActivator.activatePackages(packages)` with the proper packages.
This commit is contained in:
@@ -33,6 +33,9 @@ class PackageManager
|
||||
@packageStates = {}
|
||||
@observingDisabledPackages = false
|
||||
|
||||
@packageActivators = []
|
||||
@registerPackageActivator(this, ['atom', 'textmate'])
|
||||
|
||||
getPackageState: (name) ->
|
||||
@packageStates[name]
|
||||
|
||||
@@ -51,12 +54,23 @@ class PackageManager
|
||||
pack?.disable()
|
||||
pack
|
||||
|
||||
activatePackages: ->
|
||||
# ThemeManager handles themes. Only activate non theme packages
|
||||
# This is the only part I dislike
|
||||
@activatePackage(pack.name) for pack in @getLoadedPackages() when not pack.isTheme()
|
||||
# Internal-only: Activate all the packages that should be activated.
|
||||
activate: ->
|
||||
for [activator, types] in @packageActivators
|
||||
packages = @getLoadedPackagesForTypes(types)
|
||||
activator.activatePackages(packages)
|
||||
|
||||
# Public: another type of package manager can handle other package types.
|
||||
# See ThemeManager
|
||||
registerPackageActivator: (activator, types) ->
|
||||
@packageActivators.push([activator, types])
|
||||
|
||||
# Internal-only:
|
||||
activatePackages: (packages) ->
|
||||
@activatePackage(pack.name) for pack in packages
|
||||
@observeDisabledPackages()
|
||||
|
||||
# Internal-only: Activate a single package by name
|
||||
activatePackage: (name, options) ->
|
||||
return pack if pack = @getActivePackage(name)
|
||||
if pack = @loadPackage(name, options)
|
||||
@@ -143,6 +157,12 @@ class PackageManager
|
||||
getLoadedPackages: ->
|
||||
_.values(@loadedPackages)
|
||||
|
||||
# Private: Get packages for a certain package type
|
||||
#
|
||||
# * types: an {Array} of {String}s like ['atom', 'textmate']
|
||||
getLoadedPackagesForTypes: (types) ->
|
||||
pack for pack in @getLoadedPackages() when pack.getType() in types
|
||||
|
||||
resolvePackagePath: (name) ->
|
||||
return name if fsUtils.isDirectorySync(name)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ class ThemeManager
|
||||
|
||||
constructor: (@packageManager) ->
|
||||
@lessCache = null
|
||||
@packageManager.registerPackageActivator(this, ['theme'])
|
||||
|
||||
# Internal-only:
|
||||
getAvailableNames: ->
|
||||
@@ -38,6 +39,9 @@ class ThemeManager
|
||||
getLoadedThemes: ->
|
||||
pack for pack in @packageManager.getLoadedPackages() when pack.isTheme()
|
||||
|
||||
# Internal-only: adhere to the PackageActivator interface
|
||||
activatePackages: (themePackages) -> @activateThemes()
|
||||
|
||||
# Internal-only:
|
||||
activateThemes: ->
|
||||
# atom.config.observe runs the callback once, then on subsequent changes.
|
||||
|
||||
@@ -52,8 +52,7 @@ window.startEditorWindow = ->
|
||||
atom.themes.loadBaseStylesheets()
|
||||
atom.packages.loadPackages()
|
||||
deserializeEditorWindow()
|
||||
atom.themes.activateThemes()
|
||||
atom.packages.activatePackages()
|
||||
atom.packages.activate()
|
||||
atom.keymap.loadUserKeymaps()
|
||||
atom.requireUserInitScript()
|
||||
atom.menu.update()
|
||||
|
||||
Reference in New Issue
Block a user