Atom Themes can be loaded

This commit is contained in:
Corey Johnson
2012-12-27 14:31:13 -08:00
parent d509507b0c
commit 0d946078c9
9 changed files with 57 additions and 9 deletions

View File

@@ -10,7 +10,7 @@ Project = require 'project'
Pane = require 'pane'
PaneColumn = require 'pane-column'
PaneRow = require 'pane-row'
TextMateTheme = require 'text-mate-theme'
Theme = require 'theme'
module.exports =
class RootView extends View
@@ -41,7 +41,7 @@ class RootView extends View
config.load()
TextMateTheme.activate(config.get("core.theme") ? 'IR_Black')
Theme.load(config.get("core.theme") ? 'IR_Black')
@handleEvents()

View File

@@ -1,17 +1,18 @@
_ = require 'underscore'
fs = require 'fs'
Theme = require 'Theme'
module.exports =
class TextMateTheme extends Theme
constructor: (@path, {settings}) ->
super
@rulesets = []
globalSettings = settings[0]
@buildGlobalSettingsRulesets(settings[0])
@buildScopeSelectorRulesets(settings[1..])
@stylesheets = {}
@stylesheets[@path] = @getStylesheet()
getStylesheet: ->
lines = []
for {selector, properties} in @getRulesets()

View File

@@ -16,7 +16,7 @@ class Theme
if @isTextMateTheme(path)
theme = @loadTextMateTheme(path)
else
throw new Error("I only know how to load textmate themes!")
theme = @loadAtomTheme(path)
if theme
theme.activate()
@@ -34,13 +34,25 @@ class Theme
theme = new TextMateTheme(path, data[0])
theme
@loadAtomTheme: (path) ->
new Theme(path)
@isTextMateTheme: (path) ->
/\.(tmTheme|plist)$/.test(path)
@stylesheets: null
constructor: (@path) ->
json = fs.read(fs.join(path, "package.json"))
@stylesheets = {}
for stylesheetName in JSON.parse(json).stylesheets
stylesheetPath = fs.join(@path, stylesheetName)
@stylesheets[stylesheetPath] = fs.read(stylesheetPath)
activate: ->
applyStylesheet(@path, @getStylesheet())
for stylesheetPath, stylesheetContent of @stylesheets
applyStylesheet(stylesheetPath, stylesheetContent)
getStylesheet: ->
fs.read(@path)
deactivate: ->
for stylesheetPath, stylesheetContent of @stylesheets
window.removeStylesheet(stylesheetPath)