mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
* Move src/app to src/ * Move src/stdlib to src/ * Remove src/app and src/stdlib from NODE_PATH
59 lines
1.6 KiB
CoffeeScript
59 lines
1.6 KiB
CoffeeScript
path = require 'path'
|
|
EventEmitter = require 'event-emitter'
|
|
|
|
_ = require 'underscore'
|
|
|
|
fsUtils = require 'fs-utils'
|
|
Theme = require 'theme'
|
|
|
|
module.exports =
|
|
class ThemeManager
|
|
_.extend @prototype, EventEmitter
|
|
|
|
constructor: ->
|
|
@loadedThemes = []
|
|
|
|
getAvailablePaths: ->
|
|
themePaths = []
|
|
for themeDirPath in config.themeDirPaths
|
|
themePaths.push(fsUtils.listSync(themeDirPath, ['', '.css', 'less'])...)
|
|
_.uniq(themePaths)
|
|
|
|
getAvailableNames: ->
|
|
path.basename(themePath).split('.')[0] for themePath in @getAvailablePaths()
|
|
|
|
unload: ->
|
|
removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
|
|
theme.deactivate() while theme = @loadedThemes.pop()
|
|
|
|
load: ->
|
|
config.observe 'core.themes', (themeNames) =>
|
|
@unload()
|
|
themeNames = [themeNames] unless _.isArray(themeNames)
|
|
@loadTheme(themeName) for themeName in themeNames
|
|
@loadUserStylesheet()
|
|
|
|
@trigger('reloaded')
|
|
|
|
loadTheme: (name) ->
|
|
try
|
|
@loadedThemes.push(new Theme(name))
|
|
catch error
|
|
console.warn("Failed to load theme #{name}", error.stack ? error)
|
|
|
|
getUserStylesheetPath: ->
|
|
stylesheetPath = fsUtils.resolve(path.join(config.configDirPath, 'user'), ['css', 'less'])
|
|
if fsUtils.isFileSync(stylesheetPath)
|
|
stylesheetPath
|
|
else
|
|
null
|
|
|
|
getImportPaths: ->
|
|
theme.directoryPath for theme in @loadedThemes when theme.directoryPath
|
|
|
|
loadUserStylesheet: ->
|
|
if userStylesheetPath = @getUserStylesheetPath()
|
|
@userStylesheetPath = userStylesheetPath
|
|
userStylesheetContents = loadStylesheet(userStylesheetPath)
|
|
applyStylesheet(userStylesheetPath, userStylesheetContents, 'userTheme')
|