Use Twilight theme stylesheet based on TextMateTheme

This commit is contained in:
Nathan Sobo
2012-08-08 16:55:34 -06:00
parent 2df05e235a
commit c8154e4e8c
7 changed files with 75 additions and 132 deletions

View File

@@ -7,6 +7,7 @@ EditSession = require 'edit-session'
CursorView = require 'cursor-view'
SelectionView = require 'selection-view'
Native = require 'native'
TextMateTheme = require 'text-mate-theme'
fs = require 'fs'
$ = require 'jquery'
@@ -54,7 +55,7 @@ class Editor extends View
initialize: ({editSession, @mini} = {}) ->
requireStylesheet 'editor.css'
requireStylesheet 'theme/twilight.css'
TextMateTheme.activate('Twilight')
@id = Editor.idCounter++
@lineCache = []

View File

@@ -1,13 +1,56 @@
_ = require 'underscore'
fs = require 'fs'
plist = require 'plist'
module.exports =
class TextMateTheme
@themesByName: {}
@loadAll: ->
for themePath in fs.list(require.resolve("themes"))
@registerTheme(TextMateTheme.load(themePath))
@load: (path) ->
plistString = fs.read(require.resolve(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)
theme.activate()
else
throw new Error("No theme with name '#{name}'")
constructor: ({@name, settings}) ->
@rulesets = []
globalSettings = settings[0]
@buildGlobalSettingsRulesets(settings[0])
@buildScopeSelectorRulesets(settings[1..])
activate: ->
applyStylesheet(@name, @getStylesheet())
getStylesheet: ->
lines = []
for {selector, properties} in @getRulesets()
lines.push("#{selector} {")
for name, value of properties
lines.push " #{name}: #{value};"
lines.push("}\n")
lines.join("\n")
getRulesets: -> @rulesets
buildGlobalSettingsRulesets: ({settings}) ->
@@ -38,7 +81,8 @@ class TextMateTheme
properties: @translateScopeSelectorSettings(settings)
translateScopeSelector: (textmateScopeSelector) ->
textmateScopeSelector.replace('.', '--')
scopes = textmateScopeSelector.replace(/\./g, '-').split(/\s+/).map (scope) -> '.' + scope
scopes.join(' ')
translateScopeSelectorSettings: ({ foreground, background, fontStyle }) ->
properties = {}

View File

@@ -3,6 +3,7 @@
Native = require 'native'
TextMateBundle = require 'text-mate-bundle'
TextMateTheme = require 'text-mate-theme'
fs = require 'fs'
_ = require 'underscore'
$ = require 'jquery'
@@ -25,6 +26,8 @@ windowAdditions =
startup: (path) ->
TextMateBundle.loadAll()
TextMateTheme.loadAll()
@attachRootView(path)
$(window).on 'close', => @close()
$(window).on 'beforeunload', =>