From 540cfbd4e77544b5f165c82a4b8a674bfd40bec9 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 15 Mar 2017 12:28:43 +0100 Subject: [PATCH] use correct theme --- src/vs/workbench/browser/part.ts | 8 +++--- src/vs/workbench/common/component.ts | 26 +++++++++++-------- src/vs/workbench/test/browser/part.test.ts | 16 +----------- .../workbench/test/workbenchTestServices.ts | 19 +++++++++++++- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/vs/workbench/browser/part.ts b/src/vs/workbench/browser/part.ts index fed8241b26b..e9aca1b54c6 100644 --- a/src/vs/workbench/browser/part.ts +++ b/src/vs/workbench/browser/part.ts @@ -8,7 +8,7 @@ import 'vs/css!./media/part'; import { Dimension, Builder } from 'vs/base/browser/builder'; import { WorkbenchComponent } from 'vs/workbench/common/component'; -import { IThemeService } from 'vs/platform/theme/common/themeService'; +import { IThemeService, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; export interface IPartOptions { hasTitle?: boolean; @@ -32,9 +32,11 @@ export abstract class Part extends WorkbenchComponent { super(id, themeService); } - protected onThemeChange(): void { + protected onThemeChange(theme: ITheme, collector: ICssStyleCollector): void { + + // only call if our create() method has been called if (this.parent) { - this.updateStyles(); // only call if our create() method has been called + super.onThemeChange(theme, collector); } } diff --git a/src/vs/workbench/common/component.ts b/src/vs/workbench/common/component.ts index 22378acdf92..dadfb8d644e 100644 --- a/src/vs/workbench/common/component.ts +++ b/src/vs/workbench/common/component.ts @@ -7,7 +7,7 @@ import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle'; import { Scope, Memento } from 'vs/workbench/common/memento'; import { IStorageService } from 'vs/platform/storage/common/storage'; -import { IThemeService } from 'vs/platform/theme/common/themeService'; +import { IThemeService, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; /** * Base class of any core/ui component in the workbench. Examples include services, extensions, parts, viewlets and quick open. @@ -39,6 +39,7 @@ export class WorkbenchComponent extends Disposable implements IWorkbenchComponen private _toUnbind: IDisposable[]; private id: string; private componentMemento: Memento; + private theme: ITheme; constructor( id: string, @@ -49,21 +50,24 @@ export class WorkbenchComponent extends Disposable implements IWorkbenchComponen this._toUnbind = []; this.id = id; this.componentMemento = new Memento(this.id); + this.theme = themeService.getTheme(); // Hook up to theme changes - this.toUnbind.push(this.themeService.onThemeChange(() => this.onThemeChange())); + this.toUnbind.push(this.themeService.onThemeChange((theme, collector) => this.onThemeChange(theme, collector))); + } + + protected onThemeChange(theme: ITheme, collector: ICssStyleCollector): void { + this.theme = theme; + + this.updateStyles(collector); + } + + protected updateStyles(collector: ICssStyleCollector): void { + // Subclasses to override } protected getColor(id: string): string { - return this.themeService.getTheme().getColor(id).toString(); - } - - protected onThemeChange(): void { - this.updateStyles(); - } - - protected updateStyles(): void { - // Subclasses to override + return this.theme.getColor(id).toString(); } protected get toUnbind() { diff --git a/src/vs/workbench/test/browser/part.test.ts b/src/vs/workbench/test/browser/part.test.ts index 13a7e5085d8..a8a31790634 100644 --- a/src/vs/workbench/test/browser/part.test.ts +++ b/src/vs/workbench/test/browser/part.test.ts @@ -13,21 +13,7 @@ import { IWorkspaceContextService, WorkspaceContextService } from 'vs/platform/w import { IStorageService } from 'vs/platform/storage/common/storage'; import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService'; import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; -import { IThemeService, ITheme, IThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { IDisposable } from 'vs/base/common/lifecycle'; - -class TestThemeService implements IThemeService { - - _serviceBrand: any; - - getTheme(): ITheme { - throw new Error('Method not implemented.'); - } - - onThemeChange(participant: IThemingParticipant): IDisposable { - return { dispose: () => { } }; - } -} +import { TestThemeService } from 'vs/workbench/test/workbenchTestServices'; class MyPart extends Part { diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 874a42daa1d..3238028c958 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -52,6 +52,7 @@ import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IThemeService, ITheme, IThemingParticipant } from 'vs/platform/theme/common/themeService'; import { IDisposable } from 'vs/base/common/lifecycle'; +import { Color } from "vs/base/common/color"; export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput { return instantiationService.createInstance(FileEditorInput, resource, void 0); @@ -973,12 +974,28 @@ export class TestWindowsService implements IWindowsService { } } +export class TestTheme implements ITheme { + selector: string; + label: string; + type: 'light' | 'dark' | 'hc'; + + getColor(color: string, useDefault?: boolean): Color { + throw new Error('Method not implemented.'); + } + + isDefault(color: string): boolean { + throw new Error('Method not implemented.'); + } +} + +const testTheme = new TestTheme(); + export class TestThemeService implements IThemeService { _serviceBrand: any; getTheme(): ITheme { - throw new Error('Method not implemented.'); + return testTheme; } onThemeChange(participant: IThemingParticipant): IDisposable {