Skip to content

Commit 51ff418

Browse files
committed
clean up ThemeService API
1 parent ef6b3de commit 51ff418

13 files changed

Lines changed: 219 additions & 181 deletions

File tree

src/vs/editor/contrib/inspectTMScopes/electron-browser/inspectTMScopes.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,13 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
241241
result += `<tr><td class="tm-metadata-key">background</td><td class="tm-metadata-value">${metadata.background}</td>`;
242242
result += `</tbody></table>`;
243243

244-
let theme = this._themeService.getColorThemeDocument();
245-
if (theme) {
246-
result += `<hr/>`;
247-
let matchingRule = findMatchingThemeRule(theme, data.tokens1[token1Index].scopes);
248-
if (matchingRule) {
249-
result += `<code class="tm-theme-selector">${matchingRule.rawSelector}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
250-
} else {
251-
result += `<span class="tm-theme-selector">No theme selector.</span>`;
252-
}
244+
let theme = this._themeService.getColorTheme();
245+
result += `<hr/>`;
246+
let matchingRule = findMatchingThemeRule(theme, data.tokens1[token1Index].scopes);
247+
if (matchingRule) {
248+
result += `<code class="tm-theme-selector">${matchingRule.rawSelector}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
249+
} else {
250+
result += `<span class="tm-theme-selector">No theme selector.</span>`;
253251
}
254252

255253
result += `<hr/>`;

src/vs/editor/electron-browser/textMate/TMHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
'use strict';
77

8-
import { IThemeDocument, IThemeSettingStyle } from 'vs/workbench/services/themes/common/themeService';
8+
import { IColorTheme, IThemeSettingStyle } from 'vs/workbench/services/themes/common/themeService';
99

10-
export function findMatchingThemeRule(theme: IThemeDocument, scopes: string[]): ThemeRule {
10+
export function findMatchingThemeRule(theme: IColorTheme, scopes: string[]): ThemeRule {
1111
for (let i = scopes.length - 1; i >= 0; i--) {
1212
let parentScopes = scopes.slice(0, i);
1313
let scope = scopes[i];
@@ -19,7 +19,7 @@ export function findMatchingThemeRule(theme: IThemeDocument, scopes: string[]):
1919
return null;
2020
}
2121

22-
function findMatchingThemeRule2(theme: IThemeDocument, scope: string, parentScopes: string[]): ThemeRule {
22+
function findMatchingThemeRule2(theme: IColorTheme, scope: string, parentScopes: string[]): ThemeRule {
2323
let result: ThemeRule = null;
2424

2525
// Loop backwards, to ensure the last most specific rule wins

src/vs/editor/electron-browser/textMate/TMSyntax.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ export class MainProcessTextMateSyntax implements ITextMateService {
162162
}
163163

164164
private _updateTheme(): void {
165-
this._grammarRegistry.setTheme(this._themeService.getColorThemeDocument());
165+
let colorTheme = this._themeService.getColorTheme();
166+
this._grammarRegistry.setTheme({ name: colorTheme.label, settings: colorTheme.settings });
166167
let colorMap = this._grammarRegistry.getColorMap();
167168
let cssRules = MainProcessTextMateSyntax._generateCSS(colorMap);
168169
this._styleElement.innerHTML = cssRules;

src/vs/workbench/browser/parts/editor/textEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export abstract class BaseTextEditor extends BaseEditor {
112112
objects.assign(overrides, {
113113
overviewRulerLanes: 3,
114114
lineNumbersMinChars: 3,
115-
theme: this.themeService.getColorTheme(),
115+
theme: this.themeService.getColorTheme().id,
116116
fixedOverflowWidgets: true
117117
});
118118
return overrides;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class Repl extends Panel implements IPrivateReplService {
271271
},
272272
lineDecorationsWidth: 0,
273273
scrollBeyondLastLine: false,
274-
theme: this.themeService.getColorTheme(),
274+
theme: this.themeService.getColorTheme().id,
275275
renderLineHighlight: 'none',
276276
fixedOverflowWidgets: true,
277277
acceptSuggestionOnEnter: false

src/vs/workbench/parts/extensions/browser/extensionEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class ExtensionEditor extends BaseEditor {
325325
webview.contents = [body];
326326

327327
webview.onDidClickLink(link => this.openerService.open(link), null, this.contentDisposables);
328-
this.themeService.onDidColorThemeChange(themeId => webview.style(themeId), null, this.contentDisposables);
328+
this.themeService.onDidColorThemeChange(theme => webview.style(theme), null, this.contentDisposables);
329329
this.contentDisposables.push(webview);
330330
})
331331
.then(null, () => {

src/vs/workbench/parts/html/browser/webview.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { addDisposableListener, addClass } from 'vs/base/browser/dom';
1414
import { isLightTheme, isDarkTheme } from 'vs/platform/theme/common/themes';
1515
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1616
import { MenuRegistry } from 'vs/platform/actions/common/actions';
17+
import { IColorTheme } from 'vs/workbench/services/themes/common/themeService';
1718

1819
declare interface WebviewElement extends HTMLElement {
1920
src: string;
@@ -157,7 +158,8 @@ export default class Webview {
157158
this._send('focus');
158159
}
159160

160-
style(themeId: string): void {
161+
style(theme: IColorTheme): void {
162+
let themeId = theme.id;
161163
const {color, backgroundColor, fontFamily, fontWeight, fontSize} = window.getComputedStyle(this._styleElement);
162164

163165
let value = `

src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1515
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1616
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1717
import { ITerminalService, ITerminalFont, TERMINAL_PANEL_ID } from 'vs/workbench/parts/terminal/common/terminal';
18-
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
18+
import { IThemeService, IColorTheme } from 'vs/workbench/services/themes/common/themeService';
1919
import { KillTerminalAction, CreateNewTerminalAction, SwitchTerminalInstanceAction, SwitchTerminalInstanceActionItem, CopyTerminalSelectionAction, TerminalPasteAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
2020
import { Panel } from 'vs/workbench/browser/panel';
2121
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
@@ -62,7 +62,7 @@ export class TerminalPanel extends Panel {
6262

6363
this._terminalService.setContainers(this.getContainer().getHTMLElement(), this._terminalContainer);
6464

65-
this._register(this._themeService.onDidColorThemeChange(themeId => this._updateTheme(themeId)));
65+
this._register(this._themeService.onDidColorThemeChange(theme => this._updateTheme(theme)));
6666
this._register(this._configurationService.onDidUpdateConfiguration(() => this._updateFont()));
6767
this._updateFont();
6868
this._updateTheme();
@@ -192,11 +192,8 @@ export class TerminalPanel extends Panel {
192192
}));
193193
}
194194

195-
private _updateTheme(themeId?: string): void {
196-
if (!themeId) {
197-
themeId = this._themeService.getColorTheme();
198-
}
199-
195+
private _updateTheme(colorTheme?: IColorTheme): void {
196+
let themeId = colorTheme.id;
200197
let baseThemeId = getBaseThemeId(themeId);
201198
if (baseThemeId === this._currentBaseThemeId) {
202199
return;

src/vs/workbench/parts/themes/electron-browser/themes.contribution.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ export class SelectColorThemeAction extends Action {
4040

4141
run(): TPromise<void> {
4242
return this.themeService.getColorThemes().then(themes => {
43-
const currentThemeId = this.themeService.getColorTheme();
44-
const currentTheme = themes.filter(theme => theme.id === currentThemeId)[0];
43+
const currentTheme = this.themeService.getColorTheme();
4544

4645
const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'category:themes');
4746

@@ -58,7 +57,7 @@ export class SelectColorThemeAction extends Action {
5857
};
5958

6059
const placeHolder = localize('themes.selectTheme', "Select Color Theme");
61-
const autoFocusIndex = firstIndex(picks, p => p.id === currentThemeId);
60+
const autoFocusIndex = firstIndex(picks, p => p.id === currentTheme.id);
6261
const delayer = new Delayer<void>(100);
6362

6463
if (this.extensionGalleryService.isEnabled()) {
@@ -94,8 +93,7 @@ class SelectIconThemeAction extends Action {
9493

9594
run(): TPromise<void> {
9695
return this.themeService.getFileIconThemes().then(themes => {
97-
const currentThemeId = this.themeService.getFileIconTheme();
98-
const currentTheme = themes.filter(theme => theme.id === currentThemeId)[0];
96+
const currentTheme = this.themeService.getFileIconTheme();
9997

10098
const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'tag:icon-theme');
10199

@@ -114,7 +112,7 @@ class SelectIconThemeAction extends Action {
114112
};
115113

116114
const placeHolder = localize('themes.selectIconTheme', "Select File Icon Theme");
117-
const autoFocusIndex = firstIndex(picks, p => p.id === currentThemeId);
115+
const autoFocusIndex = firstIndex(picks, p => p.id === currentTheme.id);
118116
const delayer = new Delayer<void>(100);
119117

120118

src/vs/workbench/parts/themes/test/electron-browser/themes.test.contribution.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
1212
import pfs = require('vs/base/node/pfs');
1313
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1414
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
15-
import { IThemeService, IThemeDocument } from 'vs/workbench/services/themes/common/themeService';
15+
import { IThemeService, IColorTheme } from 'vs/workbench/services/themes/common/themeService';
1616
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
1717
import { toResource } from 'vs/workbench/common/editor';
1818
import { ITextMateService } from 'vs/editor/node/textMate/textMateService';
@@ -40,11 +40,11 @@ interface IThemesResult {
4040
}
4141

4242
class ThemeDocument {
43-
private readonly _theme: IThemeDocument;
43+
private readonly _theme: IColorTheme;
4444
private readonly _cache: { [scopes: string]: ThemeRule; };
4545
private readonly _defaultColor: string;
4646

47-
constructor(theme: IThemeDocument) {
47+
constructor(theme: IColorTheme) {
4848
this._theme = theme;
4949
this._cache = Object.create(null);
5050
this._defaultColor = '#000000';
@@ -68,15 +68,15 @@ class ThemeDocument {
6868
let expected = this._defaultColor.toUpperCase();
6969
// No matching rule
7070
if (actual !== expected) {
71-
throw new Error(`[${this._theme.name}]: Unexpected color ${actual} for ${scopes}. Expected default ${expected}`);
71+
throw new Error(`[${this._theme.label}]: Unexpected color ${actual} for ${scopes}. Expected default ${expected}`);
7272
}
7373
return this._generateExplanation('default', color);
7474
}
7575

7676
let actual = color.toUpperCase();
7777
let expected = matchingRule.settings.foreground.toUpperCase();
7878
if (actual !== expected) {
79-
throw new Error(`[${this._theme.name}]: Unexpected color ${actual} for ${scopes}. Expected ${expected} coming in from ${matchingRule.rawSelector}`);
79+
throw new Error(`[${this._theme.label}]: Unexpected color ${actual} for ${scopes}. Expected ${expected} coming in from ${matchingRule.rawSelector}`);
8080
}
8181
return this._generateExplanation(matchingRule.rawSelector, color);
8282
}
@@ -187,14 +187,14 @@ class Snapper {
187187
if (success) {
188188
let themeName = getThemeName(themeId);
189189
result[themeName] = {
190-
document: new ThemeDocument(this.themeService.getColorThemeDocument()),
190+
document: new ThemeDocument(this.themeService.getColorTheme()),
191191
tokens: this._themedTokenize(grammar, lines)
192192
};
193193
}
194194
});
195195
}));
196196
}).then(_ => {
197-
return this.themeService.setColorTheme(currentTheme, false).then(_ => {
197+
return this.themeService.setColorTheme(currentTheme.id, false).then(_ => {
198198
return result;
199199
});
200200
});

0 commit comments

Comments
 (0)