Skip to content

Commit

Permalink
Workspace folder picker command (for #32936) (#34648)
Browse files Browse the repository at this point in the history
* Workspace folder picker command (for #32936)

* fix test

* make this proper API
  • Loading branch information
bpasero authored Sep 20, 2017
1 parent 01dade3 commit 492ae2a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion extensions/vscode-api-tests/src/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ suite('commands namespace tests', () => {

return Promise.all([a, b, c, d]);
});
});
});
12 changes: 12 additions & 0 deletions extensions/vscode-api-tests/src/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ suite('window namespace tests', () => {
return Promise.all([a, b]);
});

test('showWorkspaceFolderPick', function () {
const p = (<any>window).showWorkspaceFolderPick(undefined);

return commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem').then(() => {
return p.then(workspace => {
assert.ok(true);
}, error => {
assert.ok(false);
});
});
});

test('Default value for showInput Box accepted even if fails validateInput, #33691', function () {
const result = window.showInputBox({
validateInput: (value: string) => {
Expand Down
27 changes: 26 additions & 1 deletion src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ declare module 'vscode' {
export namespace window {
export function showOpenDialog(options: OpenDialogOptions): Thenable<Uri[]>;
export function showSaveDialog(options: SaveDialogOptions): Thenable<Uri>;

/**
* Shows a selection list of [workspace folders](#workspace.workspaceFolders) to pick from.
* Returns `undefined` if no folder is open.
*
* @param options Configures the behavior of the workspace folder list.
* @return A promise that resolves to the workspace folder or `undefined`.
*/
export function showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions): Thenable<WorkspaceFolder | undefined>;
}

/**
* Options to configure the behaviour of the [workspace folder](#WorkspaceFolder) pick UI.
*/
export interface WorkspaceFolderPickOptions {

/**
* An optional string to show as place holder in the input box to guide the user what to pick on.
*/
placeHolder?: string;

/**
* Set to `true` to keep the picker open when focus moves to another part of the editor or to another window.
*/
ignoreFocusOut?: boolean;
}

// todo@joh discover files etc
Expand Down Expand Up @@ -172,4 +197,4 @@ declare module 'vscode' {
export namespace languages {
export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable;
}
}
}
5 changes: 4 additions & 1 deletion src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function createApiFactory(
const extHostDiagnostics = threadService.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(threadService));
const languageFeatures = threadService.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(threadService, extHostDocuments, extHostCommands, extHostHeapService, extHostDiagnostics));
const extHostFileSystemEvent = threadService.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService());
const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService));
const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService, extHostWorkspace, extHostCommands));
const extHostTerminalService = threadService.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(threadService));
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands));
const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService, extHostWorkspace));
Expand Down Expand Up @@ -347,6 +347,9 @@ export function createApiFactory(
showQuickPick(items: any, options: vscode.QuickPickOptions, token?: vscode.CancellationToken) {
return extHostQuickOpen.showQuickPick(items, options, token);
},
showWorkspaceFolderPick(options: vscode.WorkspaceFolderPickOptions) {
return extHostQuickOpen.showWorkspaceFolderPick(options);
},
showInputBox(options?: vscode.InputBoxOptions, token?: vscode.CancellationToken) {
return extHostQuickOpen.showInput(options, token);
},
Expand Down
23 changes: 21 additions & 2 deletions src/vs/workbench/api/node/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { wireCancellationToken } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { QuickPickOptions, QuickPickItem, InputBoxOptions } from 'vscode';
import { QuickPickOptions, QuickPickItem, InputBoxOptions, WorkspaceFolderPickOptions, WorkspaceFolder } from 'vscode';
import { MainContext, MainThreadQuickOpenShape, ExtHostQuickOpenShape, MyQuickPickItems, IMainContext } from './extHost.protocol';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';

export type Item = string | QuickPickItem;

export class ExtHostQuickOpen implements ExtHostQuickOpenShape {

private _proxy: MainThreadQuickOpenShape;
private _workspace: ExtHostWorkspace;
private _commands: ExtHostCommands;

private _onDidSelectItem: (handle: number) => void;
private _validateInput: (input: string) => string;

constructor(mainContext: IMainContext) {
constructor(mainContext: IMainContext, workspace: ExtHostWorkspace, commands: ExtHostCommands) {
this._proxy = mainContext.get(MainContext.MainThreadQuickOpen);
this._workspace = workspace;
this._commands = commands;
}

showQuickPick(itemsOrItemsPromise: string[] | Thenable<string[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<string | undefined>;
Expand Down Expand Up @@ -117,4 +124,16 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
}
return undefined;
}

// ---- workspace folder picker

showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token = CancellationToken.None): Thenable<WorkspaceFolder> {
return this._commands.executeCommand('_workbench.pickWorkspaceFolder', [options]).then((folder: WorkspaceFolder) => {
if (!folder) {
return undefined;
}

return this._workspace.getWorkspaceFolders().filter(folder => folder.uri.toString() === folder.uri.toString())[0];
});
}
}

0 comments on commit 492ae2a

Please sign in to comment.