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 6, 2018
1 parent 10bf4c6 commit 35f7ed7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/vs/platform/quickinput/common/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
import URI from 'vs/base/common/uri';
import { Event } from 'vs/base/common/event';
import { FileKind } from 'vs/platform/files/common/files';

export interface IQuickPickItem {
id?: string;
Expand All @@ -19,6 +20,11 @@ export interface IQuickPickItem {
picked?: boolean;
}

export interface IFilePickItem extends IQuickPickItem {
resource: URI;
fileKind?: FileKind;
}

export interface IQuickNavigateConfiguration {
keybindings: ResolvedKeybinding[];
}
Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/browser/actions/workspaceCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import URI from 'vs/base/common/uri';
import * as resources from 'vs/base/common/resources';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { dirname } from 'vs/base/common/paths';
import { IQuickOpenService, IFilePickOpenEntry, IPickOptions } from 'vs/platform/quickOpen/common/quickOpen';
import { CancellationToken } from 'vs/base/common/cancellation';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
Expand All @@ -24,6 +23,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { isLinux } from 'vs/base/common/platform';
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
import { IQuickInputService, IPickOptions, IFilePickItem } from 'vs/platform/quickinput/common/quickInput';

export const ADD_ROOT_FOLDER_COMMAND_ID = 'addRootFolder';
export const ADD_ROOT_FOLDER_LABEL = nls.localize('addFolderToWorkspace', "Add Folder to Workspace...");
Expand Down Expand Up @@ -158,8 +158,8 @@ CommandsRegistry.registerCommand({
}
});

CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (accessor, args?: [IPickOptions, CancellationToken]) {
const quickOpenService = accessor.get(IQuickOpenService);
CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (accessor, args?: [IPickOptions<IFilePickItem>, CancellationToken]) {
const quickInputService = accessor.get(IQuickInputService);
const uriDisplayService = accessor.get(IUriDisplayService);
const contextService = accessor.get(IWorkspaceContextService);

Expand All @@ -175,10 +175,10 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
folder,
resource: folder.uri,
fileKind: FileKind.ROOT_FOLDER
} as IFilePickOpenEntry;
} as IFilePickItem;
});

let options: IPickOptions;
let options: IPickOptions<IFilePickItem>;
if (args) {
options = args[0];
}
Expand All @@ -187,8 +187,8 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
options = Object.create(null);
}

if (!options.autoFocus) {
options.autoFocus = { autoFocusFirstEntry: true };
if (!options.activeItem) {
options.activeItem = folderPicks[0];
}

if (!options.placeHolder) {
Expand All @@ -208,7 +208,7 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
token = CancellationToken.None;
}

return quickOpenService.pick(folderPicks, options, token).then(pick => {
return quickInputService.pick(folderPicks, options, token).then(pick => {
if (!pick) {
return void 0;
}
Expand Down
40 changes: 22 additions & 18 deletions src/vs/workbench/browser/parts/editor/editorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ 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';

class SideBySideEditorEncodingSupport implements IEncodingSupport {
constructor(private master: IEncodingSupport, private details: IEncodingSupport) { }
Expand Down Expand Up @@ -834,6 +835,7 @@ export class ChangeModeAction extends Action {
@IEditorService private editorService: IEditorService,
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService,
@IPreferencesService private preferencesService: IPreferencesService,
@IInstantiationService private instantiationService: IInstantiationService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService
Expand All @@ -844,7 +846,7 @@ export class ChangeModeAction extends Action {
run(): TPromise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) {
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
}

const textModel = activeTextEditorWidget.getModel();
Expand Down Expand Up @@ -987,18 +989,18 @@ export class ChangeModeAction extends Action {
const currentAssociation = this.modeService.getModeIdByFilenameOrFirstLine(basename);

const languages = this.modeService.getRegisteredLanguageNames();
const picks: IPickOpenEntry[] = languages.sort().map((lang, index) => {
const picks: IQuickPickItem[] = languages.sort().map((lang, index) => {
const id = this.modeService.getModeIdForLanguageName(lang.toLowerCase());

return <IPickOpenEntry>{
return <IQuickPickItem>{
id,
label: lang,
description: (id === currentAssociation) ? nls.localize('currentAssociation', "Current Association") : void 0
};
});

TPromise.timeout(50 /* quick open is sensitive to being opened so soon after another */).done(() => {
this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || basename) }).done(language => {
this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || basename) }).done(language => {
if (language) {
const fileAssociationsConfig = this.configurationService.inspect(FILES_ASSOCIATIONS_CONFIG);

Expand Down Expand Up @@ -1030,7 +1032,7 @@ export class ChangeModeAction extends Action {
}
}

export interface IChangeEOLEntry extends IPickOpenEntry {
export interface IChangeEOLEntry extends IQuickPickItem {
eol: EndOfLineSequence;
}

Expand All @@ -1043,19 +1045,20 @@ class ChangeIndentationAction extends Action {
actionId: string,
actionLabel: string,
@IEditorService private editorService: IEditorService,
@IQuickOpenService private quickOpenService: IQuickOpenService
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService
) {
super(actionId, actionLabel);
}

run(): TPromise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) {
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
}

if (!isWritableCodeEditor(activeTextEditorWidget)) {
return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
return this.quickInputService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
}

const picks = [
Expand Down Expand Up @@ -1093,19 +1096,19 @@ export class ChangeEOLAction extends Action {
actionId: string,
actionLabel: string,
@IEditorService private editorService: IEditorService,
@IQuickOpenService private quickOpenService: IQuickOpenService
@IQuickInputService private quickInputService: IQuickInputService
) {
super(actionId, actionLabel);
}

run(): TPromise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) {
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
}

if (!isWritableCodeEditor(activeTextEditorWidget)) {
return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
return this.quickInputService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
}

const textModel = activeTextEditorWidget.getModel();
Expand All @@ -1117,7 +1120,7 @@ export class ChangeEOLAction extends Action {

const selectedIndex = (textModel && textModel.getEOL() === '\n') ? 0 : 1;

return this.quickOpenService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), autoFocus: { autoFocusIndex: selectedIndex } }).then(eol => {
return this.quickInputService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), activeItem: EOLOptions[selectedIndex] }).then(eol => {
if (eol) {
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget);
if (activeCodeEditor && isWritableCodeEditor(activeCodeEditor)) {
Expand All @@ -1139,6 +1142,7 @@ export class ChangeEncodingAction extends Action {
actionLabel: string,
@IEditorService private editorService: IEditorService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService,
@ITextResourceConfigurationService private textResourceConfigurationService: ITextResourceConfigurationService,
@IFileService private fileService: IFileService
) {
Expand All @@ -1147,19 +1151,19 @@ export class ChangeEncodingAction extends Action {

run(): TPromise<any> {
if (!getCodeEditor(this.editorService.activeTextEditorWidget)) {
return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
}

let activeControl = this.editorService.activeControl;
let encodingSupport: IEncodingSupport = toEditorWithEncodingSupport(activeControl.input);
if (!encodingSupport) {
return this.quickOpenService.pick([{ label: nls.localize('noFileEditor', "No file active at this time") }]);
return this.quickInputService.pick([{ label: nls.localize('noFileEditor', "No file active at this time") }]);
}

let pickActionPromise: TPromise<IPickOpenEntry>;
let pickActionPromise: TPromise<IQuickPickItem>;

let saveWithEncodingPick: IPickOpenEntry;
let reopenWithEncodingPick: IPickOpenEntry;
let saveWithEncodingPick: IQuickPickItem;
let reopenWithEncodingPick: IQuickPickItem;
if (language === LANGUAGE_DEFAULT) {
saveWithEncodingPick = { label: nls.localize('saveWithEncoding', "Save with Encoding") };
reopenWithEncodingPick = { label: nls.localize('reopenWithEncoding', "Reopen with Encoding") };
Expand All @@ -1173,7 +1177,7 @@ export class ChangeEncodingAction extends Action {
} else if (!isWritableBaseEditor(activeControl)) {
pickActionPromise = TPromise.as(reopenWithEncodingPick);
} else {
pickActionPromise = this.quickOpenService.pick([reopenWithEncodingPick, saveWithEncodingPick], { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true });
pickActionPromise = this.quickInputService.pick([reopenWithEncodingPick, saveWithEncodingPick], { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true });
}

return pickActionPromise.then(action => {
Expand Down

0 comments on commit 35f7ed7

Please sign in to comment.