Skip to content

Commit

Permalink
Provide API to open a new folder (fixes #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Apr 4, 2016
1 parent bae2168 commit 3aa5939
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/vs/platform/instantiation/common/instantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export interface IInstantiationService {
createInstance<A1, A2, A3, A4, A5, A6, A7, T>(descriptor: descriptors.SyncDescriptor7<A1, A2, A3, A4, A5, A6, A7, T>, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7): T;
createInstance<A1, A2, A3, A4, A5, A6, A7, A8, T>(descriptor: descriptors.SyncDescriptor8<A1, A2, A3, A4, A5, A6, A7, A8, T>, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8): T;

createInstance<T>(descriptor: descriptors.SyncDescriptor0<T>, ...args: any[]): T;

createInstance<T>(ctor: IConstructorSignature0<T>): T;
createInstance<A1, T>(ctor: IConstructorSignature1<A1, T>, first: A1): T;
createInstance<A1, A2, T>(ctor: IConstructorSignature2<A1, A2, T>, first: A1, second: A2): T;
Expand Down
8 changes: 8 additions & 0 deletions src/vs/workbench/api/node/extHostApiCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IDisposable} from 'vs/base/common/lifecycle';
import * as vscode from 'vscode';
import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
import * as types from 'vs/workbench/api/node/extHostTypes';
import {isMacintosh} from 'vs/base/common/platform';
import {ISingleEditOperation} from 'vs/editor/common/editorCommon';
import * as modes from 'vs/editor/common/modes';
import {ICommandHandlerDescription} from 'vs/platform/keybinding/common/keybindingService';
Expand Down Expand Up @@ -162,6 +163,13 @@ class ExtHostApiCommands {
{ name: 'column', description: '(optional) Column in which to preview.' },
]
});

this._register('vscode.openFolder', (uri: URI) => this._commands.executeCommand(isMacintosh ? 'workbench.action.files.openFileFolder' : 'workbench.action.files.openFolder', uri), {
description: 'Open a folder in the current window.',
args: [
{ name: 'uri', description: 'Uri of the folder to open.', constraint: URI }
]
});
}

// --- command impl
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/common/actionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function createCommandHandler(descriptor: SyncActionDescriptor): ICommand
}

export function triggerAndDisposeAction(instantitationService: IInstantiationService, telemetryService: ITelemetryService, partService: IPartService, descriptor: SyncActionDescriptor, args: any): TPromise<any> {
let actionInstance = instantitationService.createInstance(descriptor.syncDescriptor);
let actionInstance = Array.isArray(args) ? instantitationService.createInstance(descriptor.syncDescriptor, ...args) : instantitationService.createInstance(descriptor.syncDescriptor);
actionInstance.label = descriptor.label || actionInstance.label;

// don't run the action when not enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,24 @@ export class GlobalCopyPathAction extends Action {
}

export class BaseOpenAction extends Action {

private ipcMsg: string;
private ipcArg: any;

constructor(id: string, label: string, ipcMsg: string) {
constructor(id: string, label: string, ipcMsg: string, ipcArg?: any) {
super(id, label);

this.ipcMsg = ipcMsg;
this.ipcArg = ipcArg;
}

public run(): TPromise<any> {
ipc.send(this.ipcMsg); // Handle in browser process

// Handle in browser process
if (this.ipcArg) {
ipc.send(this.ipcMsg, this.ipcArg);
} else {
ipc.send(this.ipcMsg);
}

return TPromise.as(true);
}
Expand All @@ -140,19 +147,18 @@ export const OPEN_FOLDER_LABEL = nls.localize('openFolder', "Open Folder...");

export class OpenFolderAction extends BaseOpenAction {

constructor(id: string, label: string) {
super(id, label, 'vscode:openFolderPicker');
constructor(id: string, label: string, folderToOpen?: uri) {
super(id, label, folderToOpen ? 'vscode:windowOpen' : 'vscode:openFolderPicker', folderToOpen ? [folderToOpen.fsPath] : void 0);
}

}

export const OPEN_FILE_FOLDER_ID = 'workbench.action.files.openFileFolder';
export const OPEN_FILE_FOLDER_LABEL = nls.localize('openFileFolder', "Open...");

export class OpenFileFolderAction extends BaseOpenAction {

constructor(id: string, label: string) {
super(id, label, 'vscode:openFileFolderPicker');
constructor(id: string, label: string, folderToOpen?: uri) {
super(id, label, folderToOpen ? 'vscode:windowOpen' : 'vscode:openFileFolderPicker', folderToOpen ? [folderToOpen.fsPath] : void 0);
}
}

Expand Down

0 comments on commit 3aa5939

Please sign in to comment.