Skip to content

Commit 6c2f83d

Browse files
committed
[theme] add theme to the view context
1 parent 2cf6548 commit 6c2f83d

10 files changed

Lines changed: 57 additions & 13 deletions

File tree

src/vs/editor/browser/codeEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
1313
import { EditorAction, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
1414
import { EditorBrowserRegistry } from 'vs/editor/browser/editorBrowserExtensions';
1515
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
16+
import { IThemeService } from 'vs/platform/theme/common/themeService';
1617

1718
export class CodeEditor extends CodeEditorWidget {
1819

@@ -22,9 +23,10 @@ export class CodeEditor extends CodeEditorWidget {
2223
@IInstantiationService instantiationService: IInstantiationService,
2324
@ICodeEditorService codeEditorService: ICodeEditorService,
2425
@ICommandService commandService: ICommandService,
25-
@IContextKeyService contextKeyService: IContextKeyService
26+
@IContextKeyService contextKeyService: IContextKeyService,
27+
@IThemeService themeService: IThemeService
2628
) {
27-
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService);
29+
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
2830
}
2931

3032
protected _getContributions(): IEditorContributionCtor[] {

src/vs/editor/browser/standalone/standaloneCodeEditor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
8383
@ICodeEditorService codeEditorService: ICodeEditorService,
8484
@ICommandService commandService: ICommandService,
8585
@IContextKeyService contextKeyService: IContextKeyService,
86-
@IKeybindingService keybindingService: IKeybindingService
86+
@IKeybindingService keybindingService: IKeybindingService,
87+
@IThemeService themeService: IThemeService
8788
) {
88-
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService);
89+
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
8990

9091
if (keybindingService instanceof StandaloneKeybindingService) {
9192
this._standaloneKeybindingService = keybindingService;
@@ -213,7 +214,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
213214
}
214215
let model: IModel = options.model;
215216
delete options.model;
216-
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService);
217+
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, standaloneThemeService);
217218

218219
this._contextViewService = <IEditorContextViewService>contextViewService;
219220
this._standaloneThemeService = standaloneThemeService;

src/vs/editor/browser/view/viewImpl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData'
4848
import { EditorScrollbar } from 'vs/editor/browser/viewParts/editorScrollbar/editorScrollbar';
4949
import { Minimap } from 'vs/editor/browser/viewParts/minimap/minimap';
5050
import * as viewEvents from 'vs/editor/common/view/viewEvents';
51+
import { IThemeService } from 'vs/platform/theme/common/themeService';
5152

5253
export interface IContentWidgetData {
5354
widget: editorBrowser.IContentWidget;
@@ -94,6 +95,7 @@ export class View extends ViewEventHandler {
9495
constructor(
9596
commandService: ICommandService,
9697
configuration: Configuration,
98+
themeService: IThemeService,
9799
model: IViewModel,
98100
execCoreEditorCommandFunc: ExecCoreEditorCommandFunc
99101
) {
@@ -111,7 +113,11 @@ export class View extends ViewEventHandler {
111113
this.eventDispatcher.addEventHandler(this);
112114

113115
// The view context is passed on to most classes (basically to reduce param. counts in ctors)
114-
this._context = new ViewContext(configuration, model, this.eventDispatcher);
116+
this._context = new ViewContext(configuration, themeService.getTheme(), model, this.eventDispatcher);
117+
118+
this._register(themeService.onThemeChange(theme => {
119+
this.eventDispatcher.emit(new viewEvents.ViewThemeChangedEvent());
120+
}));
115121

116122
this.viewParts = [];
117123

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
3232
import { IPosition } from 'vs/editor/common/core/position';
3333
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
3434
import { CoreEditorCommand } from 'vs/editor/common/controller/coreCommands';
35+
import { IThemeService } from 'vs/platform/theme/common/themeService';
3536

3637
export abstract class CodeEditorWidget extends CommonCodeEditor implements editorBrowser.ICodeEditor {
3738

@@ -70,6 +71,7 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
7071

7172
private _codeEditorService: ICodeEditorService;
7273
private _commandService: ICommandService;
74+
private _themeService: IThemeService;
7375

7476
protected domElement: HTMLElement;
7577
private _focusTracker: CodeEditorWidgetFocusTracker;
@@ -87,11 +89,13 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
8789
@IInstantiationService instantiationService: IInstantiationService,
8890
@ICodeEditorService codeEditorService: ICodeEditorService,
8991
@ICommandService commandService: ICommandService,
90-
@IContextKeyService contextKeyService: IContextKeyService
92+
@IContextKeyService contextKeyService: IContextKeyService,
93+
@IThemeService themeService: IThemeService
9194
) {
9295
super(domElement, options, instantiationService, contextKeyService);
9396
this._codeEditorService = codeEditorService;
9497
this._commandService = commandService;
98+
this._themeService = themeService;
9599

96100
this._focusTracker = new CodeEditorWidgetFocusTracker(domElement);
97101
this._focusTracker.onChage(() => {
@@ -426,6 +430,7 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
426430
this._view = new View(
427431
this._commandService,
428432
this._configuration,
433+
this._themeService,
429434
this.viewModel,
430435
(editorCommand: CoreEditorCommand, args: any) => {
431436
if (!this.cursor) {

src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService'
1212
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1313
import { CodeEditor } from 'vs/editor/browser/codeEditor';
1414
import { IConfigurationChangedEvent, IEditorOptions } from 'vs/editor/common/config/editorOptions';
15+
import { IThemeService } from 'vs/platform/theme/common/themeService';
1516

1617
export class EmbeddedCodeEditorWidget extends CodeEditor {
1718

@@ -25,9 +26,10 @@ export class EmbeddedCodeEditorWidget extends CodeEditor {
2526
@IInstantiationService instantiationService: IInstantiationService,
2627
@ICodeEditorService codeEditorService: ICodeEditorService,
2728
@ICommandService commandService: ICommandService,
28-
@IContextKeyService contextKeyService: IContextKeyService
29+
@IContextKeyService contextKeyService: IContextKeyService,
30+
@IThemeService themeService: IThemeService
2931
) {
30-
super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService);
32+
super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService, themeService);
3133

3234
this._parentEditor = parentEditor;
3335
this._overwriteOptions = options;

src/vs/editor/common/view/viewContext.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ import { IConfiguration } from 'vs/editor/common/editorCommon';
88
import { IViewModel, IViewLayout } from 'vs/editor/common/viewModel/viewModel';
99
import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler';
1010
import { ViewEventDispatcher } from 'vs/editor/common/view/viewEventDispatcher';
11+
import { ITheme } from 'vs/platform/theme/common/themeService';
1112

1213
export class ViewContext {
1314

1415
public readonly configuration: IConfiguration;
16+
public readonly theme: ITheme;
1517
public readonly model: IViewModel;
1618
public readonly viewLayout: IViewLayout;
1719
public readonly privateViewEventBus: ViewEventDispatcher;
1820

1921
constructor(
2022
configuration: IConfiguration,
23+
theme: ITheme,
2124
model: IViewModel,
2225
privateViewEventBus: ViewEventDispatcher
2326
) {
2427
this.configuration = configuration;
28+
this.theme = theme;
2529
this.model = model;
2630
this.viewLayout = model.viewLayout;
2731
this.privateViewEventBus = privateViewEventBus;

src/vs/editor/common/view/viewEvents.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const enum ViewEventType {
2727
ViewTokensChanged = 13,
2828
ViewTokensColorsChanged = 14,
2929
ViewZonesChanged = 15,
30+
ViewThemeChanged = 16
3031
}
3132

3233
export class ViewConfigurationChangedEvent {
@@ -262,6 +263,14 @@ export class ViewTokensChangedEvent {
262263
}
263264
}
264265

266+
export class ViewThemeChangedEvent {
267+
268+
public readonly type = ViewEventType.ViewThemeChanged;
269+
270+
constructor() {
271+
}
272+
}
273+
265274
export class ViewTokensColorsChangedEvent {
266275

267276
public readonly type = ViewEventType.ViewTokensColorsChanged;
@@ -296,4 +305,5 @@ export type ViewEvent = (
296305
| ViewTokensChangedEvent
297306
| ViewTokensColorsChangedEvent
298307
| ViewZonesChangedEvent
308+
| ViewThemeChangedEvent
299309
);

src/vs/editor/common/viewModel/viewEventHandler.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export class ViewEventHandler extends Disposable {
7979
public onZonesChanged(e: viewEvents.ViewZonesChangedEvent): boolean {
8080
return false;
8181
}
82+
public onThemeChanged(e: viewEvents.ViewThemeChangedEvent): boolean {
83+
return false;
84+
}
8285

8386
// --- end event handlers
8487

@@ -181,6 +184,13 @@ export class ViewEventHandler extends Disposable {
181184
}
182185
break;
183186

187+
188+
case viewEvents.ViewEventType.ViewThemeChanged:
189+
if (this.onThemeChanged(e)) {
190+
shouldRender = true;
191+
}
192+
break;
193+
184194
default:
185195
console.info('View received unknown event: ');
186196
console.info(e);

src/vs/workbench/parts/debug/electron-browser/replEditor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ContextMenuController } from 'vs/editor/contrib/contextmenu/browser/con
1919
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
2020
import { SnippetController } from 'vs/editor/contrib/snippet/common/snippetController';
2121
import { TabCompletionController } from 'vs/workbench/parts/snippets/electron-browser/tabCompletion';
22+
import { IThemeService } from 'vs/platform/theme/common/themeService';
2223

2324
export class ReplInputEditor extends CodeEditorWidget {
2425
constructor(
@@ -27,9 +28,10 @@ export class ReplInputEditor extends CodeEditorWidget {
2728
@IInstantiationService instantiationService: IInstantiationService,
2829
@ICodeEditorService codeEditorService: ICodeEditorService,
2930
@ICommandService commandService: ICommandService,
30-
@IContextKeyService contextKeyService: IContextKeyService
31+
@IContextKeyService contextKeyService: IContextKeyService,
32+
@IThemeService themeService: IThemeService
3133
) {
32-
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService);
34+
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
3335
}
3436

3537
protected _getContributions(): IEditorContributionCtor[] {

src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService'
3838
import { Parts, IPartService } from 'vs/workbench/services/part/common/partService';
3939
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
4040
import { IMessageService, Severity } from 'vs/platform/message/common/message';
41+
import { IThemeService } from 'vs/platform/theme/common/themeService';
4142

4243
export const WALK_THROUGH_FOCUS = new RawContextKey<boolean>('interactivePlaygroundFocus', false);
4344

@@ -68,9 +69,10 @@ class WalkThroughCodeEditor extends CodeEditor {
6869
@IInstantiationService instantiationService: IInstantiationService,
6970
@ICodeEditorService codeEditorService: ICodeEditorService,
7071
@ICommandService commandService: ICommandService,
71-
@IContextKeyService contextKeyService: IContextKeyService
72+
@IContextKeyService contextKeyService: IContextKeyService,
73+
@IThemeService themeService: IThemeService
7274
) {
73-
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService);
75+
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService);
7476
}
7577

7678
getTelemetryData() {

0 commit comments

Comments
 (0)