[theme] add theme to the view context

This commit is contained in:
Martin Aeschlimann
2017-05-10 13:01:05 +02:00
parent 2cf6548165
commit 6c2f83dfcd
10 changed files with 57 additions and 13 deletions
+4 -2
View File
@@ -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[] {
@@ -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 = <IEditorContextViewService>contextViewService;
this._standaloneThemeService = standaloneThemeService;
+7 -1
View File
@@ -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 = [];
@@ -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) {
@@ -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;
+4
View File
@@ -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;
+10
View File
@@ -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
);
@@ -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);
@@ -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[] {
@@ -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<boolean>('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() {