From 6c2f83dfcdfc82e99fa9fee2abc595c896c227e6 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Wed, 10 May 2017 13:01:05 +0200 Subject: [PATCH] [theme] add theme to the view context --- src/vs/editor/browser/codeEditor.ts | 6 ++++-- .../editor/browser/standalone/standaloneCodeEditor.ts | 7 ++++--- src/vs/editor/browser/view/viewImpl.ts | 8 +++++++- src/vs/editor/browser/widget/codeEditorWidget.ts | 7 ++++++- .../editor/browser/widget/embeddedCodeEditorWidget.ts | 6 ++++-- src/vs/editor/common/view/viewContext.ts | 4 ++++ src/vs/editor/common/view/viewEvents.ts | 10 ++++++++++ src/vs/editor/common/viewModel/viewEventHandler.ts | 10 ++++++++++ .../parts/debug/electron-browser/replEditor.ts | 6 ++++-- .../walkThrough/electron-browser/walkThroughPart.ts | 6 ++++-- 10 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/vs/editor/browser/codeEditor.ts b/src/vs/editor/browser/codeEditor.ts index 721d90d9bdd..77271726ba2 100644 --- a/src/vs/editor/browser/codeEditor.ts +++ b/src/vs/editor/browser/codeEditor.ts @@ -13,6 +13,7 @@ import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { EditorAction, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export class CodeEditor extends CodeEditorWidget { @@ -22,9 +23,10 @@ export class CodeEditor extends CodeEditorWidget { @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, @ICommandService commandService: ICommandService, - @IContextKeyService contextKeyService: IContextKeyService + @IContextKeyService contextKeyService: IContextKeyService, + @IThemeService themeService: IThemeService ) { - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService); + super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService); } protected _getContributions(): IEditorContributionCtor[] { diff --git a/src/vs/editor/browser/standalone/standaloneCodeEditor.ts b/src/vs/editor/browser/standalone/standaloneCodeEditor.ts index 3cc70066d90..7644c520feb 100644 --- a/src/vs/editor/browser/standalone/standaloneCodeEditor.ts +++ b/src/vs/editor/browser/standalone/standaloneCodeEditor.ts @@ -83,9 +83,10 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE @ICodeEditorService codeEditorService: ICodeEditorService, @ICommandService commandService: ICommandService, @IContextKeyService contextKeyService: IContextKeyService, - @IKeybindingService keybindingService: IKeybindingService + @IKeybindingService keybindingService: IKeybindingService, + @IThemeService themeService: IThemeService ) { - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService); + super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService); if (keybindingService instanceof StandaloneKeybindingService) { this._standaloneKeybindingService = keybindingService; @@ -213,7 +214,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon } let model: IModel = options.model; delete options.model; - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService); + super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, standaloneThemeService); this._contextViewService = contextViewService; this._standaloneThemeService = standaloneThemeService; diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 49a8d522741..c1cfa7f9037 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -48,6 +48,7 @@ import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData' import { EditorScrollbar } from 'vs/editor/browser/viewParts/editorScrollbar/editorScrollbar'; import { Minimap } from 'vs/editor/browser/viewParts/minimap/minimap'; import * as viewEvents from 'vs/editor/common/view/viewEvents'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export interface IContentWidgetData { widget: editorBrowser.IContentWidget; @@ -94,6 +95,7 @@ export class View extends ViewEventHandler { constructor( commandService: ICommandService, configuration: Configuration, + themeService: IThemeService, model: IViewModel, execCoreEditorCommandFunc: ExecCoreEditorCommandFunc ) { @@ -111,7 +113,11 @@ export class View extends ViewEventHandler { this.eventDispatcher.addEventHandler(this); // The view context is passed on to most classes (basically to reduce param. counts in ctors) - this._context = new ViewContext(configuration, model, this.eventDispatcher); + this._context = new ViewContext(configuration, themeService.getTheme(), model, this.eventDispatcher); + + this._register(themeService.onThemeChange(theme => { + this.eventDispatcher.emit(new viewEvents.ViewThemeChangedEvent()); + })); this.viewParts = []; diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 19579878aa2..ff008292f72 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -32,6 +32,7 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IPosition } from 'vs/editor/common/core/position'; import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer'; import { CoreEditorCommand } from 'vs/editor/common/controller/coreCommands'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export abstract class CodeEditorWidget extends CommonCodeEditor implements editorBrowser.ICodeEditor { @@ -70,6 +71,7 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito private _codeEditorService: ICodeEditorService; private _commandService: ICommandService; + private _themeService: IThemeService; protected domElement: HTMLElement; private _focusTracker: CodeEditorWidgetFocusTracker; @@ -87,11 +89,13 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, @ICommandService commandService: ICommandService, - @IContextKeyService contextKeyService: IContextKeyService + @IContextKeyService contextKeyService: IContextKeyService, + @IThemeService themeService: IThemeService ) { super(domElement, options, instantiationService, contextKeyService); this._codeEditorService = codeEditorService; this._commandService = commandService; + this._themeService = themeService; this._focusTracker = new CodeEditorWidgetFocusTracker(domElement); this._focusTracker.onChage(() => { @@ -426,6 +430,7 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito this._view = new View( this._commandService, this._configuration, + this._themeService, this.viewModel, (editorCommand: CoreEditorCommand, args: any) => { if (!this.cursor) { diff --git a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts index 0956a3e7d81..185f3537c51 100644 --- a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts +++ b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts @@ -12,6 +12,7 @@ import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService' import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { CodeEditor } from 'vs/editor/browser/codeEditor'; import { IConfigurationChangedEvent, IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export class EmbeddedCodeEditorWidget extends CodeEditor { @@ -25,9 +26,10 @@ export class EmbeddedCodeEditorWidget extends CodeEditor { @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, @ICommandService commandService: ICommandService, - @IContextKeyService contextKeyService: IContextKeyService + @IContextKeyService contextKeyService: IContextKeyService, + @IThemeService themeService: IThemeService ) { - super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService); + super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService, themeService); this._parentEditor = parentEditor; this._overwriteOptions = options; diff --git a/src/vs/editor/common/view/viewContext.ts b/src/vs/editor/common/view/viewContext.ts index ebb5cc199a3..91b722b0afb 100644 --- a/src/vs/editor/common/view/viewContext.ts +++ b/src/vs/editor/common/view/viewContext.ts @@ -8,20 +8,24 @@ import { IConfiguration } from 'vs/editor/common/editorCommon'; import { IViewModel, IViewLayout } from 'vs/editor/common/viewModel/viewModel'; import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler'; import { ViewEventDispatcher } from 'vs/editor/common/view/viewEventDispatcher'; +import { ITheme } from 'vs/platform/theme/common/themeService'; export class ViewContext { public readonly configuration: IConfiguration; + public readonly theme: ITheme; public readonly model: IViewModel; public readonly viewLayout: IViewLayout; public readonly privateViewEventBus: ViewEventDispatcher; constructor( configuration: IConfiguration, + theme: ITheme, model: IViewModel, privateViewEventBus: ViewEventDispatcher ) { this.configuration = configuration; + this.theme = theme; this.model = model; this.viewLayout = model.viewLayout; this.privateViewEventBus = privateViewEventBus; diff --git a/src/vs/editor/common/view/viewEvents.ts b/src/vs/editor/common/view/viewEvents.ts index 7decc3f5231..a0788dda030 100644 --- a/src/vs/editor/common/view/viewEvents.ts +++ b/src/vs/editor/common/view/viewEvents.ts @@ -27,6 +27,7 @@ export const enum ViewEventType { ViewTokensChanged = 13, ViewTokensColorsChanged = 14, ViewZonesChanged = 15, + ViewThemeChanged = 16 } export class ViewConfigurationChangedEvent { @@ -262,6 +263,14 @@ export class ViewTokensChangedEvent { } } +export class ViewThemeChangedEvent { + + public readonly type = ViewEventType.ViewThemeChanged; + + constructor() { + } +} + export class ViewTokensColorsChangedEvent { public readonly type = ViewEventType.ViewTokensColorsChanged; @@ -296,4 +305,5 @@ export type ViewEvent = ( | ViewTokensChangedEvent | ViewTokensColorsChangedEvent | ViewZonesChangedEvent + | ViewThemeChangedEvent ); diff --git a/src/vs/editor/common/viewModel/viewEventHandler.ts b/src/vs/editor/common/viewModel/viewEventHandler.ts index 3ef6a84a4e4..6696cf63894 100644 --- a/src/vs/editor/common/viewModel/viewEventHandler.ts +++ b/src/vs/editor/common/viewModel/viewEventHandler.ts @@ -79,6 +79,9 @@ export class ViewEventHandler extends Disposable { public onZonesChanged(e: viewEvents.ViewZonesChangedEvent): boolean { return false; } + public onThemeChanged(e: viewEvents.ViewThemeChangedEvent): boolean { + return false; + } // --- end event handlers @@ -181,6 +184,13 @@ export class ViewEventHandler extends Disposable { } break; + + case viewEvents.ViewEventType.ViewThemeChanged: + if (this.onThemeChanged(e)) { + shouldRender = true; + } + break; + default: console.info('View received unknown event: '); console.info(e); diff --git a/src/vs/workbench/parts/debug/electron-browser/replEditor.ts b/src/vs/workbench/parts/debug/electron-browser/replEditor.ts index 3e607802ab3..d1e61773616 100644 --- a/src/vs/workbench/parts/debug/electron-browser/replEditor.ts +++ b/src/vs/workbench/parts/debug/electron-browser/replEditor.ts @@ -19,6 +19,7 @@ import { ContextMenuController } from 'vs/editor/contrib/contextmenu/browser/con import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController'; import { SnippetController } from 'vs/editor/contrib/snippet/common/snippetController'; import { TabCompletionController } from 'vs/workbench/parts/snippets/electron-browser/tabCompletion'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export class ReplInputEditor extends CodeEditorWidget { constructor( @@ -27,9 +28,10 @@ export class ReplInputEditor extends CodeEditorWidget { @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, @ICommandService commandService: ICommandService, - @IContextKeyService contextKeyService: IContextKeyService + @IContextKeyService contextKeyService: IContextKeyService, + @IThemeService themeService: IThemeService ) { - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService); + super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService); } protected _getContributions(): IEditorContributionCtor[] { diff --git a/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts b/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts index 640439add9a..ae8cd2085ed 100644 --- a/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts +++ b/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts @@ -38,6 +38,7 @@ import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService' import { Parts, IPartService } from 'vs/workbench/services/part/common/partService'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IMessageService, Severity } from 'vs/platform/message/common/message'; +import { IThemeService } from 'vs/platform/theme/common/themeService'; export const WALK_THROUGH_FOCUS = new RawContextKey('interactivePlaygroundFocus', false); @@ -68,9 +69,10 @@ class WalkThroughCodeEditor extends CodeEditor { @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, @ICommandService commandService: ICommandService, - @IContextKeyService contextKeyService: IContextKeyService + @IContextKeyService contextKeyService: IContextKeyService, + @IThemeService themeService: IThemeService ) { - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService); + super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService); } getTelemetryData() {