In requireStylesheet, check loadedThemes for the required stylesheet

I've made requireStylesheet also check the loadedThemes for the
requiredStylesheet.

In the event that we have 2 stylesheets with the same name `editor.css`
and `editor.css` I want the `static/` directory stylesheet to be above
the userTheme stylesheet, so that proper cascading occurs. This commit
also adding class names to the styles.
This commit is contained in:
Jon Rohan
2013-01-21 16:55:21 -08:00
parent 2001f0b7f1
commit 5b241c1e1c
3 changed files with 19 additions and 8 deletions

View File

@@ -9,7 +9,7 @@ originalSendMessageToBrowserProcess = atom.sendMessageToBrowserProcess
_.extend atom,
exitWhenDone: window.location.params.exitWhenDone
loadedThemes: []
pendingBrowserProcessCallbacks: {}
loadPackages: ->
@@ -44,7 +44,11 @@ _.extend atom,
@loadTheme(themeName) for themeName in themeNames
loadTheme: (name) ->
Theme.load(name)
@loadedThemes.push Theme.load(name)
getAtomThemeStylesheets: ->
themeNames = config.get("core.themes") ? ['Atom - Dark', 'IR_Black']
themeNames = [themeNames] unless _.isArray(themeNames)
open: (args...) ->
@sendMessageToBrowserProcess('open', args)

View File

@@ -21,7 +21,6 @@ class Theme
if TextMateTheme.testPath(path)
new TextMateTheme(path)
else
require.paths.unshift path
new AtomTheme(path)
theme.load()
@@ -32,7 +31,7 @@ class Theme
load: ->
for stylesheetPath, stylesheetContent of @stylesheets
applyStylesheet(stylesheetPath, stylesheetContent)
applyStylesheet(stylesheetPath, stylesheetContent, 'userTheme')
deactivate: ->
for stylesheetPath, stylesheetContent of @stylesheets

View File

@@ -70,18 +70,26 @@ windowAdditions =
$("head style[id='#{id}']")
requireStylesheet: (path) ->
unless fullPath = require.resolve(path)
if fullPath = require.resolve(path)
window.applyStylesheet(fullPath, fs.read(fullPath))
for theme in atom.loadedThemes
for themePath, css of theme.stylesheets
matched = true if themePath.match(path)
unless fullPath || matched
throw new Error("Could not find a file at path '#{path}'")
window.applyStylesheet(fullPath, fs.read(fullPath))
removeStylesheet: (path) ->
unless fullPath = require.resolve(path)
throw new Error("Could not find a file at path '#{path}'")
window.stylesheetElementForId(fullPath).remove()
applyStylesheet: (id, text) ->
applyStylesheet: (id, text, ttype = 'bundled') ->
unless window.stylesheetElementForId(id).length
$('head').append "<style id='#{id}'>#{text}</style>"
if $("head style.#{ttype}").length
$("head style.#{ttype}:last").after "<style class='#{ttype}' id='#{id}'>#{text}</style>"
else
$("head").append "<style class='#{ttype}' id='#{id}'>#{text}</style>"
reload: ->
if rootView?.getModifiedBuffers().length > 0