Add a theme-added event to the theme manager

This commit is contained in:
Ben Ogle 2013-09-10 16:17:35 -07:00
parent d3eec2db05
commit 261d386809
2 changed files with 18 additions and 0 deletions

View File

@ -56,3 +56,16 @@ describe "ThemeManager", ->
spyOn(console, 'warn')
themeManager.loadTheme('a-theme-that-will-not-be-found')
expect(console.warn).toHaveBeenCalled()
describe "theme-loaded event", ->
beforeEach ->
spyOn(themeManager, 'getUserStylesheetPath').andCallFake -> null
themeManager.load()
it "fires when a new theme has been added", ->
themeManager.on 'theme-loaded', loadHandler = jasmine.createSpy()
config.set('core.themes', ['atom-dark-syntax'])
expect(loadHandler).toHaveBeenCalled()
expect(loadHandler.mostRecentCall.args[0]).toBeInstanceOf Theme

View File

@ -23,6 +23,9 @@ class ThemeManager
getAvailableNames: ->
path.basename(themePath).split('.')[0] for themePath in @getAvailablePaths()
getThemes: ->
_.clone(@loadedThemes)
unload: ->
removeStylesheet(@userStylesheetPath) if @userStylesheetPath?
theme.deactivate() while theme = @loadedThemes.pop()
@ -38,7 +41,9 @@ class ThemeManager
loadTheme: (name) ->
try
theme = new Theme(name)
@loadedThemes.push(new Theme(name))
@trigger('theme-loaded', theme)
catch error
console.warn("Failed to load theme #{name}", error.stack ? error)