Skip to content

Commit e839c27

Browse files
committed
fix implicit anys (for microsoft#70352)
1 parent 97cc9b1 commit e839c27

1 file changed

Lines changed: 42 additions & 28 deletions

File tree

src/vs/workbench/contrib/themes/browser/themes.contribution.ts

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configur
2222
import { LIGHT, DARK, HIGH_CONTRAST } from 'vs/platform/theme/common/themeService';
2323
import { colorThemeSchemaId } from 'vs/workbench/services/themes/common/colorThemeSchema';
2424
import { onUnexpectedError } from 'vs/base/common/errors';
25-
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
25+
import { IQuickInputService, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
2626

2727
export class SelectColorThemeAction extends Action {
2828

@@ -45,27 +45,28 @@ export class SelectColorThemeAction extends Action {
4545
return this.themeService.getColorThemes().then(themes => {
4646
const currentTheme = this.themeService.getColorTheme();
4747

48-
const picks: QuickPickInput[] = ([] as QuickPickInput[]).concat(
49-
toEntries(themes.filter(t => t.type === LIGHT), localize('themes.category.light', "light themes")),
50-
toEntries(themes.filter(t => t.type === DARK), localize('themes.category.dark', "dark themes")),
51-
toEntries(themes.filter(t => t.type === HIGH_CONTRAST), localize('themes.category.hc', "high contrast themes")),
52-
configurationEntries(this.extensionGalleryService, localize('installColorThemes', "Install Additional Color Themes..."))
53-
);
48+
const picks: QuickPickInput<ThemeItem>[] = [
49+
...toEntries(themes.filter(t => t.type === LIGHT), localize('themes.category.light', "light themes")),
50+
...toEntries(themes.filter(t => t.type === DARK), localize('themes.category.dark', "dark themes")),
51+
...toEntries(themes.filter(t => t.type === HIGH_CONTRAST), localize('themes.category.hc', "high contrast themes")),
52+
...configurationEntries(this.extensionGalleryService, localize('installColorThemes', "Install Additional Color Themes..."))
53+
];
5454

55-
const selectTheme = (theme: IColorTheme, applyTheme: boolean) => {
55+
const selectTheme = (theme: ThemeItem, applyTheme: boolean) => {
56+
let themeId = theme.id;
5657
if (typeof theme.id === 'undefined') { // 'pick in marketplace' entry
5758
if (applyTheme) {
5859
openExtensionViewlet(this.viewletService, 'category:themes ');
5960
}
60-
theme = currentTheme;
61+
themeId = currentTheme.id;
6162
}
6263
let target: ConfigurationTarget | undefined = undefined;
6364
if (applyTheme) {
6465
let confValue = this.configurationService.inspect(COLOR_THEME_SETTING);
6566
target = typeof confValue.workspace !== 'undefined' ? ConfigurationTarget.WORKSPACE : ConfigurationTarget.USER;
6667
}
6768

68-
this.themeService.setColorTheme(theme.id, target).then(undefined,
69+
this.themeService.setColorTheme(themeId, target).then(undefined,
6970
err => {
7071
onUnexpectedError(err);
7172
this.themeService.setColorTheme(currentTheme.id, undefined);
@@ -74,12 +75,13 @@ export class SelectColorThemeAction extends Action {
7475
};
7576

7677
const placeHolder = localize('themes.selectTheme', "Select Color Theme (Up/Down Keys to Preview)");
77-
const autoFocusIndex = firstIndex(picks, p => p.type !== 'separator' && p.id === currentTheme.id);
78+
const autoFocusIndex = firstIndex(picks, p => isItem(p) && p.id === currentTheme.id);
79+
const activeItem: ThemeItem = picks[autoFocusIndex] as ThemeItem;
7880
const delayer = new Delayer<void>(100);
79-
const chooseTheme = theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0);
80-
const tryTheme = theme => delayer.trigger(() => selectTheme(theme, false));
81+
const chooseTheme = (theme: ThemeItem) => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0);
82+
const tryTheme = (theme: ThemeItem) => delayer.trigger(() => selectTheme(theme, false));
8183

82-
return this.quickInputService.pick(picks, { placeHolder, activeItem: picks[autoFocusIndex], onDidFocus: tryTheme })
84+
return this.quickInputService.pick(picks, { placeHolder, activeItem, onDidFocus: tryTheme })
8385
.then(chooseTheme);
8486
});
8587
}
@@ -107,25 +109,26 @@ class SelectIconThemeAction extends Action {
107109
return this.themeService.getFileIconThemes().then(themes => {
108110
const currentTheme = this.themeService.getFileIconTheme();
109111

110-
let picks: QuickPickInput[] = [{ id: '', label: localize('noIconThemeLabel', 'None'), description: localize('noIconThemeDesc', 'Disable file icons') }];
112+
let picks: QuickPickInput<ThemeItem>[] = [{ id: '', label: localize('noIconThemeLabel', 'None'), description: localize('noIconThemeDesc', 'Disable file icons') }];
111113
picks = picks.concat(
112114
toEntries(themes),
113115
configurationEntries(this.extensionGalleryService, localize('installIconThemes', "Install Additional File Icon Themes..."))
114116
);
115117

116-
const selectTheme = (theme, applyTheme: boolean) => {
118+
const selectTheme = (theme: ThemeItem, applyTheme: boolean) => {
119+
let themeId = theme.id;
117120
if (typeof theme.id === 'undefined') { // 'pick in marketplace' entry
118121
if (applyTheme) {
119122
openExtensionViewlet(this.viewletService, 'tag:icon-theme ');
120123
}
121-
theme = currentTheme;
124+
themeId = currentTheme.id;
122125
}
123126
let target: ConfigurationTarget | undefined = undefined;
124127
if (applyTheme) {
125128
let confValue = this.configurationService.inspect(ICON_THEME_SETTING);
126129
target = typeof confValue.workspace !== 'undefined' ? ConfigurationTarget.WORKSPACE : ConfigurationTarget.USER;
127130
}
128-
this.themeService.setFileIconTheme(theme && theme.id, target).then(undefined,
131+
this.themeService.setFileIconTheme(themeId, target).then(undefined,
129132
err => {
130133
onUnexpectedError(err);
131134
this.themeService.setFileIconTheme(currentTheme.id, undefined);
@@ -134,18 +137,19 @@ class SelectIconThemeAction extends Action {
134137
};
135138

136139
const placeHolder = localize('themes.selectIconTheme', "Select File Icon Theme");
137-
const autoFocusIndex = firstIndex(picks, p => p.type !== 'separator' && p.id === currentTheme.id);
140+
const autoFocusIndex = firstIndex(picks, p => isItem(p) && p.id === currentTheme.id);
141+
const activeItem: ThemeItem = picks[autoFocusIndex] as ThemeItem;
138142
const delayer = new Delayer<void>(100);
139-
const chooseTheme = theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0);
140-
const tryTheme = theme => delayer.trigger(() => selectTheme(theme, false));
143+
const chooseTheme = (theme: ThemeItem) => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0);
144+
const tryTheme = (theme: ThemeItem) => delayer.trigger(() => selectTheme(theme, false));
141145

142-
return this.quickInputService.pick(picks, { placeHolder, activeItem: picks[autoFocusIndex], onDidFocus: tryTheme })
146+
return this.quickInputService.pick(picks, { placeHolder, activeItem, onDidFocus: tryTheme })
143147
.then(chooseTheme);
144148
});
145149
}
146150
}
147151

148-
function configurationEntries(extensionGalleryService: IExtensionGalleryService, label: string): QuickPickInput[] {
152+
function configurationEntries(extensionGalleryService: IExtensionGalleryService, label: string): QuickPickInput<ThemeItem>[] {
149153
if (extensionGalleryService.isEnabled()) {
150154
return [
151155
{
@@ -154,7 +158,7 @@ function configurationEntries(extensionGalleryService: IExtensionGalleryService,
154158
{
155159
id: undefined,
156160
label: label,
157-
alwaysShow: true,
161+
alwaysShow: true
158162
}
159163
];
160164
}
@@ -169,11 +173,21 @@ function openExtensionViewlet(viewletService: IViewletService, query: string) {
169173
}
170174
});
171175
}
176+
interface ThemeItem {
177+
id: string | undefined;
178+
label: string;
179+
description?: string;
180+
alwaysShow?: boolean;
181+
}
182+
183+
function isItem(i: QuickPickInput<ThemeItem>): i is ThemeItem {
184+
return i['type'] !== 'separatpr';
185+
}
172186

173-
function toEntries(themes: Array<IColorTheme | IFileIconTheme>, label?: string) {
174-
const toEntry = theme => <IQuickPickItem>{ id: theme.id, label: theme.label, description: theme.description };
175-
const sorter = (t1: IQuickPickItem, t2: IQuickPickItem) => t1.label.localeCompare(t2.label);
176-
let entries: QuickPickInput[] = themes.map(toEntry).sort(sorter);
187+
function toEntries(themes: Array<IColorTheme | IFileIconTheme>, label?: string): QuickPickInput<ThemeItem>[] {
188+
const toEntry = (theme: IColorTheme): ThemeItem => ({ id: theme.id, label: theme.label, description: theme.description });
189+
const sorter = (t1: ThemeItem, t2: ThemeItem) => t1.label.localeCompare(t2.label);
190+
let entries: QuickPickInput<ThemeItem>[] = themes.map(toEntry).sort(sorter);
177191
if (entries.length > 0 && label) {
178192
entries.unshift({ type: 'separator', label });
179193
}

0 commit comments

Comments
 (0)