From 261d3868097348ccb3bd5f76aedc36eec0a88789 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 10 Sep 2013 16:17:35 -0700 Subject: [PATCH] Add a theme-added event to the theme manager --- spec/theme-manager-spec.coffee | 13 +++++++++++++ src/theme-manager.coffee | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index 2c2aac46a..83733cdc9 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -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 diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 71de7295a..ea3aca9a4 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -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)