-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into hide-activity-bar
- Loading branch information
Showing
29 changed files
with
1,214 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
import { localize } from 'vs/nls'; | ||
import { TreeExplorerNodeProvider } from 'vscode'; | ||
import { TPromise } from 'vs/base/common/winjs.base'; | ||
import { Disposable } from 'vs/workbench/api/node/extHostTypes'; | ||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; | ||
import { MainContext, ExtHostTreeExplorersShape, MainThreadTreeExplorersShape } from './extHost.protocol'; | ||
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; | ||
|
||
private _extNodeProviders: { [providerId: string]: TreeExplorerNodeProvider<any> }; | ||
private _extNodeMaps: { [providerId: string]: { [id: number]: any } }; | ||
|
||
constructor( | ||
threadService: IThreadService, | ||
private commands: ExtHostCommands | ||
) { | ||
super(); | ||
|
||
this._proxy = threadService.get(MainContext.MainThreadExplorers); | ||
|
||
this._extNodeProviders = Object.create(null); | ||
this._extNodeMaps = Object.create(null); | ||
} | ||
|
||
registerTreeExplorerNodeProvider(providerId: string, provider: TreeExplorerNodeProvider<any>): Disposable { | ||
this._proxy.$registerTreeExplorerNodeProvider(providerId); | ||
this._extNodeProviders[providerId] = provider; | ||
|
||
return new Disposable(() => { | ||
delete this._extNodeProviders[providerId]; | ||
delete this._extNodeProviders[providerId]; | ||
}); | ||
} | ||
|
||
$provideRootNode(providerId: string): TPromise<InternalTreeExplorerNode> { | ||
const provider = this._extNodeProviders[providerId]; | ||
if (!provider) { | ||
const errMessage = localize('treeExplorer.notRegistered', 'No TreeExplorerNodeProvider with id \'{0}\' registered.', providerId); | ||
return TPromise.wrapError(errMessage); | ||
} | ||
|
||
return asWinJsPromise(() => provider.provideRootNode()).then(extRootNode => { | ||
const extNodeMap = Object.create(null); | ||
const internalRootNode = new InternalTreeExplorerNode(extRootNode, provider); | ||
|
||
extNodeMap[internalRootNode.id] = extRootNode; | ||
this._extNodeMaps[providerId] = extNodeMap; | ||
|
||
return internalRootNode; | ||
}, err => { | ||
const errMessage = localize('treeExplorer.failedToProvideRootNode', 'TreeExplorerNodeProvider \'{0}\' failed to provide root node.', providerId); | ||
return TPromise.wrapError(errMessage); | ||
}); | ||
} | ||
|
||
$resolveChildren(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise<InternalTreeExplorerNode[]> { | ||
const provider = this._extNodeProviders[providerId]; | ||
if (!provider) { | ||
const errMessage = localize('treeExplorer.notRegistered', 'No TreeExplorerNodeProvider with id \'{0}\' registered.', providerId); | ||
return TPromise.wrapError(errMessage); | ||
} | ||
|
||
const extNodeMap = this._extNodeMaps[providerId]; | ||
const extNode = extNodeMap[mainThreadNode.id]; | ||
|
||
return asWinJsPromise(() => provider.resolveChildren(extNode)).then(children => { | ||
return children.map(extChild => { | ||
const internalChild = new InternalTreeExplorerNode(extChild, provider); | ||
extNodeMap[internalChild.id] = extChild; | ||
return internalChild; | ||
}); | ||
}, err => { | ||
const errMessage = localize('treeExplorer.failedToResolveChildren', 'TreeExplorerNodeProvider \'{0}\' failed to resolveChildren.', providerId); | ||
return TPromise.wrapError(errMessage); | ||
}); | ||
} | ||
|
||
// 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 extNode = this._extNodeMaps[providerId][mainThreadNode.id]; | ||
|
||
const internalCommand = commandConverter.toInternal({ | ||
title: '', | ||
command: mainThreadNode.clickCommand, | ||
arguments: [extNode] | ||
}); | ||
|
||
return TPromise.wrap(internalCommand); | ||
} | ||
|
||
return TPromise.as(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
import { TPromise } from 'vs/base/common/winjs.base'; | ||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; | ||
import { ExtHostContext, MainThreadTreeExplorersShape, ExtHostTreeExplorersShape } from './extHost.protocol'; | ||
import { ICustomTreeExplorerService } from 'vs/workbench/parts/explorers/browser/customTreeExplorerService'; | ||
import { InternalTreeExplorerNodeContent } 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; | ||
|
||
constructor( | ||
@IThreadService private threadService: IThreadService, | ||
@ICustomTreeExplorerService private treeExplorerService: ICustomTreeExplorerService, | ||
@IMessageService private messageService: IMessageService, | ||
@ICommandService private commandService: ICommandService | ||
) { | ||
super(); | ||
|
||
this._proxy = threadService.get(ExtHostContext.ExtHostExplorers); | ||
} | ||
|
||
$registerTreeExplorerNodeProvider(providerId: string): void { | ||
const onError = err => { this.messageService.show(Severity.Error, err); }; | ||
|
||
this.treeExplorerService.registerTreeExplorerNodeProvider(providerId, { | ||
provideRootNode: (): TPromise<InternalTreeExplorerNodeContent> => { | ||
return this._proxy.$provideRootNode(providerId).then(rootNode => rootNode, onError); | ||
}, | ||
resolveChildren: (node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> => { | ||
return this._proxy.$resolveChildren(providerId, node).then(children => children, onError); | ||
}, | ||
executeCommand: (node: InternalTreeExplorerNodeContent): TPromise<any> => { | ||
return this._proxy.$getInternalCommand(providerId, node).then(command => { | ||
return this.commandService.executeCommand(command.id, ...command.arguments); | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.