Move base stylesheet loading into atom.

Load the config during setup, but don't observe until the editor window
starts up.
This commit is contained in:
Ben Ogle
2013-09-03 14:39:15 -07:00
parent 9c5c05ff41
commit 5c12a7ceef
3 changed files with 26 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ telepath = require 'telepath'
ThemeManager = require 'theme-manager'
window.atom =
baseStylesheetPaths: []
loadedPackages: {}
activePackages: {}
packageStates: {}
@@ -58,6 +59,7 @@ window.atom =
loadPackages: ->
@loadPackage(name) for name in @getAvailablePackageNames() when not @isPackageDisabled(name)
@themes.on 'reloaded', =>
@loadBaseStylesheets()
pack.reloadStylesheets?() for name, pack of @loadedPackages
null
@@ -130,6 +132,17 @@ window.atom =
packages.push(metadata)
packages
loadBaseStylesheets: ->
@unloadBaseStylesheets()
@baseStylesheetPaths.push(requireStylesheet('atom'))
if nativeStylesheetPath = fsUtils.resolveOnLoadPath(process.platform, ['css', 'less'])
requireStylesheet(nativeStylesheetPath)
@baseStylesheetPaths.push(nativeStylesheetPath)
unloadBaseStylesheets: ->
removeStylesheet(sheet) for sheet in @baseStylesheetPaths
@baseStylesheetPaths = []
open: (options) ->
ipc.sendChannel('open', options)

View File

@@ -81,7 +81,6 @@ class Config
load: ->
@initializeConfigDirectory()
@loadUserConfig()
@observeUserConfig()
# Private:
loadUserConfig: ->

View File

@@ -35,10 +35,8 @@ window.setUpEnvironment = (windowMode) ->
window.pasteboard = new Pasteboard
window.keymap = new Keymap()
requireStylesheet 'atom'
if nativeStylesheetPath = fsUtils.resolveOnLoadPath(process.platform, ['css', 'less'])
requireStylesheet(nativeStylesheetPath)
config.load()
atom.loadBaseStylesheets()
# This method is only called when opening a real application window
window.startEditorWindow = ->
@@ -47,7 +45,7 @@ window.startEditorWindow = ->
windowEventHandler = new WindowEventHandler
restoreDimensions()
config.load()
config.observeUserConfig()
keymap.loadBundledKeymaps()
atom.themes.load()
atom.loadPackages()
@@ -69,6 +67,7 @@ window.unloadEditorWindow = ->
windowState.set('project', project.serialize())
windowState.set('syntax', syntax.serialize())
windowState.set('rootView', rootView.serialize())
config.unobserveUserConfig()
atom.deactivatePackages()
windowState.set('packageStates', atom.packageStates)
atom.saveWindowState()
@@ -126,6 +125,12 @@ window.resolveStylesheet = (stylesheetPath) ->
else
fsUtils.resolveOnLoadPath(stylesheetPath, ['css', 'less'])
# Public: resolves and applies the stylesheet specified by the path.
#
# * stylesheetPath: String. Can be an absolute path or the name of a CSS or
# LESS file in the stylesheets path.
#
# Returns the absolute path to the stylesheet
window.requireStylesheet = (stylesheetPath) ->
if fullPath = window.resolveStylesheet(stylesheetPath)
content = window.loadStylesheet(fullPath)
@@ -133,6 +138,8 @@ window.requireStylesheet = (stylesheetPath) ->
else
throw new Error("Could not find a file at path '#{stylesheetPath}'")
fullPath
window.loadStylesheet = (stylesheetPath) ->
if path.extname(stylesheetPath) is '.less'
loadLessStylesheet(stylesheetPath)
@@ -146,6 +153,7 @@ window.loadLessStylesheet = (lessStylesheetPath) ->
paths: importPaths.concat(config.lessSearchPaths)
filename: lessStylesheetPath
console.log importPaths.concat(config.lessSearchPaths)
try
content = null
parser.parse fsUtils.read(lessStylesheetPath), (e, tree) ->