提交 51ff4183 编写于 作者: M Martin Aeschlimann

clean up ThemeService API

上级 ef6b3de1
......@@ -241,15 +241,13 @@ class InspectTMScopesWidget extends Disposable implements IContentWidget {
result += `<tr><td class="tm-metadata-key">background</td><td class="tm-metadata-value">${metadata.background}</td>`;
result += `</tbody></table>`;
let theme = this._themeService.getColorThemeDocument();
if (theme) {
result += `<hr/>`;
let matchingRule = findMatchingThemeRule(theme, data.tokens1[token1Index].scopes);
if (matchingRule) {
result += `<code class="tm-theme-selector">${matchingRule.rawSelector}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
} else {
result += `<span class="tm-theme-selector">No theme selector.</span>`;
}
let theme = this._themeService.getColorTheme();
result += `<hr/>`;
let matchingRule = findMatchingThemeRule(theme, data.tokens1[token1Index].scopes);
if (matchingRule) {
result += `<code class="tm-theme-selector">${matchingRule.rawSelector}\n${JSON.stringify(matchingRule.settings, null, '\t')}</code>`;
} else {
result += `<span class="tm-theme-selector">No theme selector.</span>`;
}
result += `<hr/>`;
......
......@@ -5,9 +5,9 @@
'use strict';
import { IThemeDocument, IThemeSettingStyle } from 'vs/workbench/services/themes/common/themeService';
import { IColorTheme, IThemeSettingStyle } from 'vs/workbench/services/themes/common/themeService';
export function findMatchingThemeRule(theme: IThemeDocument, scopes: string[]): ThemeRule {
export function findMatchingThemeRule(theme: IColorTheme, scopes: string[]): ThemeRule {
for (let i = scopes.length - 1; i >= 0; i--) {
let parentScopes = scopes.slice(0, i);
let scope = scopes[i];
......@@ -19,7 +19,7 @@ export function findMatchingThemeRule(theme: IThemeDocument, scopes: string[]):
return null;
}
function findMatchingThemeRule2(theme: IThemeDocument, scope: string, parentScopes: string[]): ThemeRule {
function findMatchingThemeRule2(theme: IColorTheme, scope: string, parentScopes: string[]): ThemeRule {
let result: ThemeRule = null;
// Loop backwards, to ensure the last most specific rule wins
......
......@@ -162,7 +162,8 @@ export class MainProcessTextMateSyntax implements ITextMateService {
}
private _updateTheme(): void {
this._grammarRegistry.setTheme(this._themeService.getColorThemeDocument());
let colorTheme = this._themeService.getColorTheme();
this._grammarRegistry.setTheme({ name: colorTheme.label, settings: colorTheme.settings });
let colorMap = this._grammarRegistry.getColorMap();
let cssRules = MainProcessTextMateSyntax._generateCSS(colorMap);
this._styleElement.innerHTML = cssRules;
......
......@@ -112,7 +112,7 @@ export abstract class BaseTextEditor extends BaseEditor {
objects.assign(overrides, {
overviewRulerLanes: 3,
lineNumbersMinChars: 3,
theme: this.themeService.getColorTheme(),
theme: this.themeService.getColorTheme().id,
fixedOverflowWidgets: true
});
return overrides;
......
......@@ -271,7 +271,7 @@ export class Repl extends Panel implements IPrivateReplService {
},
lineDecorationsWidth: 0,
scrollBeyondLastLine: false,
theme: this.themeService.getColorTheme(),
theme: this.themeService.getColorTheme().id,
renderLineHighlight: 'none',
fixedOverflowWidgets: true,
acceptSuggestionOnEnter: false
......
......@@ -325,7 +325,7 @@ export class ExtensionEditor extends BaseEditor {
webview.contents = [body];
webview.onDidClickLink(link => this.openerService.open(link), null, this.contentDisposables);
this.themeService.onDidColorThemeChange(themeId => webview.style(themeId), null, this.contentDisposables);
this.themeService.onDidColorThemeChange(theme => webview.style(theme), null, this.contentDisposables);
this.contentDisposables.push(webview);
})
.then(null, () => {
......
......@@ -14,6 +14,7 @@ import { addDisposableListener, addClass } from 'vs/base/browser/dom';
import { isLightTheme, isDarkTheme } from 'vs/platform/theme/common/themes';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { MenuRegistry } from 'vs/platform/actions/common/actions';
import { IColorTheme } from 'vs/workbench/services/themes/common/themeService';
declare interface WebviewElement extends HTMLElement {
src: string;
......@@ -157,7 +158,8 @@ export default class Webview {
this._send('focus');
}
style(themeId: string): void {
style(theme: IColorTheme): void {
let themeId = theme.id;
const {color, backgroundColor, fontFamily, fontWeight, fontSize} = window.getComputedStyle(this._styleElement);
let value = `
......
......@@ -15,7 +15,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITerminalService, ITerminalFont, TERMINAL_PANEL_ID } from 'vs/workbench/parts/terminal/common/terminal';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IThemeService, IColorTheme } from 'vs/workbench/services/themes/common/themeService';
import { KillTerminalAction, CreateNewTerminalAction, SwitchTerminalInstanceAction, SwitchTerminalInstanceActionItem, CopyTerminalSelectionAction, TerminalPasteAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
import { Panel } from 'vs/workbench/browser/panel';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
......@@ -62,7 +62,7 @@ export class TerminalPanel extends Panel {
this._terminalService.setContainers(this.getContainer().getHTMLElement(), this._terminalContainer);
this._register(this._themeService.onDidColorThemeChange(themeId => this._updateTheme(themeId)));
this._register(this._themeService.onDidColorThemeChange(theme => this._updateTheme(theme)));
this._register(this._configurationService.onDidUpdateConfiguration(() => this._updateFont()));
this._updateFont();
this._updateTheme();
......@@ -192,11 +192,8 @@ export class TerminalPanel extends Panel {
}));
}
private _updateTheme(themeId?: string): void {
if (!themeId) {
themeId = this._themeService.getColorTheme();
}
private _updateTheme(colorTheme?: IColorTheme): void {
let themeId = colorTheme.id;
let baseThemeId = getBaseThemeId(themeId);
if (baseThemeId === this._currentBaseThemeId) {
return;
......
......@@ -40,8 +40,7 @@ export class SelectColorThemeAction extends Action {
run(): TPromise<void> {
return this.themeService.getColorThemes().then(themes => {
const currentThemeId = this.themeService.getColorTheme();
const currentTheme = themes.filter(theme => theme.id === currentThemeId)[0];
const currentTheme = this.themeService.getColorTheme();
const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'category:themes');
......@@ -58,7 +57,7 @@ export class SelectColorThemeAction extends Action {
};
const placeHolder = localize('themes.selectTheme', "Select Color Theme");
const autoFocusIndex = firstIndex(picks, p => p.id === currentThemeId);
const autoFocusIndex = firstIndex(picks, p => p.id === currentTheme.id);
const delayer = new Delayer<void>(100);
if (this.extensionGalleryService.isEnabled()) {
......@@ -94,8 +93,7 @@ class SelectIconThemeAction extends Action {
run(): TPromise<void> {
return this.themeService.getFileIconThemes().then(themes => {
const currentThemeId = this.themeService.getFileIconTheme();
const currentTheme = themes.filter(theme => theme.id === currentThemeId)[0];
const currentTheme = this.themeService.getFileIconTheme();
const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'tag:icon-theme');
......@@ -114,7 +112,7 @@ class SelectIconThemeAction extends Action {
};
const placeHolder = localize('themes.selectIconTheme', "Select File Icon Theme");
const autoFocusIndex = firstIndex(picks, p => p.id === currentThemeId);
const autoFocusIndex = firstIndex(picks, p => p.id === currentTheme.id);
const delayer = new Delayer<void>(100);
......
......@@ -12,7 +12,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import pfs = require('vs/base/node/pfs');
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IThemeService, IThemeDocument } from 'vs/workbench/services/themes/common/themeService';
import { IThemeService, IColorTheme } from 'vs/workbench/services/themes/common/themeService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { toResource } from 'vs/workbench/common/editor';
import { ITextMateService } from 'vs/editor/node/textMate/textMateService';
......@@ -40,11 +40,11 @@ interface IThemesResult {
}
class ThemeDocument {
private readonly _theme: IThemeDocument;
private readonly _theme: IColorTheme;
private readonly _cache: { [scopes: string]: ThemeRule; };
private readonly _defaultColor: string;
constructor(theme: IThemeDocument) {
constructor(theme: IColorTheme) {
this._theme = theme;
this._cache = Object.create(null);
this._defaultColor = '#000000';
......@@ -68,7 +68,7 @@ class ThemeDocument {
let expected = this._defaultColor.toUpperCase();
// No matching rule
if (actual !== expected) {
throw new Error(`[${this._theme.name}]: Unexpected color ${actual} for ${scopes}. Expected default ${expected}`);
throw new Error(`[${this._theme.label}]: Unexpected color ${actual} for ${scopes}. Expected default ${expected}`);
}
return this._generateExplanation('default', color);
}
......@@ -76,7 +76,7 @@ class ThemeDocument {
let actual = color.toUpperCase();
let expected = matchingRule.settings.foreground.toUpperCase();
if (actual !== expected) {
throw new Error(`[${this._theme.name}]: Unexpected color ${actual} for ${scopes}. Expected ${expected} coming in from ${matchingRule.rawSelector}`);
throw new Error(`[${this._theme.label}]: Unexpected color ${actual} for ${scopes}. Expected ${expected} coming in from ${matchingRule.rawSelector}`);
}
return this._generateExplanation(matchingRule.rawSelector, color);
}
......@@ -187,14 +187,14 @@ class Snapper {
if (success) {
let themeName = getThemeName(themeId);
result[themeName] = {
document: new ThemeDocument(this.themeService.getColorThemeDocument()),
document: new ThemeDocument(this.themeService.getColorTheme()),
tokens: this._themedTokenize(grammar, lines)
};
}
});
}));
}).then(_ => {
return this.themeService.setColorTheme(currentTheme, false).then(_ => {
return this.themeService.setColorTheme(currentTheme.id, false).then(_ => {
return result;
});
});
......
......@@ -14,30 +14,34 @@ export const VS_LIGHT_THEME = 'vs';
export const VS_DARK_THEME = 'vs-dark';
export const VS_HC_THEME = 'hc-black';
export interface IThemeService {
_serviceBrand: any;
setColorTheme(themeId: string, broadcastToAllWindows: boolean): TPromise<boolean>;
getColorTheme(): string;
getColorThemeDocument(): IThemeDocument;
getColorThemes(): TPromise<IThemeData[]>;
onDidColorThemeChange: Event<string>;
setFileIconTheme(iconThemeId: string, broadcastToAllWindows: boolean): TPromise<boolean>;
getFileIconTheme(): string;
getFileIconThemes(): TPromise<IThemeData[]>;
export class IColorTheme {
id: string;
label: string;
description?: string;
isLoaded: boolean;
settings?: IThemeSetting[];
}
export interface IThemeData {
export interface IFileIconTheme {
id: string;
label: string;
description?: string;
path: string;
isLoaded: boolean;
hasFileIcons?: boolean;
hasFolderIcons?: boolean;
}
export interface IThemeDocument {
name: string;
include: string;
settings: IThemeSetting[];
export interface IThemeService {
_serviceBrand: any;
setColorTheme(themeId: string, broadcastToAllWindows: boolean): TPromise<IColorTheme>;
getColorTheme(): IColorTheme;
getColorThemes(): TPromise<IColorTheme[]>;
onDidColorThemeChange: Event<IColorTheme>;
setFileIconTheme(iconThemeId: string, broadcastToAllWindows: boolean): TPromise<IFileIconTheme>;
getFileIconTheme(): IFileIconTheme;
getFileIconThemes(): TPromise<IFileIconTheme[]>;
onDidFileIconThemeChange: Event<IFileIconTheme>;
}
export interface IThemeSetting {
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IThemeDocument, IThemeSetting } from 'vs/workbench/services/themes/common/themeService';
import { IThemeSetting } from 'vs/workbench/services/themes/common/themeService';
import { Color } from 'vs/base/common/color';
import { getBaseThemeId, getSyntaxThemeId } from 'vs/platform/theme/common/themes';
......@@ -59,9 +59,9 @@ class Theme {
private settings: IThemeSetting[];
private globalSettings: ThemeGlobalSettings = null;
constructor(private themeId: string, themeDocument: IThemeDocument) {
constructor(private themeId: string, themeSettings: IThemeSetting[]) {
this.selector = `${getBaseThemeId(themeId)}.${getSyntaxThemeId(themeId)}`;
this.settings = themeDocument.settings;
this.settings = themeSettings;
let settings = this.settings[0];
if (!settings.scope) {
this.globalSettings = settings.settings;
......@@ -92,7 +92,7 @@ abstract class StyleRules {
export class EditorStylesContribution {
public contributeStyles(themeId: string, themeDocument: IThemeDocument, cssRules: string[]) {
public contributeStyles(themeId: string, themeSettings: IThemeSetting[], cssRules: string[]) {
let editorStyleRules = [
new EditorBackgroundStyleRules(),
new EditorCursorStyleRules(),
......@@ -106,7 +106,7 @@ export class EditorStylesContribution {
new EditorHoverHighlightStyleRules(),
new EditorLinkStyleRules()
];
let theme = new Theme(themeId, themeDocument);
let theme = new Theme(themeId, themeSettings);
if (theme.hasGlobalSettings()) {
editorStyleRules.forEach((editorStyleRule => {
editorStyleRule.getCssRules(theme, cssRules);
......@@ -117,8 +117,8 @@ export class EditorStylesContribution {
export class SearchViewStylesContribution {
public contributeStyles(themeId: string, themeDocument: IThemeDocument, cssRules: string[]): void {
let theme = new Theme(themeId, themeDocument);
public contributeStyles(themeId: string, themeSettings: IThemeSetting[], cssRules: string[]): void {
let theme = new Theme(themeId, themeSettings);
if (theme.hasGlobalSettings()) {
if (theme.getGlobalSettings().findMatchHighlight) {
let color = new Color(theme.getGlobalSettings().findMatchHighlight);
......@@ -160,8 +160,8 @@ export class TerminalStylesContribution {
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
public contributeStyles(themeId: string, themeDocument: IThemeDocument, cssRules: string[]): void {
const theme = new Theme(themeId, themeDocument);
public contributeStyles(themeId: string, themeSettings: IThemeSetting[], cssRules: string[]): void {
const theme = new Theme(themeId, themeSettings);
if (theme.hasGlobalSettings()) {
const keys = Object.keys(theme.getGlobalSettings());
keys.filter(key => key.indexOf('ansi') === 0).forEach(key => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册