mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Execute onClickCommand on Main side
This commit is contained in:
@@ -289,7 +289,7 @@ export abstract class ExtHostEditorsShape {
|
||||
export abstract class ExtHostTreeExplorersShape {
|
||||
$provideRootNode(providerId: string): TPromise<InternalTreeExplorerNode> { throw ni(); };
|
||||
$resolveChildren(providerId: string, node: InternalTreeExplorerNode): TPromise<InternalTreeExplorerNode[]> { throw ni(); }
|
||||
$executeCommand(providerId: string, node: InternalTreeExplorerNode): TPromise<void> { throw ni(); }
|
||||
$getInternalCommand(providerId: string, node: InternalTreeExplorerNode): TPromise<modes.Command> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostExtensionServiceShape {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { MainContext, ExtHostTreeExplorersShape, MainThreadTreeExplorersShape }
|
||||
import { InternalTreeExplorerNode } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
|
||||
export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
private _proxy: MainThreadTreeExplorersShape;
|
||||
@@ -79,14 +80,20 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
});
|
||||
}
|
||||
|
||||
$executeCommand(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise<void> {
|
||||
// Convert the command on the ExtHost side so we can pass the original externalNode to the registered handler
|
||||
$getInternalCommand(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise<modes.Command> {
|
||||
const commandConverter = this.commands.converter;
|
||||
|
||||
if (mainThreadNode.clickCommand) {
|
||||
const externalNode = this._externalNodeMaps[providerId][mainThreadNode.id];
|
||||
return asWinJsPromise(() => this.commands.executeCommand(mainThreadNode.clickCommand, externalNode)).then(() => {
|
||||
return null;
|
||||
}, err => {
|
||||
return TPromise.wrapError(`Failed to execute command '${mainThreadNode.clickCommand}' provided by TreeExplorerNodeProvider '${providerId}'.`);
|
||||
|
||||
const internalCommand = commandConverter.toInternal({
|
||||
title: '',
|
||||
command: mainThreadNode.clickCommand,
|
||||
arguments: [externalNode]
|
||||
});
|
||||
|
||||
return TPromise.wrap(internalCommand);
|
||||
}
|
||||
|
||||
return TPromise.as(null);
|
||||
|
||||
@@ -10,6 +10,7 @@ import { ExtHostContext, MainThreadTreeExplorersShape, ExtHostTreeExplorersShape
|
||||
import { ITreeExplorerViewletService } from 'vs/workbench/parts/explorers/browser/treeExplorerViewletService';
|
||||
import { InternalTreeExplorerNode } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import { IMessageService, Severity } from 'vs/platform/message/common/message';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
|
||||
export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape {
|
||||
private _proxy: ExtHostTreeExplorersShape;
|
||||
@@ -17,7 +18,8 @@ export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape {
|
||||
constructor(
|
||||
@IThreadService private threadService: IThreadService,
|
||||
@ITreeExplorerViewletService private treeExplorerService: ITreeExplorerViewletService,
|
||||
@IMessageService private messageService: IMessageService
|
||||
@IMessageService private messageService: IMessageService,
|
||||
@ICommandService private commandService: ICommandService
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -34,8 +36,10 @@ export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape {
|
||||
resolveChildren: (node: InternalTreeExplorerNode): TPromise<InternalTreeExplorerNode[]> => {
|
||||
return this._proxy.$resolveChildren(providerId, node).then(children => children, onError);
|
||||
},
|
||||
executeCommand: (node: InternalTreeExplorerNode): TPromise<void> => {
|
||||
return this._proxy.$executeCommand(providerId, node);
|
||||
executeCommand: (node: InternalTreeExplorerNode): TPromise<any> => {
|
||||
return this._proxy.$getInternalCommand(providerId, node).then(command => {
|
||||
return this.commandService.executeCommand(command.id, ...command.arguments);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user