diff --git a/src/vs/platform/quickOpen/common/quickOpen.ts b/src/vs/platform/quickOpen/common/quickOpen.ts index e5e1bffd9d41d85e7d25f6a0353c2ee6fb681271..6a9b847fc09ae56fd76d61e129e137fb7faf1976 100644 --- a/src/vs/platform/quickOpen/common/quickOpen.ts +++ b/src/vs/platform/quickOpen/common/quickOpen.ts @@ -86,6 +86,14 @@ export interface IPickOptions { contextKey?: string; } +export interface IStringPickOptions extends IPickOptions { + onDidFocus?: (item: string) => void; +} + +export interface ITypedPickOptions extends IPickOptions { + onDidFocus?: (entry: T) => void; +} + export interface IShowOptions { quickNavigateConfiguration?: IQuickNavigateConfiguration; inputSelection?: { start: number; end: number; }; @@ -114,10 +122,10 @@ export interface IQuickOpenService { * Passing in a promise will allow you to resolve the elements in the background while quick open will show a * progress bar spinning. */ - pick(picks: TPromise, options?: IPickOptions, token?: CancellationToken): TPromise; - pick(picks: TPromise, options?: IPickOptions, token?: CancellationToken): TPromise; - pick(picks: string[], options?: IPickOptions, token?: CancellationToken): TPromise; - pick(picks: T[], options?: IPickOptions, token?: CancellationToken): TPromise; + pick(picks: TPromise, options?: IStringPickOptions, token?: CancellationToken): TPromise; + pick(picks: TPromise, options?: ITypedPickOptions, token?: CancellationToken): TPromise; + pick(picks: string[], options?: IStringPickOptions, token?: CancellationToken): TPromise; + pick(picks: T[], options?: ITypedPickOptions, token?: CancellationToken): TPromise; /** * Allows to navigate from the outside in an opened picker. diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 5bc53c73ece332af0d91fb601d540dc58cdf76a5..178903e64f2715e92a78ab6e89eddf4ee91ff45c 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -34,7 +34,7 @@ import { Event, Emitter } from 'vs/base/common/event'; import { IPartService } from 'vs/workbench/services/part/common/partService'; import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, CLOSE_ON_FOCUS_LOST_CONFIG } from 'vs/workbench/browser/quickopen'; import * as errors from 'vs/base/common/errors'; -import { IPickOpenEntry, IFilePickOpenEntry, IQuickOpenService, IPickOptions, IShowOptions, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen'; +import { IPickOpenEntry, IFilePickOpenEntry, IQuickOpenService, IShowOptions, IPickOpenItem, IStringPickOptions, ITypedPickOptions } from 'vs/platform/quickOpen/common/quickOpen'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -73,6 +73,7 @@ interface IInternalPickOptions { ignoreFocusLost?: boolean; quickNavigateConfiguration?: IQuickNavigateConfiguration; onDidType?: (value: string) => any; + onDidFocus?: (item: any) => void; } export class QuickOpenController extends Component implements IQuickOpenService { @@ -145,11 +146,11 @@ export class QuickOpenController extends Component implements IQuickOpenService } } - pick(picks: TPromise, options?: IPickOptions, token?: CancellationToken): TPromise; - pick(picks: TPromise, options?: IPickOptions, token?: CancellationToken): TPromise; - pick(picks: string[], options?: IPickOptions, token?: CancellationToken): TPromise; - pick(picks: T[], options?: IPickOptions, token?: CancellationToken): TPromise; - pick(arg1: string[] | TPromise | IPickOpenEntry[] | TPromise, options?: IPickOptions, token?: CancellationToken): TPromise { + pick(picks: TPromise, options?: IStringPickOptions, token?: CancellationToken): TPromise; + pick(picks: TPromise, options?: ITypedPickOptions, token?: CancellationToken): TPromise; + pick(picks: string[], options?: IStringPickOptions, token?: CancellationToken): TPromise; + pick(picks: T[], options?: ITypedPickOptions, token?: CancellationToken): TPromise; + pick(arg1: string[] | TPromise | IPickOpenEntry[] | TPromise, options?: IStringPickOptions | ITypedPickOptions, token?: CancellationToken): TPromise { if (!options) { options = Object.create(null); } @@ -279,7 +280,16 @@ export class QuickOpenController extends Component implements IQuickOpenService // Model const model = new QuickOpenModel([], new PickOpenActionProvider()); - const entries = picks.map((e, index) => this.instantiationService.createInstance(PickOpenEntry, e, index, () => progress(e), () => this.pickOpenWidget.refresh())); + const entries = picks.map((e, index) => { + const onPreview = () => { + if (options.onDidFocus) { + options.onDidFocus(e); + } + + progress(e); + }; + return this.instantiationService.createInstance(PickOpenEntry, e, index, onPreview, () => this.pickOpenWidget.refresh()); + }); if (picks.length === 0) { entries.push(this.instantiationService.createInstance(PickOpenEntry, { label: nls.localize('emptyPicks', "There are no entries to pick from") }, 0, null, null)); } diff --git a/src/vs/workbench/parts/themes/electron-browser/themes.contribution.ts b/src/vs/workbench/parts/themes/electron-browser/themes.contribution.ts index bde131d66ed088209a343e03447c3f18d93ff85d..4dea03c0c205de6638f8fa8b510cd976577c4af7 100644 --- a/src/vs/workbench/parts/themes/electron-browser/themes.contribution.ts +++ b/src/vs/workbench/parts/themes/electron-browser/themes.contribution.ts @@ -77,13 +77,11 @@ export class SelectColorThemeAction extends Action { const placeHolder = localize('themes.selectTheme', "Select Color Theme (Up/Down Keys to Preview)"); const autoFocusIndex = firstIndex(picks, p => p.id === currentTheme.id); const delayer = new Delayer(100); + const chooseTheme = theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0); + const tryTheme = theme => delayer.trigger(() => selectTheme(theme, false)); - return this.quickOpenService.pick(picks, { placeHolder, autoFocus: { autoFocusIndex } }) - .then( - theme => delayer.trigger(() => selectTheme(theme || currentTheme, true), 0), - null, - theme => delayer.trigger(() => selectTheme(theme, false)) - ); + return this.quickOpenService.pick(picks, { placeHolder, autoFocus: { autoFocusIndex }, onDidFocus: tryTheme }) + .then(chooseTheme); }); } }