Skip to content

Commit

Permalink
Use QuickInput (#29096)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Aug 10, 2018
1 parent d4a4d95 commit ffba35d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/vs/platform/quickinput/common/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const IQuickInputService = createDecorator<IQuickInputService>('quickInpu

export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

export type QuickPickInput<T> = TPromise<(T | IQuickPickSeparator)[]> | (T | IQuickPickSeparator)[];
export type QuickPickInput<T = IQuickPickItem> = T | IQuickPickSeparator;

export interface IQuickInputService {

Expand All @@ -232,9 +232,9 @@ export interface IQuickInputService {
/**
* Opens the quick input box for selecting items and returns a promise with the user selected item(s) if any.
*/
pick<T extends IQuickPickItem>(picks: QuickPickInput<T>, options?: IPickOptions<T> & { canPickMany: true }, token?: CancellationToken): TPromise<T[]>;
pick<T extends IQuickPickItem>(picks: QuickPickInput<T>, options?: IPickOptions<T> & { canPickMany: false }, token?: CancellationToken): TPromise<T>;
pick<T extends IQuickPickItem>(picks: QuickPickInput<T>, options?: Omit<IPickOptions<T>, 'canPickMany'>, token?: CancellationToken): TPromise<T>;
pick<T extends IQuickPickItem>(picks: TPromise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: IPickOptions<T> & { canPickMany: true }, token?: CancellationToken): TPromise<T[]>;
pick<T extends IQuickPickItem>(picks: TPromise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: IPickOptions<T> & { canPickMany: false }, token?: CancellationToken): TPromise<T>;
pick<T extends IQuickPickItem>(picks: TPromise<QuickPickInput<T>[]> | QuickPickInput<T>[], options?: Omit<IPickOptions<T>, 'canPickMany'>, token?: CancellationToken): TPromise<T>;

/**
* Opens the quick input box for text input and returns a promise with the user typed value if any.
Expand Down
41 changes: 20 additions & 21 deletions src/vs/workbench/browser/parts/editor/editorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpa
import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor';
import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/binaryDiffEditor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { SUPPORTED_ENCODINGS, IFileService, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
Expand All @@ -58,7 +58,8 @@ import { Schemas } from 'vs/base/common/network';
import { IAnchor } from 'vs/base/browser/ui/contextview/contextview';
import { Themable } from 'vs/workbench/common/theme';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
import { getIconClasses } from 'vs/workbench/browser/labels';

class SideBySideEditorEncodingSupport implements IEncodingSupport {
constructor(private master: IEncodingSupport, private details: IEncodingSupport) { }
Expand Down Expand Up @@ -834,7 +835,6 @@ export class ChangeModeAction extends Action {
@IModelService private modelService: IModelService,
@IEditorService private editorService: IEditorService,
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService,
@IPreferencesService private preferencesService: IPreferencesService,
@IInstantiationService private instantiationService: IInstantiationService,
Expand Down Expand Up @@ -867,7 +867,7 @@ export class ChangeModeAction extends Action {

// All languages are valid picks
const languages = this.modeService.getRegisteredLanguageNames();
const picks: IPickOpenEntry[] = languages.sort().map((lang, index) => {
const picks: QuickPickInput[] = languages.sort().map((lang, index) => {
let description: string;
if (currentModeId === lang) {
description = nls.localize('languageDescription', "({0}) - Configured Language", this.modeService.getModeIdForLanguageName(lang.toLowerCase()));
Expand All @@ -887,20 +887,20 @@ export class ChangeModeAction extends Action {
}
}

return <IFilePickOpenEntry>{
return <IQuickPickItem>{
label: lang,
resource: fakeResource,
iconClasses: getIconClasses(this.modelService, this.modeService, fakeResource),
description
};
});

if (hasLanguageSupport) {
picks[0].separator = { border: true, label: nls.localize('languagesPicks', "languages (identifier)") };
picks.unshift({ type: 'separator', border: true, label: nls.localize('languagesPicks', "languages (identifier)") });
}

// Offer action to configure via settings
let configureModeAssociations: IPickOpenEntry;
let configureModeSettings: IPickOpenEntry;
let configureModeAssociations: IQuickPickItem;
let configureModeSettings: IQuickPickItem;
let galleryAction: Action;
if (hasLanguageSupport) {
const ext = paths.extname(resource.fsPath) || paths.basename(resource.fsPath);
Expand All @@ -917,15 +917,15 @@ export class ChangeModeAction extends Action {
}

// Offer to "Auto Detect"
const autoDetectMode: IPickOpenEntry = {
const autoDetectMode: IQuickPickItem = {
label: nls.localize('autoDetect', "Auto Detect")
};

if (hasLanguageSupport) {
picks.unshift(autoDetectMode);
}

return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguage', "Select Language Mode"), matchOnDescription: true }).then(pick => {
return this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguage', "Select Language Mode"), matchOnDescription: true }).then(pick => {
if (!pick) {
return;
}
Expand Down Expand Up @@ -1045,7 +1045,6 @@ class ChangeIndentationAction extends Action {
actionId: string,
actionLabel: string,
@IEditorService private editorService: IEditorService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService
) {
super(actionId, actionLabel);
Expand All @@ -1061,7 +1060,7 @@ class ChangeIndentationAction extends Action {
return this.quickInputService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
}

const picks = [
const picks: QuickPickInput<IQuickPickItem & { run(): void }>[] = [
activeTextEditorWidget.getAction(IndentUsingSpaces.ID),
activeTextEditorWidget.getAction(IndentUsingTabs.ID),
activeTextEditorWidget.getAction(DetectIndentation.ID),
Expand All @@ -1080,10 +1079,10 @@ class ChangeIndentationAction extends Action {
};
});

(<IPickOpenEntry>picks[0]).separator = { label: nls.localize('indentView', "change view") };
(<IPickOpenEntry>picks[3]).separator = { label: nls.localize('indentConvert', "convert file"), border: true };
picks.splice(3, 0, { type: 'separator', label: nls.localize('indentConvert', "convert file"), border: true });
picks.unshift({ type: 'separator', label: nls.localize('indentView', "change view") });

return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true }).then(action => action && action.run());
return this.quickInputService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true }).then(action => action && action.run());
}
}

Expand Down Expand Up @@ -1141,7 +1140,6 @@ export class ChangeEncodingAction extends Action {
actionId: string,
actionLabel: string,
@IEditorService private editorService: IEditorService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService,
@ITextResourceConfigurationService private textResourceConfigurationService: ITextResourceConfigurationService,
@IFileService private fileService: IFileService
Expand Down Expand Up @@ -1204,7 +1202,7 @@ export class ChangeEncodingAction extends Action {
let aliasMatchIndex: number;

// All encodings are valid picks
const picks: IPickOpenEntry[] = Object.keys(SUPPORTED_ENCODINGS)
const picks: QuickPickInput[] = Object.keys(SUPPORTED_ENCODINGS)
.sort((k1, k2) => {
if (k1 === configuredEncoding) {
return -1;
Expand Down Expand Up @@ -1233,13 +1231,14 @@ export class ChangeEncodingAction extends Action {

// If we have a guessed encoding, show it first unless it matches the configured encoding
if (guessedEncoding && configuredEncoding !== guessedEncoding && SUPPORTED_ENCODINGS[guessedEncoding]) {
picks[0].separator = { border: true };
picks.unshift({ type: 'separator', border: true });
picks.unshift({ id: guessedEncoding, label: SUPPORTED_ENCODINGS[guessedEncoding].labelLong, description: nls.localize('guessedEncoding', "Guessed from content") });
}

return this.quickOpenService.pick(picks, {
const items = picks.filter(p => p.type !== 'separator') as IQuickPickItem[];
return this.quickInputService.pick(picks, {
placeHolder: isReopenWithEncoding ? nls.localize('pickEncodingForReopen', "Select File Encoding to Reopen File") : nls.localize('pickEncodingForSave', "Select File Encoding to Save with"),
autoFocus: { autoFocusIndex: typeof directMatchIndex === 'number' ? directMatchIndex : typeof aliasMatchIndex === 'number' ? aliasMatchIndex : void 0 }
activeItem: items[typeof directMatchIndex === 'number' ? directMatchIndex : typeof aliasMatchIndex === 'number' ? aliasMatchIndex : -1]
}).then(encoding => {
if (encoding) {
activeControl = this.editorService.activeControl;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ export class QuickInputService extends Component implements IQuickInputService {
this.updateStyles();
}

pick<T extends IQuickPickItem, O extends IPickOptions<T>>(picks: QuickPickInput<T>, options: O = <O>{}, token: CancellationToken = CancellationToken.None): TPromise<O extends { canPickMany: true } ? T[] : T> {
pick<T extends IQuickPickItem, O extends IPickOptions<T>>(picks: TPromise<QuickPickInput<T>[]> | QuickPickInput<T>[], options: O = <O>{}, token: CancellationToken = CancellationToken.None): TPromise<O extends { canPickMany: true } ? T[] : T> {
return new TPromise<O extends { canPickMany: true } ? T[] : T>((doResolve, reject) => {
let resolve = (result: any) => {
resolve = doResolve;
Expand Down

0 comments on commit ffba35d

Please sign in to comment.