mirror of
https://github.com/atom/atom.git
synced 2026-02-14 00:25:08 -05:00
Load themes from ~/.atom/themes
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}'")
|
||||
|
||||
@@ -27,7 +27,6 @@ windowAdditions =
|
||||
startup: ->
|
||||
@config = new Config
|
||||
@syntax = new Syntax
|
||||
TextMateTheme.loadAll()
|
||||
@setUpKeymap()
|
||||
@pasteboard = new Pasteboard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user