From 26d696a93ddaa758bc12f4b42ec623b4dd5bb7fa Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 21 Aug 2014 11:53:10 -0700 Subject: [PATCH] Add classes to the workspace for themes Fixes #3097 --- spec/theme-manager-spec.coffee | 15 +++++++++++++++ src/theme-manager.coffee | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index 8b503dd0a..d3a30c589 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -247,6 +247,21 @@ describe "ThemeManager", -> # from within the theme itself expect($(".editor").css("background-color")).toBe "rgb(0, 152, 255)" + describe "theme classes on the workspace", -> + it 'adds theme-* classes to the workspace for each active theme', -> + expect(atom.workspaceView).toHaveClass 'theme-atom-dark-ui' + + themeManager.on 'reloaded', reloadHandler = jasmine.createSpy() + atom.config.set('core.themes', ['theme-with-ui-variables']) + + waitsFor -> + reloadHandler.callCount > 0 + + runs -> + # `theme-` twice as it prefixes the name with `theme-` + expect(atom.workspaceView).toHaveClass 'theme-theme-with-ui-variables' + expect(atom.workspaceView).not.toHaveClass 'theme-atom-dark-ui' + describe "when the user stylesheet changes", -> it "reloads it", -> [stylesheetRemovedHandler, stylesheetAddedHandler, stylesheetsChangedHandler] = [] diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 98e0f4620..542227187 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -94,6 +94,7 @@ class ThemeManager console.warn("Failed to activate theme '#{themeName}' because it isn't installed.") Q.all(promises).then => + @addActiveThemeClasses() @refreshLessCache() # Update cache again now that @getActiveThemes() is populated @loadUserStylesheet() @reloadBaseStylesheets() @@ -103,10 +104,21 @@ class ThemeManager deferred.promise deactivateThemes: -> + @removeActiveThemeClasses() @unwatchUserStylesheet() @packageManager.deactivatePackage(pack.name) for pack in @getActiveThemes() null + addActiveThemeClasses: -> + for pack in @getActiveThemes() + atom.workspaceView?[0]?.classList.add("theme-#{pack.name}") + return + + removeActiveThemeClasses: -> + for pack in @getActiveThemes() + atom.workspaceView?[0]?.classList.remove("theme-#{pack.name}") + return + refreshLessCache: -> @lessCache?.setImportPaths(@getImportPaths())