Load themes from ~/.atom/themes

This commit is contained in:
Corey Johnson
2012-12-26 14:38:25 -08:00
parent bae9ae6d59
commit e5e5c497e1
7 changed files with 841 additions and 21 deletions

View File

@@ -15,7 +15,9 @@ _.extend atom,
getAvailablePackages: ->
allPackageNames = []
for packageDirPath in config.packageDirPaths
packageNames = fs.list(packageDirPath).map (packagePath) -> fs.base(packagePath)
packageNames = fs.list(packageDirPath)
.filter((packagePath) -> fs.isDirectory(packagePath))
.map((packagePath) -> fs.base(packagePath))
allPackageNames.push(packageNames...)
_.unique(allPackageNames)

View File

@@ -9,6 +9,7 @@ configDirPath = fs.absolute("~/.atom")
configJsonPath = fs.join(configDirPath, "config.json")
userInitScriptPath = fs.join(configDirPath, "atom.coffee")
bundledPackagesDirPath = fs.join(resourcePath, "src/packages")
userThemesDirPath = fs.join(configDirPath, "themes")
userPackagesDirPath = fs.join(configDirPath, "packages")
require.paths.unshift userPackagesDirPath
@@ -16,6 +17,7 @@ require.paths.unshift userPackagesDirPath
module.exports =
class Config
configDirPath: configDirPath
themeDirPath: userThemesDirPath
packageDirPaths: [userPackagesDirPath, bundledPackagesDirPath]
settings: null

View File

@@ -4,31 +4,20 @@ plist = require 'plist'
module.exports =
class TextMateTheme
@themesByName: {}
@load: (name) ->
regex = new RegExp("#{_.escapeRegExp(name)}\.(tmTheme|plist)$", "i")
path = _.find fs.list(config.themeDirPath), (path) -> regex.test(path)
return null unless path
@loadAll: ->
for themePath in fs.list(require.resolve("themes"))
@registerTheme(TextMateTheme.load(themePath))
@load: (path) ->
plistString = fs.read(require.resolve(path))
plistString = fs.read(path)
theme = null
plist.parseString plistString, (err, data) ->
throw new Error("Error loading theme at '#{path}': #{err}") if err
theme = new TextMateTheme(data[0])
theme
@registerTheme: (theme) ->
@themesByName[theme.name] = theme
@getNames: ->
_.keys(@themesByName)
@getTheme: (name) ->
@themesByName[name]
@activate: (name) ->
if theme = @getTheme(name)
if theme = @load(name)
theme.activate()
else
throw new Error("No theme with name '#{name}'")

View File

@@ -27,7 +27,6 @@ windowAdditions =
startup: ->
@config = new Config
@syntax = new Syntax
TextMateTheme.loadAll()
@setUpKeymap()
@pasteboard = new Pasteboard