Remove ‘group’ parameter to addStyleSheet in favor of ‘priority’

This commit is contained in:
Nathan Sobo
2015-01-06 20:08:45 -07:00
parent 2c1f8ce733
commit 7dd67caf57
8 changed files with 23 additions and 77 deletions

View File

@@ -109,7 +109,7 @@ class Package
getType: -> 'atom'
getStylesheetType: -> 'bundled'
getStyleSheetPriority: -> 0
load: ->
@measure 'loadTime', =>
@@ -175,8 +175,9 @@ class Package
activateStylesheets: ->
return if @stylesheetsActivated
group = @getStylesheetType()
@stylesheetDisposables = new CompositeDisposable
priority = @getStyleSheetPriority()
for [sourcePath, source] in @stylesheets
if match = path.basename(sourcePath).match(/[^.]*\.([^.]*)\./)
context = match[1]
@@ -185,7 +186,7 @@ class Package
else
context = undefined
@stylesheetDisposables.add(atom.styles.addStyleSheet(source, {sourcePath, group, context}))
@stylesheetDisposables.add(atom.styles.addStyleSheet(source, {sourcePath, priority, context}))
@stylesheetsActivated = true
activateResources: ->

View File

@@ -92,12 +92,7 @@ class StyleManager
addStyleSheet: (source, params) ->
sourcePath = params?.sourcePath
context = params?.context
group = params?.group
priority = params?.priority ?
switch group
when 'bundled' then 0
when 'theme' then 1
when 'user' then 2
priority = params?.priority
if sourcePath? and styleElement = @styleElementsBySourcePath[sourcePath]
updated = true
@@ -111,10 +106,6 @@ class StyleManager
styleElement.context = context
styleElement.setAttribute('context', context)
if group?
styleElement.group = group
styleElement.setAttribute('group', group)
if priority?
styleElement.priority = priority
styleElement.setAttribute('priority', priority)
@@ -129,14 +120,7 @@ class StyleManager
new Disposable => @removeStyleElement(styleElement)
addStyleElement: (styleElement) ->
{sourcePath, group, priority} = styleElement
if group?
for existingElement, index in @styleElements
if existingElement.group is group
insertIndex = index + 1
else
break if insertIndex?
{sourcePath, priority} = styleElement
if priority?
for existingElement, index in @styleElements

View File

@@ -56,13 +56,6 @@ class StylesElement extends HTMLElement
styleElementClone.priority = styleElement.priority
@styleElementClonesByOriginalElement.set(styleElement, styleElementClone)
group = styleElement.getAttribute('group')
if group?
for child in @children
if child.getAttribute('group') is group and child.nextSibling?.getAttribute('group') isnt group
insertBefore = child.nextSibling
break
priority = styleElement.priority
if priority?
for child in @children

View File

@@ -219,28 +219,30 @@ class ThemeManager
#
# Returns a {Disposable} on which `.dispose()` can be called to remove the
# required stylesheet.
requireStylesheet: (stylesheetPath, type='bundled') ->
requireStylesheet: (stylesheetPath) ->
if fullPath = @resolveStylesheet(stylesheetPath)
content = @loadStylesheet(fullPath)
@applyStylesheet(fullPath, content, type)
@applyStylesheet(fullPath, content)
else
throw new Error("Could not find a file at path '#{stylesheetPath}'")
unwatchUserStylesheet: ->
@userStylesheetFile?.off()
@userStylesheetFile = null
@removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
@userStyleSheetDisposable?.dispose()
@userStyleSheetDisposable = null
loadUserStylesheet: ->
@unwatchUserStylesheet()
userStylesheetPath = atom.styles.getUserStyleSheetPath()
return unless fs.isFileSync(userStylesheetPath)
@userStylesheetPath = userStylesheetPath
@userStylesheetFile = new File(userStylesheetPath)
@userStylesheetFile.on 'contents-changed moved removed', => @loadUserStylesheet()
userStylesheetContents = @loadStylesheet(userStylesheetPath, true)
@applyStylesheet(userStylesheetPath, userStylesheetContents, 'user')
@userStyleSheetDisposable = atom.styles.addStyleSheet(userStylesheetContents, sourcePath: userStylesheetPath, priority: 2)
loadBaseStylesheets: ->
@requireStylesheet('../static/bootstrap')
@@ -291,8 +293,8 @@ class ThemeManager
removeStylesheet: (stylesheetPath) ->
@styleSheetDisposablesBySourcePath[stylesheetPath]?.dispose()
applyStylesheet: (path, text, type='bundled') ->
@styleSheetDisposablesBySourcePath[path] = atom.styles.addStyleSheet(text, sourcePath: path, group: type)
applyStylesheet: (path, text) ->
@styleSheetDisposablesBySourcePath[path] = atom.styles.addStyleSheet(text, sourcePath: path)
stringToId: (string) ->
string.replace(/\\/g, '/')

View File

@@ -5,7 +5,7 @@ module.exports =
class ThemePackage extends Package
getType: -> 'theme'
getStylesheetType: -> 'theme'
getStyleSheetPriority: -> 1
enable: ->
atom.config.unshiftAtKeyPath('core.themes', @name)