mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Reload user stylesheet when changed
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
path = require 'path'
|
||||
|
||||
{$, $$, fs, WorkspaceView} = require 'atom'
|
||||
temp = require 'temp'
|
||||
|
||||
ThemeManager = require '../src/theme-manager'
|
||||
AtomPackage = require '../src/atom-package'
|
||||
@@ -155,3 +157,29 @@ describe "ThemeManager", ->
|
||||
expect($(".editor").css("padding-top")).toBe "150px"
|
||||
expect($(".editor").css("padding-right")).toBe "150px"
|
||||
expect($(".editor").css("padding-bottom")).toBe "150px"
|
||||
|
||||
describe "when the user stylesheet changes", ->
|
||||
it "reloads it", ->
|
||||
userStylesheetPath = path.join(temp.mkdirSync("atom"), 'user.css')
|
||||
fs.writeFileSync(userStylesheetPath, 'body {border-style: dotted !important;}')
|
||||
|
||||
spyOn(themeManager, 'getUserStylesheetPath').andReturn userStylesheetPath
|
||||
themeManager.activateThemes()
|
||||
|
||||
expect($(document.body).css('border-style')).toBe 'dotted'
|
||||
spyOn(themeManager, 'loadUserStylesheet').andCallThrough()
|
||||
|
||||
fs.writeFileSync(userStylesheetPath, 'body {border-style: dashed}')
|
||||
|
||||
waitsFor ->
|
||||
themeManager.loadUserStylesheet.callCount is 1
|
||||
|
||||
runs ->
|
||||
expect($(document.body).css('border-style')).toBe 'dashed'
|
||||
fs.removeSync(userStylesheetPath)
|
||||
|
||||
waitsFor ->
|
||||
themeManager.loadUserStylesheet.callCount is 2
|
||||
|
||||
runs ->
|
||||
expect($(document.body).css('border-style')).toBe 'none'
|
||||
|
||||
@@ -4,6 +4,7 @@ _ = require 'underscore-plus'
|
||||
{Emitter} = require 'emissary'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
File = require './file'
|
||||
Package = require './package'
|
||||
AtomPackage = require './atom-package'
|
||||
{$} = require './space-pen-extensions'
|
||||
@@ -71,7 +72,7 @@ class ThemeManager
|
||||
|
||||
# Internal-only:
|
||||
deactivateThemes: ->
|
||||
@removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
|
||||
@unwatchUserStylesheet()
|
||||
@packageManager.deactivatePackage(pack.name) for pack in @getActiveThemes()
|
||||
null
|
||||
|
||||
@@ -106,12 +107,23 @@ class ThemeManager
|
||||
else
|
||||
null
|
||||
|
||||
#Private:
|
||||
unwatchUserStylesheet: ->
|
||||
@userStylesheetFile?.off()
|
||||
@removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
|
||||
|
||||
# Private:
|
||||
loadUserStylesheet: ->
|
||||
if userStylesheetPath = @getUserStylesheetPath()
|
||||
@userStylesheetPath = userStylesheetPath
|
||||
userStylesheetContents = @loadStylesheet(userStylesheetPath)
|
||||
@applyStylesheet(userStylesheetPath, userStylesheetContents, 'userTheme')
|
||||
@unwatchUserStylesheet()
|
||||
userStylesheetPath = @getUserStylesheetPath()
|
||||
return unless fs.isFileSync(userStylesheetPath)
|
||||
|
||||
@userStylesheetPath = userStylesheetPath
|
||||
@userStylesheetFile = new File(userStylesheetPath)
|
||||
@userStylesheetFile.on 'contents-changed moved removed', =>
|
||||
@loadUserStylesheet()
|
||||
userStylesheetContents = @loadStylesheet(userStylesheetPath)
|
||||
@applyStylesheet(userStylesheetPath, userStylesheetContents, 'userTheme')
|
||||
|
||||
# Internal-only:
|
||||
loadBaseStylesheets: ->
|
||||
@@ -178,8 +190,7 @@ class ThemeManager
|
||||
|
||||
# Internal-only:
|
||||
removeStylesheet: (stylesheetPath) ->
|
||||
unless fullPath = @resolveStylesheet(stylesheetPath)
|
||||
throw new Error("Could not find a file at path '#{stylesheetPath}'")
|
||||
fullPath = @resolveStylesheet(stylesheetPath) ? stylesheetPath
|
||||
@stylesheetElementForId(@stringToId(fullPath)).remove()
|
||||
|
||||
# Internal-only:
|
||||
|
||||
Reference in New Issue
Block a user