From 30513cfde0c36ebdf07da7621d44cda7f1926df6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 8 Jan 2015 17:51:09 -0800 Subject: [PATCH] Rename ThemeManager methods for clarity/consistency Signed-off-by: Max Brunsfeld --- spec/package-manager-spec.coffee | 11 +++++---- spec/text-editor-element-spec.coffee | 2 +- spec/theme-manager-spec.coffee | 36 ++++++++++++++-------------- src/atom.coffee | 2 +- src/text-editor-component.coffee | 2 +- src/theme-manager.coffee | 20 ++++++++++++---- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/spec/package-manager-spec.coffee b/spec/package-manager-spec.coffee index 66c6167dd..6539f6faa 100644 --- a/spec/package-manager-spec.coffee +++ b/spec/package-manager-spec.coffee @@ -645,7 +645,7 @@ describe "PackageManager", -> expect(console.warn.callCount).toBe 1 describe "with themes", -> - reloadedHandler = null + didChangeActiveThemesHandler = null beforeEach -> waitsForPromise -> @@ -670,17 +670,18 @@ describe "PackageManager", -> expect(atom.config.get('core.themes')).toContain packageName expect(atom.config.get('core.disabledPackages')).not.toContain packageName - reloadedHandler = jasmine.createSpy('reloadedHandler') - reloadedHandler.reset() - atom.themes.onDidReloadAll reloadedHandler + didChangeActiveThemesHandler = jasmine.createSpy('didChangeActiveThemesHandler') + didChangeActiveThemesHandler.reset() + atom.themes.onDidChangeActiveThemes didChangeActiveThemesHandler pack = atom.packages.disablePackage(packageName) waitsFor -> - reloadedHandler.callCount is 1 + didChangeActiveThemesHandler.callCount is 1 runs -> expect(atom.packages.getActivePackages()).not.toContain pack expect(atom.config.get('core.themes')).not.toContain packageName expect(atom.config.get('core.themes')).not.toContain packageName expect(atom.config.get('core.disabledPackages')).not.toContain packageName + diff --git a/spec/text-editor-element-spec.coffee b/spec/text-editor-element-spec.coffee index 9517b1c34..35e13fb17 100644 --- a/spec/text-editor-element-spec.coffee +++ b/spec/text-editor-element-spec.coffee @@ -107,7 +107,7 @@ describe "TextEditorElement", -> spyOn(atom.themes, 'isInitialLoadComplete').andCallFake -> initialThemeLoadComplete - spyOn(atom.themes, 'onDidReloadAll').andCallFake (fn) -> + spyOn(atom.themes, 'onDidChangeActiveThemes').andCallFake (fn) -> themeReloadCallback = fn atom.config.set("editor.useShadowDOM", false) diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index fc9624f93..d74e9d74b 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -73,54 +73,54 @@ describe "ThemeManager", -> describe "when the core.themes config value changes", -> it "add/removes stylesheets to reflect the new config value", -> - themeManager.onDidReloadAll reloadHandler = jasmine.createSpy() + themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() spyOn(atom.styles, 'getUserStyleSheetPath').andCallFake -> null waitsForPromise -> themeManager.activateThemes() runs -> - reloadHandler.reset() + didChangeActiveThemesHandler.reset() atom.config.set('core.themes', []) waitsFor -> - reloadHandler.callCount == 1 + didChangeActiveThemesHandler.callCount == 1 runs -> - reloadHandler.reset() + didChangeActiveThemesHandler.reset() expect($('style.theme')).toHaveLength 0 atom.config.set('core.themes', ['atom-dark-ui']) waitsFor -> - reloadHandler.callCount == 1 + didChangeActiveThemesHandler.callCount == 1 runs -> - reloadHandler.reset() + didChangeActiveThemesHandler.reset() expect($('style[priority=1]')).toHaveLength 2 expect($('style[priority=1]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/ atom.config.set('core.themes', ['atom-light-ui', 'atom-dark-ui']) waitsFor -> - reloadHandler.callCount == 1 + didChangeActiveThemesHandler.callCount == 1 runs -> - reloadHandler.reset() + didChangeActiveThemesHandler.reset() expect($('style[priority=1]')).toHaveLength 2 expect($('style[priority=1]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/ expect($('style[priority=1]:eq(1)').attr('source-path')).toMatch /atom-light-ui/ atom.config.set('core.themes', []) waitsFor -> - reloadHandler.callCount == 1 + didChangeActiveThemesHandler.callCount == 1 runs -> - reloadHandler.reset() + didChangeActiveThemesHandler.reset() expect($('style[priority=1]')).toHaveLength 2 # atom-dark-ui has an directory path, the syntax one doesn't atom.config.set('core.themes', ['theme-with-index-less', 'atom-dark-ui']) waitsFor -> - reloadHandler.callCount == 1 + didChangeActiveThemesHandler.callCount == 1 runs -> expect($('style[priority=1]')).toHaveLength 2 @@ -130,7 +130,7 @@ describe "ThemeManager", -> it 'adds theme-* classes to the workspace for each active theme', -> workspaceElement = atom.views.getView(atom.workspace) - themeManager.onDidReloadAll reloadHandler = jasmine.createSpy() + themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() waitsForPromise -> themeManager.activateThemes() @@ -138,11 +138,11 @@ describe "ThemeManager", -> runs -> expect(workspaceElement).toHaveClass 'theme-atom-dark-ui' - themeManager.onDidReloadAll reloadHandler = jasmine.createSpy() + themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() atom.config.set('core.themes', ['theme-with-ui-variables', 'theme-with-syntax-variables']) waitsFor -> - reloadHandler.callCount > 0 + didChangeActiveThemesHandler.callCount > 0 runs -> # `theme-` twice as it prefixes the name with `theme-` @@ -259,11 +259,11 @@ describe "ThemeManager", -> themeManager.activateThemes() it "loads the correct values from the theme's ui-variables file", -> - themeManager.onDidReloadAll reloadHandler = jasmine.createSpy() + themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() atom.config.set('core.themes', ['theme-with-ui-variables', 'theme-with-syntax-variables']) waitsFor -> - reloadHandler.callCount > 0 + didChangeActiveThemesHandler.callCount > 0 runs -> # an override loaded in the base css @@ -276,11 +276,11 @@ describe "ThemeManager", -> describe "when there is a theme with incomplete variables", -> it "loads the correct values from the fallback ui-variables", -> - themeManager.onDidReloadAll reloadHandler = jasmine.createSpy() + themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() atom.config.set('core.themes', ['theme-with-incomplete-ui-variables', 'theme-with-syntax-variables']) waitsFor -> - reloadHandler.callCount > 0 + didChangeActiveThemesHandler.callCount > 0 runs -> # an override loaded in the base css diff --git a/src/atom.coffee b/src/atom.coffee index 891ae9273..8d5053254 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -721,7 +721,7 @@ class Atom extends Model @themes.load() watchThemes: -> - @themes.onDidReloadAll => + @themes.onDidChangeActiveThemes => # Only reload stylesheets from non-theme packages for pack in @packages.getActivePackages() when pack.getType() isnt 'theme' pack.reloadStylesheets?() diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index e009c16e4..9edbfc99b 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -185,7 +185,7 @@ TextEditorComponent = React.createClass @subscribe stylesElement.onDidUpdateStyleElement @onStylesheetsChanged @subscribe stylesElement.onDidRemoveStyleElement @onStylesheetsChanged unless atom.themes.isInitialLoadComplete() - @subscribe atom.themes.onDidReloadAll @onAllThemesLoaded + @subscribe atom.themes.onDidChangeActiveThemes @onAllThemesLoaded @subscribe scrollbarStyle.changes, @refreshScrollbars @domPollingIntervalId = setInterval(@pollDOM, @domPollingInterval) diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 99fb7ccd2..e9c21a6d2 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -61,8 +61,12 @@ class ThemeManager # updating the list of active themes have completed. # # * `callback` {Function} + onDidChangeActiveThemes: (callback) -> + @emitter.on 'did-change-active-themes', callback + onDidReloadAll: (callback) -> - @emitter.on 'did-reload-all', callback + Grim.deprecate("Use `::onDidChangeActiveThemes` instead.") + @onDidChangeActiveThemes(callback) # Deprecated: Invoke `callback` when a stylesheet has been added to the dom. # @@ -132,9 +136,13 @@ class ThemeManager ### # Public: Get an array of all the loaded theme names. - getLoadedNames: -> + getLoadedThemeNames: -> theme.name for theme in @getLoadedThemes() + getLoadedNames: -> + Grim.deprecate("Use `::getLoadedThemeNames` instead.") + @getLoadedThemeNames() + # Public: Get an array of all the loaded themes. getLoadedThemes: -> pack for pack in @packageManager.getLoadedPackages() when pack.isTheme() @@ -144,9 +152,13 @@ class ThemeManager ### # Public: Get an array of all the active theme names. - getActiveNames: -> + getActiveThemeNames: -> theme.name for theme in @getActiveThemes() + getActiveNames: -> + Grim.deprecate("Use `::getActiveThemeNames` instead.") + @getActiveThemeNames() + # Public: Get an array of all the active themes. getActiveThemes: -> pack for pack in @packageManager.getActivePackages() when pack.isTheme() @@ -323,7 +335,7 @@ class ThemeManager @reloadBaseStylesheets() @initialLoadComplete = true @emit 'reloaded' - @emitter.emit 'did-reload-all' + @emitter.emit 'did-change-active-themes' deferred.resolve() deferred.promise