From 5c12a7ceefae28abdbe2e35d1ccab256f79d8082 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 3 Sep 2013 14:39:15 -0700 Subject: [PATCH] Move base stylesheet loading into atom. Load the config during setup, but don't observe until the editor window starts up. --- src/atom.coffee | 13 +++++++++++++ src/config.coffee | 1 - src/window.coffee | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 45e807db9..7b48282cd 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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) diff --git a/src/config.coffee b/src/config.coffee index 5d317322a..6de3cd47c 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -81,7 +81,6 @@ class Config load: -> @initializeConfigDirectory() @loadUserConfig() - @observeUserConfig() # Private: loadUserConfig: -> diff --git a/src/window.coffee b/src/window.coffee index f5997334b..e1b323ee2 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -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) ->