Skip to content

Commit f6c1da4

Browse files
author
Benjamin Pasero
committed
icons: support in pickers
1 parent 01d3b74 commit f6c1da4

4 files changed

Lines changed: 42 additions & 20 deletions

File tree

src/vs/workbench/browser/parts/quickopen/quickOpenController.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {KeyMod} from 'vs/base/common/keyCodes';
3535
import {QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry} from 'vs/workbench/browser/quickopen';
3636
import errors = require('vs/base/common/errors');
3737
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
38-
import {IPickOpenEntry, IInputOptions, IQuickOpenService, IPickOptions, IShowOptions} from 'vs/workbench/services/quickopen/common/quickOpenService';
38+
import {IPickOpenEntry, IFilePickOpenEntry, IInputOptions, IQuickOpenService, IPickOptions, IShowOptions} from 'vs/workbench/services/quickopen/common/quickOpenService';
3939
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
4040
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
4141
import {IMessageService, Severity} from 'vs/platform/message/common/message';
@@ -273,7 +273,8 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
273273
this.telemetryService
274274
);
275275

276-
this.pickOpenWidget.create();
276+
const pickOpenContainer = this.pickOpenWidget.create();
277+
DOM.addClass(pickOpenContainer, 'show-file-icons');
277278
}
278279

279280
// Update otherwise
@@ -325,9 +326,9 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
325326

326327
// Model
327328
const model = new QuickOpenModel();
328-
const entries = picks.map(e => new PickOpenEntry(e, () => progress(e)));
329+
const entries = picks.map(e => this.instantiationService.createInstance(PickOpenEntry, e, () => progress(e)));
329330
if (picks.length === 0) {
330-
entries.push(new PickOpenEntry({ label: nls.localize('emptyPicks', "There are no entries to pick from") }));
331+
entries.push(this.instantiationService.createInstance(PickOpenEntry, { label: nls.localize('emptyPicks', "There are no entries to pick from") }, null));
331332
}
332333

333334
model.setEntries(entries);
@@ -941,10 +942,13 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
941942
private hasSeparator: boolean;
942943
private separatorLabel: string;
943944
private alwaysShow: boolean;
945+
private resource: URI;
946+
private isFolder: boolean;
944947

945948
constructor(
946949
item: IPickOpenEntry,
947-
private onPreview?: () => void
950+
private onPreview: () => void,
951+
@IModeService private modeService: IModeService
948952
) {
949953
super(item.label);
950954

@@ -953,6 +957,16 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
953957
this.hasSeparator = item.separator && item.separator.border;
954958
this.separatorLabel = item.separator && item.separator.label;
955959
this.alwaysShow = item.alwaysShow;
960+
961+
const fileItem = <IFilePickOpenEntry>item;
962+
this.resource = fileItem.resource;
963+
this.isFolder = fileItem.isFolder;
964+
}
965+
966+
public getLabelOptions(): IIconLabelOptions {
967+
return {
968+
extraClasses: this.resource ? getIconClasses(this.modeService, this.resource, this.isFolder) : []
969+
};
956970
}
957971

958972
public get shouldRunWithContext(): IEntryRunContext {
@@ -1026,7 +1040,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
10261040

10271041
public getLabelOptions(): IIconLabelOptions {
10281042
return {
1029-
extraClasses: getIconClasses(this.modeService, this.resource),
1043+
extraClasses: getIconClasses(this.modeService, this.resource)
10301044
};
10311045
}
10321046

src/vs/workbench/electron-browser/actions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {IConfigurationService} from 'vs/platform/configuration/common/configurat
2323
import {CommandsRegistry} from 'vs/platform/commands/common/commands';
2424
import paths = require('vs/base/common/paths');
2525
import {isMacintosh} from 'vs/base/common/platform';
26-
import {IQuickOpenService, IPickOpenEntry, ISeparator} from 'vs/workbench/services/quickopen/common/quickOpenService';
26+
import {IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry, ISeparator} from 'vs/workbench/services/quickopen/common/quickOpenService';
2727
import {KeyMod} from 'vs/base/common/keyCodes';
2828
import {ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
2929
import * as browser from 'vs/base/browser/browser';
@@ -428,8 +428,10 @@ export class OpenRecentAction extends Action {
428428
}
429429

430430
private openRecent(recentFiles: string[], recentFolders: string[]): void {
431-
function toPick(path: string, separator: ISeparator): IPickOpenEntry {
431+
function toPick(path: string, separator: ISeparator, isFolder: boolean): IFilePickOpenEntry {
432432
return {
433+
resource: URI.file(path),
434+
isFolder,
433435
label: paths.basename(path),
434436
description: paths.dirname(path),
435437
separator,
@@ -443,8 +445,8 @@ export class OpenRecentAction extends Action {
443445
ipc.send('vscode:windowOpen', [path], newWindow);
444446
}
445447

446-
const folderPicks: IPickOpenEntry[] = recentFolders.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('folders', "folders") } : void 0));
447-
const filePicks: IPickOpenEntry[] = recentFiles.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('files', "files"), border: true } : void 0));
448+
const folderPicks: IFilePickOpenEntry[] = recentFolders.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('folders', "folders") } : void 0, true));
449+
const filePicks: IFilePickOpenEntry[] = recentFiles.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('files', "files"), border: true } : void 0, false));
448450

449451
const hasWorkspace = !!this.contextService.getWorkspace();
450452

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SelectColorThemeAction extends Action {
4242
const currentThemeId = this.themeService.getColorTheme();
4343
const currentTheme = themes.filter(theme => theme.id === currentThemeId)[0];
4444

45-
const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'category:themes');
45+
const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'category:themes');
4646

4747
const picks: IPickOpenEntry[] = themes
4848
.map(theme => ({ id: theme.id, label: theme.label, description: theme.description }))
@@ -64,12 +64,12 @@ const pickInMarketPlace = findInMarketplacePick(this.viewletService, 'category:t
6464
picks.push(pickInMarketPlace);
6565
}
6666

67-
return this.quickOpenService.pick(picks, { placeHolder, autoFocus: { autoFocusIndex }})
67+
return this.quickOpenService.pick(picks, { placeHolder, autoFocus: { autoFocusIndex } })
6868
.then(
69-
theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0),
70-
null,
71-
theme => delayer.trigger(() => selectTheme(theme, false))
72-
);
69+
theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0),
70+
null,
71+
theme => delayer.trigger(() => selectTheme(theme, false))
72+
);
7373
});
7474
}
7575
}
@@ -121,11 +121,11 @@ class SelectIconThemeAction extends Action {
121121
picks.push(pickInMarketPlace);
122122
}
123123

124-
return this.quickOpenService.pick(picks, { placeHolder, autoFocus: { autoFocusIndex }})
124+
return this.quickOpenService.pick(picks, { placeHolder, autoFocus: { autoFocusIndex } })
125125
.then(
126-
theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0),
127-
null,
128-
theme => delayer.trigger(() => selectTheme(theme, false))
126+
theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0),
127+
null,
128+
theme => delayer.trigger(() => selectTheme(theme, false))
129129
);
130130
});
131131
}

src/vs/workbench/services/quickopen/common/quickOpenService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
'use strict';
66

77
import {TPromise} from 'vs/base/common/winjs.base';
8+
import uri from 'vs/base/common/uri';
89
import Event from 'vs/base/common/event';
910
import {CancellationToken} from 'vs/base/common/cancellation';
1011
import {IQuickNavigateConfiguration, IAutoFocus, IEntryRunContext} from 'vs/base/parts/quickopen/common/quickOpen';
1112
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
1213

14+
export interface IFilePickOpenEntry extends IPickOpenEntry {
15+
resource: uri;
16+
isFolder?: boolean;
17+
}
18+
1319
export interface IPickOpenEntry {
1420
id?: string;
1521
label: string;

0 commit comments

Comments
 (0)