From 5b241c1e1c5eb99f2bb074d7e9827720577caf91 Mon Sep 17 00:00:00 2001 From: Jon Rohan Date: Mon, 21 Jan 2013 16:55:21 -0800 Subject: [PATCH] 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. --- src/app/atom.coffee | 8 ++++++-- src/app/theme.coffee | 3 +-- src/app/window.coffee | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 991b12538..95cb4b20a 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -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) diff --git a/src/app/theme.coffee b/src/app/theme.coffee index 1c42fcbb0..1be21fdbf 100644 --- a/src/app/theme.coffee +++ b/src/app/theme.coffee @@ -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 diff --git a/src/app/window.coffee b/src/app/window.coffee index 9e53ed5b6..ea6866ec7 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -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 "" + if $("head style.#{ttype}").length + $("head style.#{ttype}:last").after "" + else + $("head").append "" + reload: -> if rootView?.getModifiedBuffers().length > 0