mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Enahance tree api
- API to create a view passing the data provider - Have methods on created API to refresh
This commit is contained in:
@@ -18,7 +18,7 @@ import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { ExtHostDocumentSaveParticipant } from 'vs/workbench/api/node/extHostDocumentSaveParticipant';
|
||||
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
|
||||
import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics';
|
||||
import { ExtHostTreeExplorers } from 'vs/workbench/api/node/extHostTreeExplorers';
|
||||
import { ExtHostTreeView } from 'vs/workbench/api/node/extHostTreeView';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
import { ExtHostQuickOpen } from 'vs/workbench/api/node/extHostQuickOpen';
|
||||
import { ExtHostProgress } from 'vs/workbench/api/node/extHostProgress';
|
||||
@@ -111,7 +111,7 @@ export function createApiFactory(
|
||||
const extHostDocumentSaveParticipant = col.define(ExtHostContext.ExtHostDocumentSaveParticipant).set<ExtHostDocumentSaveParticipant>(new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadWorkspace)));
|
||||
const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set<ExtHostEditors>(new ExtHostEditors(threadService, extHostDocumentsAndEditors));
|
||||
const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set<ExtHostCommands>(new ExtHostCommands(threadService, extHostHeapService));
|
||||
const extHostExplorers = col.define(ExtHostContext.ExtHostExplorers).set<ExtHostTreeExplorers>(new ExtHostTreeExplorers(threadService, extHostCommands));
|
||||
const extHostTreeView = col.define(ExtHostContext.ExtHostTreeView).set<ExtHostTreeView>(new ExtHostTreeView(threadService, extHostCommands));
|
||||
const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set<ExtHostConfiguration>(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), initData.configuration));
|
||||
const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set<ExtHostDiagnostics>(new ExtHostDiagnostics(threadService));
|
||||
const languageFeatures = col.define(ExtHostContext.ExtHostLanguageFeatures).set<ExtHostLanguageFeatures>(new ExtHostLanguageFeatures(threadService, extHostDocuments, extHostCommands, extHostHeapService, extHostDiagnostics));
|
||||
@@ -363,8 +363,8 @@ export function createApiFactory(
|
||||
sampleFunction: proposedApiFunction(extension, () => {
|
||||
return extHostMessageService.showMessage(Severity.Info, 'Hello Proposed Api!', {}, []);
|
||||
}),
|
||||
registerTreeExplorerNodeProvider: proposedApiFunction(extension, (providerId: string, provider: vscode.TreeExplorerNodeProvider<any>) => {
|
||||
return extHostExplorers.registerTreeExplorerNodeProvider(providerId, provider);
|
||||
createTreeView: proposedApiFunction(extension, (providerId: string, provider: vscode.TreeDataProvider<any>): vscode.TreeView<any> => {
|
||||
return extHostTreeView.createTreeView(providerId, provider);
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import { MainThreadDiagnostics } from './mainThreadDiagnostics';
|
||||
import { MainThreadDocuments } from './mainThreadDocuments';
|
||||
import { MainThreadEditors } from './mainThreadEditors';
|
||||
import { MainThreadErrors } from './mainThreadErrors';
|
||||
import { MainThreadTreeExplorers } from './mainThreadTreeExplorers';
|
||||
import { MainThreadTreeView } from './mainThreadTreeView';
|
||||
import { MainThreadLanguageFeatures } from './mainThreadLanguageFeatures';
|
||||
import { MainThreadLanguages } from './mainThreadLanguages';
|
||||
import { MainThreadMessageService } from './mainThreadMessageService';
|
||||
@@ -74,7 +74,7 @@ export class ExtHostContribution implements IWorkbenchContribution {
|
||||
col.define(MainContext.MainThreadDocuments).set(this.instantiationService.createInstance(MainThreadDocuments, documentsAndEditors));
|
||||
col.define(MainContext.MainThreadEditors).set(this.instantiationService.createInstance(MainThreadEditors, documentsAndEditors));
|
||||
col.define(MainContext.MainThreadErrors).set(create(MainThreadErrors));
|
||||
col.define(MainContext.MainThreadExplorers).set(create(MainThreadTreeExplorers));
|
||||
col.define(MainContext.MainThreadExplorers).set(create(MainThreadTreeView));
|
||||
col.define(MainContext.MainThreadLanguageFeatures).set(create(MainThreadLanguageFeatures));
|
||||
col.define(MainContext.MainThreadLanguages).set(create(MainThreadLanguages));
|
||||
col.define(MainContext.MainThreadMessageService).set(create(MainThreadMessageService));
|
||||
|
||||
@@ -36,7 +36,7 @@ import { IPickOpenEntry, IPickOptions } from 'vs/platform/quickOpen/common/quick
|
||||
import { SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { IApplyEditsOptions, IUndoStopOptions, TextEditorRevealType, ITextEditorConfigurationUpdate, IResolvedTextEditorConfiguration, ISelectionChangeEvent } from './mainThreadEditor';
|
||||
|
||||
import { InternalTreeExplorerNodeContent } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import { InternalTreeNodeContent } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import { TaskSet } from 'vs/workbench/parts/tasks/common/tasks';
|
||||
import { IModelChangedEvent } from 'vs/editor/common/model/mirrorModel';
|
||||
import { IPosition } from "vs/editor/common/core/position";
|
||||
@@ -147,14 +147,14 @@ export abstract class MainThreadEditorsShape {
|
||||
$getDiffInformation(id: string): TPromise<editorCommon.ILineChange[]> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadTreeExplorersShape {
|
||||
$registerTreeExplorerNodeProvider(providerId: string): void { throw ni(); }
|
||||
$refresh(providerId: string, node: InternalTreeExplorerNodeContent): void { throw ni(); }
|
||||
export abstract class MainThreadTreeViewShape {
|
||||
$registerTreeDataProvider(providerId: string): void { throw ni(); }
|
||||
$refresh(providerId: string, node: InternalTreeNodeContent): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadTreeShape {
|
||||
$registerTreeExplorerNodeProvider(providerId: string, node: InternalTreeExplorerNodeContent): void { throw ni(); }
|
||||
$refresh(providerId: string, node: InternalTreeExplorerNodeContent): void { throw ni(); }
|
||||
$registerTreeExplorerNodeProvider(providerId: string, node: InternalTreeNodeContent): void { throw ni(); }
|
||||
$refresh(providerId: string, node: InternalTreeNodeContent): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadErrorsShape {
|
||||
@@ -358,15 +358,15 @@ export abstract class ExtHostDocumentsAndEditorsShape {
|
||||
}
|
||||
|
||||
|
||||
export abstract class ExtHostTreeExplorersShape {
|
||||
$provideRootNode(providerId: string): TPromise<InternalTreeExplorerNodeContent> { throw ni(); };
|
||||
$resolveChildren(providerId: string, node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> { throw ni(); }
|
||||
$getInternalCommand(providerId: string, node: InternalTreeExplorerNodeContent): TPromise<modes.Command> { throw ni(); }
|
||||
export abstract class ExtHostTreeViewShape {
|
||||
$provideRootNode(providerId: string): TPromise<InternalTreeNodeContent> { throw ni(); };
|
||||
$resolveChildren(providerId: string, node: InternalTreeNodeContent): TPromise<InternalTreeNodeContent[]> { throw ni(); }
|
||||
$getInternalCommand(providerId: string, node: InternalTreeNodeContent): TPromise<modes.Command> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostTreeShape {
|
||||
$resolveChildren(providerId: string, node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> { throw ni(); }
|
||||
$getInternalCommand(providerId: string, node: InternalTreeExplorerNodeContent): TPromise<modes.Command> { throw ni(); }
|
||||
$resolveChildren(providerId: string, node: InternalTreeNodeContent): TPromise<InternalTreeNodeContent[]> { throw ni(); }
|
||||
$getInternalCommand(providerId: string, node: InternalTreeNodeContent): TPromise<modes.Command> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostExtensionServiceShape {
|
||||
@@ -457,7 +457,7 @@ export const MainContext = {
|
||||
MainThreadDocuments: createMainId<MainThreadDocumentsShape>('MainThreadDocuments', MainThreadDocumentsShape),
|
||||
MainThreadEditors: createMainId<MainThreadEditorsShape>('MainThreadEditors', MainThreadEditorsShape),
|
||||
MainThreadErrors: createMainId<MainThreadErrorsShape>('MainThreadErrors', MainThreadErrorsShape),
|
||||
MainThreadExplorers: createMainId<MainThreadTreeExplorersShape>('MainThreadExplorers', MainThreadTreeExplorersShape),
|
||||
MainThreadExplorers: createMainId<MainThreadTreeViewShape>('MainThreadTreeView', MainThreadTreeViewShape),
|
||||
MainThreadLanguageFeatures: createMainId<MainThreadLanguageFeaturesShape>('MainThreadLanguageFeatures', MainThreadLanguageFeaturesShape),
|
||||
MainThreadLanguages: createMainId<MainThreadLanguagesShape>('MainThreadLanguages', MainThreadLanguagesShape),
|
||||
MainThreadMessageService: createMainId<MainThreadMessageServiceShape>('MainThreadMessageService', MainThreadMessageServiceShape),
|
||||
@@ -482,7 +482,7 @@ export const ExtHostContext = {
|
||||
ExtHostDocuments: createExtId<ExtHostDocumentsShape>('ExtHostDocuments', ExtHostDocumentsShape),
|
||||
ExtHostDocumentSaveParticipant: createExtId<ExtHostDocumentSaveParticipantShape>('ExtHostDocumentSaveParticipant', ExtHostDocumentSaveParticipantShape),
|
||||
ExtHostEditors: createExtId<ExtHostEditorsShape>('ExtHostEditors', ExtHostEditorsShape),
|
||||
ExtHostExplorers: createExtId<ExtHostTreeExplorersShape>('ExtHostExplorers', ExtHostTreeExplorersShape),
|
||||
ExtHostTreeView: createExtId<ExtHostTreeViewShape>('ExtHostTreeView', ExtHostTreeViewShape),
|
||||
ExtHostFileSystemEventService: createExtId<ExtHostFileSystemEventServiceShape>('ExtHostFileSystemEventService', ExtHostFileSystemEventServiceShape),
|
||||
ExtHostHeapService: createExtId<ExtHostHeapServiceShape>('ExtHostHeapMonitor', ExtHostHeapServiceShape),
|
||||
ExtHostLanguageFeatures: createExtId<ExtHostLanguageFeaturesShape>('ExtHostLanguageFeatures', ExtHostLanguageFeaturesShape),
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { TreeNode } from 'vscode';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { defaultGenerator } from 'vs/base/common/idGenerator';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { MainContext, ExtHostTreeShape, MainThreadTreeShape } from './extHost.protocol';
|
||||
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { localize } from 'vs/nls';
|
||||
import { InternalTreeExplorerNode } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
|
||||
class InternalTreeExplorerNodeImpl implements InternalTreeExplorerNode {
|
||||
|
||||
readonly id: string;
|
||||
label: string;
|
||||
hasChildren: boolean;
|
||||
clickCommand: string;
|
||||
|
||||
constructor(node: TreeNode) {
|
||||
this.id = defaultGenerator.nextId();
|
||||
this.label = node.label;
|
||||
this.hasChildren = !!node.getChildren;
|
||||
this.clickCommand = node.command ? node.command.command : null;
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostTree extends ExtHostTreeShape {
|
||||
|
||||
private _proxy: MainThreadTreeShape;
|
||||
|
||||
private _providers: Map<string, Map<string, TreeNode>> = new Map<string, Map<string, TreeNode>>();
|
||||
private _disposables: Map<string, Disposable[]> = new Map<string, Disposable[]>();
|
||||
private _nodeDisposables: Map<string, Disposable[]> = new Map<string, Disposable[]>();
|
||||
|
||||
constructor(
|
||||
threadService: IThreadService,
|
||||
private commands: ExtHostCommands
|
||||
) {
|
||||
super();
|
||||
this._proxy = threadService.get(MainContext.MainThreadTree);
|
||||
}
|
||||
|
||||
registerTree(providerId: string, root: TreeNode): Disposable {
|
||||
this._providers.set(providerId, new Map<string, TreeNode>());
|
||||
this._disposables.set(providerId, []);
|
||||
|
||||
const internalNode = new InternalTreeExplorerNodeImpl(root);
|
||||
this._providers.get(providerId).set(internalNode.id, root);
|
||||
|
||||
const disposable = root.onChange(() => {
|
||||
this._proxy.$refresh(providerId, internalNode);
|
||||
});
|
||||
this._disposables.get(providerId).push(new Disposable(() => disposable.dispose()));
|
||||
|
||||
this._proxy.$registerTreeExplorerNodeProvider(providerId, internalNode);
|
||||
|
||||
return new Disposable(() => {
|
||||
this._providers.delete(providerId);
|
||||
const disposables = this._disposables.get(providerId);
|
||||
if (disposables) {
|
||||
for (const disposable of disposables) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
this._disposables.delete(providerId);
|
||||
});
|
||||
}
|
||||
|
||||
$resolveChildren(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise<InternalTreeExplorerNode[]> {
|
||||
const provider = this._providers.get(providerId);
|
||||
if (!provider) {
|
||||
const errMessage = localize('treeExplorer.notRegistered', 'No TreeExplorerNodeProvider with id \'{0}\' registered.', providerId);
|
||||
return TPromise.wrapError(errMessage);
|
||||
}
|
||||
|
||||
const extNode = provider.get(mainThreadNode.id);
|
||||
const disposables = this._nodeDisposables.get(mainThreadNode.id);
|
||||
if (disposables) {
|
||||
for (const disposable of disposables) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
this._nodeDisposables.set(mainThreadNode.id, []);
|
||||
return asWinJsPromise(() => extNode.getChildren()).then(children => {
|
||||
return children.map(extChild => {
|
||||
const internalChild = new InternalTreeExplorerNodeImpl(extChild);
|
||||
provider.set(internalChild.id, extChild);
|
||||
if (extChild.onChange) {
|
||||
const disposable = extChild.onChange(() => this._proxy.$refresh(providerId, internalChild));
|
||||
this._disposables.get(providerId).push(new Disposable(() => disposable.dispose()));
|
||||
this._nodeDisposables.get(mainThreadNode.id).push(new Disposable(() => disposable.dispose()));
|
||||
}
|
||||
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._providers.get(providerId).get(mainThreadNode.id);
|
||||
|
||||
const internalCommand = commandConverter.toInternal({
|
||||
title: '',
|
||||
command: mainThreadNode.clickCommand,
|
||||
arguments: [extNode]
|
||||
});
|
||||
|
||||
return TPromise.wrap(internalCommand);
|
||||
}
|
||||
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
}*/
|
||||
@@ -5,25 +5,24 @@
|
||||
'use strict';
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { TreeExplorerNodeProvider } from 'vscode';
|
||||
import { TreeView, TreeDataProvider } from 'vscode';
|
||||
import { defaultGenerator } from 'vs/base/common/idGenerator';
|
||||
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 { MainContext, ExtHostTreeViewShape, MainThreadTreeViewShape } from './extHost.protocol';
|
||||
import { InternalTreeNode } 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';
|
||||
|
||||
class InternalTreeExplorerNodeImpl implements InternalTreeExplorerNode {
|
||||
class InternalTreeNodeImpl implements InternalTreeNode {
|
||||
|
||||
readonly id: string;
|
||||
label: string;
|
||||
hasChildren: boolean;
|
||||
clickCommand: string = null;
|
||||
|
||||
constructor(node: any, provider: TreeExplorerNodeProvider<any>) {
|
||||
constructor(node: any, provider: TreeDataProvider<any>) {
|
||||
this.id = defaultGenerator.nextId();
|
||||
this.label = provider.getLabel ? provider.getLabel(node) : node.toString();
|
||||
this.hasChildren = provider.getHasChildren ? provider.getHasChildren(node) : true;
|
||||
@@ -36,12 +35,13 @@ class InternalTreeExplorerNodeImpl implements InternalTreeExplorerNode {
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
private _proxy: MainThreadTreeExplorersShape;
|
||||
export class ExtHostTreeView extends ExtHostTreeViewShape {
|
||||
private _proxy: MainThreadTreeViewShape;
|
||||
|
||||
private _extNodeProviders: { [providerId: string]: TreeExplorerNodeProvider<any> };
|
||||
private _extNodeMaps: { [providerId: string]: { [id: string]: InternalTreeExplorerNode } };
|
||||
private _mainNodesMap: Map<string, Map<any, InternalTreeExplorerNode>>;
|
||||
private _extNodeProviders: { [providerId: string]: TreeDataProvider<any> };
|
||||
private _extViews: Map<string, TreeView<any>> = new Map<string, TreeView<any>>();
|
||||
private _extNodeMaps: { [providerId: string]: { [id: string]: InternalTreeNode } };
|
||||
private _mainNodesMap: Map<string, Map<any, InternalTreeNode>>;
|
||||
private _childrenNodesMap: Map<string, Map<any, any[]>>;
|
||||
|
||||
constructor(
|
||||
@@ -54,36 +54,34 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
|
||||
this._extNodeProviders = Object.create(null);
|
||||
this._extNodeMaps = Object.create(null);
|
||||
this._mainNodesMap = new Map<string, Map<any, InternalTreeExplorerNode>>();
|
||||
this._mainNodesMap = new Map<string, Map<any, InternalTreeNode>>();
|
||||
this._childrenNodesMap = new Map<string, Map<any, any[]>>();
|
||||
}
|
||||
|
||||
registerTreeExplorerNodeProvider(providerId: string, provider: TreeExplorerNodeProvider<any>): Disposable {
|
||||
this._proxy.$registerTreeExplorerNodeProvider(providerId);
|
||||
createTreeView<T>(providerId: string, provider: TreeDataProvider<T>): TreeView<T> {
|
||||
this._proxy.$registerTreeDataProvider(providerId);
|
||||
this._extNodeProviders[providerId] = provider;
|
||||
this._mainNodesMap.set(providerId, new Map<any, InternalTreeExplorerNode>());
|
||||
this._mainNodesMap.set(providerId, new Map<any, InternalTreeNode>());
|
||||
this._childrenNodesMap.set(providerId, new Map<any, any>());
|
||||
|
||||
let disposable = null;
|
||||
if (provider.onChange) {
|
||||
disposable = provider.onChange(node => {
|
||||
const treeView: TreeView<T> = {
|
||||
refresh: (node: T) => {
|
||||
const mainThreadNode = this._mainNodesMap.get(providerId).get(node);
|
||||
this._proxy.$refresh(providerId, mainThreadNode);
|
||||
});
|
||||
}
|
||||
|
||||
return new Disposable(() => {
|
||||
delete this._extNodeProviders[providerId];
|
||||
delete this._extNodeProviders[providerId];
|
||||
this._mainNodesMap.delete(providerId);
|
||||
this._childrenNodesMap.delete(providerId);
|
||||
if (disposable) {
|
||||
disposable.dispose();
|
||||
},
|
||||
dispose: () => {
|
||||
delete this._extNodeProviders[providerId];
|
||||
delete this._extNodeProviders[providerId];
|
||||
this._mainNodesMap.delete(providerId);
|
||||
this._childrenNodesMap.delete(providerId);
|
||||
this._extViews.delete(providerId);
|
||||
}
|
||||
});
|
||||
};
|
||||
this._extViews.set(providerId, treeView);
|
||||
return treeView;
|
||||
}
|
||||
|
||||
$provideRootNode(providerId: string): TPromise<InternalTreeExplorerNode> {
|
||||
$provideRootNode(providerId: string): TPromise<InternalTreeNode> {
|
||||
const provider = this._extNodeProviders[providerId];
|
||||
if (!provider) {
|
||||
const errMessage = localize('treeExplorer.notRegistered', 'No TreeExplorerNodeProvider with id \'{0}\' registered.', providerId);
|
||||
@@ -91,8 +89,8 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
}
|
||||
|
||||
return asWinJsPromise(() => provider.provideRootNode()).then(extRootNode => {
|
||||
const extNodeMap: { [id: string]: InternalTreeExplorerNode } = Object.create(null);
|
||||
const internalRootNode = new InternalTreeExplorerNodeImpl(extRootNode, provider);
|
||||
const extNodeMap: { [id: string]: InternalTreeNode } = Object.create(null);
|
||||
const internalRootNode = new InternalTreeNodeImpl(extRootNode, provider);
|
||||
|
||||
extNodeMap[internalRootNode.id] = extRootNode;
|
||||
this._extNodeMaps[providerId] = extNodeMap;
|
||||
@@ -106,7 +104,7 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
});
|
||||
}
|
||||
|
||||
$resolveChildren(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise<InternalTreeExplorerNode[]> {
|
||||
$resolveChildren(providerId: string, mainThreadNode: InternalTreeNode): TPromise<InternalTreeNode[]> {
|
||||
const provider = this._extNodeProviders[providerId];
|
||||
if (!provider) {
|
||||
const errMessage = localize('treeExplorer.notRegistered', 'No TreeExplorerNodeProvider with id \'{0}\' registered.', providerId);
|
||||
@@ -125,7 +123,7 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
|
||||
return asWinJsPromise(() => provider.resolveChildren(extNode)).then(children => {
|
||||
return children.map(extChild => {
|
||||
const internalChild = new InternalTreeExplorerNodeImpl(extChild, provider);
|
||||
const internalChild = new InternalTreeNodeImpl(extChild, provider);
|
||||
extNodeMap[internalChild.id] = extChild;
|
||||
this._mainNodesMap.get(providerId).set(extChild, internalChild);
|
||||
return internalChild;
|
||||
@@ -134,7 +132,7 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
}
|
||||
|
||||
// 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> {
|
||||
$getInternalCommand(providerId: string, mainThreadNode: InternalTreeNode): TPromise<modes.Command> {
|
||||
const commandConverter = this.commands.converter;
|
||||
|
||||
if (mainThreadNode.clickCommand) {
|
||||
@@ -151,4 +149,4 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape {
|
||||
|
||||
return TPromise.as(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ExtHostContext, MainThreadTreeShape, ExtHostTreeShape } from './extHost.protocol';
|
||||
import { ITreeExplorerService } from 'vs/workbench/parts/explorers/common/treeExplorerService';
|
||||
import { InternalTreeExplorerNodeContent, InternalTreeExplorerNodeProvider } 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 MainThreadTree extends MainThreadTreeShape {
|
||||
private _proxy: ExtHostTreeShape;
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService,
|
||||
@ITreeExplorerService private treeExplorerService: ITreeExplorerService,
|
||||
@IMessageService private messageService: IMessageService,
|
||||
@ICommandService private commandService: ICommandService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._proxy = threadService.get(ExtHostContext.ExtHostTree);
|
||||
}
|
||||
|
||||
$registerTreeExplorerNodeProvider(providerId: string, rootNode: InternalTreeExplorerNodeContent): void {
|
||||
const provider = new TreeExplorerNodeProvider(providerId, rootNode, this._proxy, this.messageService, this.commandService);
|
||||
this.treeExplorerService.registerTreeExplorerNodeProvider(providerId, provider);
|
||||
}
|
||||
|
||||
$refresh(providerId: string, node: InternalTreeExplorerNodeContent): void {
|
||||
(<TreeExplorerNodeProvider>this.treeExplorerService.getProvider(providerId))._onRefresh.fire(node);
|
||||
}
|
||||
}
|
||||
|
||||
class TreeExplorerNodeProvider implements InternalTreeExplorerNodeProvider {
|
||||
|
||||
readonly _onRefresh: Emitter<InternalTreeExplorerNodeContent> = new Emitter<InternalTreeExplorerNodeContent>();
|
||||
readonly onRefresh: Event<InternalTreeExplorerNodeContent> = this._onRefresh.event;
|
||||
|
||||
constructor(public readonly id: string, private rootNode: InternalTreeExplorerNodeContent, private _proxy: ExtHostTreeShape,
|
||||
private messageService: IMessageService,
|
||||
private commandService: ICommandService
|
||||
) {
|
||||
}
|
||||
|
||||
provideRootNode(): TPromise<InternalTreeExplorerNodeContent> {
|
||||
return TPromise.as(this.rootNode);
|
||||
}
|
||||
|
||||
resolveChildren(node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> {
|
||||
return this._proxy.$resolveChildren(this.id, node).then(children => children, err => this.messageService.show(Severity.Error, err));
|
||||
}
|
||||
|
||||
executeCommand(node: InternalTreeExplorerNodeContent): TPromise<any> {
|
||||
return this._proxy.$getInternalCommand(this.id, node).then(command => {
|
||||
return this.commandService.executeCommand(command.id, ...command.arguments);
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -7,14 +7,14 @@
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ExtHostContext, MainThreadTreeExplorersShape, ExtHostTreeExplorersShape } from './extHost.protocol';
|
||||
import { ExtHostContext, MainThreadTreeViewShape, ExtHostTreeViewShape } from './extHost.protocol';
|
||||
import { ITreeExplorerService } from 'vs/workbench/parts/explorers/common/treeExplorerService';
|
||||
import { InternalTreeExplorerNodeContent, InternalTreeExplorerNodeProvider } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel';
|
||||
import { InternalTreeNodeContent, InternalTreeNodeProvider } 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;
|
||||
export class MainThreadTreeView extends MainThreadTreeViewShape {
|
||||
private _proxy: ExtHostTreeViewShape;
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService,
|
||||
@@ -24,39 +24,39 @@ export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape {
|
||||
) {
|
||||
super();
|
||||
|
||||
this._proxy = threadService.get(ExtHostContext.ExtHostExplorers);
|
||||
this._proxy = threadService.get(ExtHostContext.ExtHostTreeView);
|
||||
}
|
||||
|
||||
$registerTreeExplorerNodeProvider(providerId: string): void {
|
||||
$registerTreeDataProvider(providerId: string): void {
|
||||
const provider = new TreeExplorerNodeProvider(providerId, this._proxy, this.messageService, this.commandService);
|
||||
this.treeExplorerService.registerTreeExplorerNodeProvider(providerId, provider);
|
||||
}
|
||||
|
||||
$refresh(providerId: string, node: InternalTreeExplorerNodeContent): void {
|
||||
$refresh(providerId: string, node: InternalTreeNodeContent): void {
|
||||
(<TreeExplorerNodeProvider>this.treeExplorerService.getProvider(providerId))._onRefresh.fire(node);
|
||||
}
|
||||
}
|
||||
|
||||
class TreeExplorerNodeProvider implements InternalTreeExplorerNodeProvider {
|
||||
class TreeExplorerNodeProvider implements InternalTreeNodeProvider {
|
||||
|
||||
readonly _onRefresh: Emitter<InternalTreeExplorerNodeContent> = new Emitter<InternalTreeExplorerNodeContent>();
|
||||
readonly onRefresh: Event<InternalTreeExplorerNodeContent> = this._onRefresh.event;
|
||||
readonly _onRefresh: Emitter<InternalTreeNodeContent> = new Emitter<InternalTreeNodeContent>();
|
||||
readonly onRefresh: Event<InternalTreeNodeContent> = this._onRefresh.event;
|
||||
|
||||
constructor(public readonly id: string, private _proxy: ExtHostTreeExplorersShape,
|
||||
constructor(public readonly id: string, private _proxy: ExtHostTreeViewShape,
|
||||
private messageService: IMessageService,
|
||||
private commandService: ICommandService
|
||||
) {
|
||||
}
|
||||
|
||||
provideRootNode(): TPromise<InternalTreeExplorerNodeContent> {
|
||||
provideRootNode(): TPromise<InternalTreeNodeContent> {
|
||||
return this._proxy.$provideRootNode(this.id).then(rootNode => rootNode, err => this.messageService.show(Severity.Error, err));
|
||||
}
|
||||
|
||||
resolveChildren(node: InternalTreeExplorerNodeContent): TPromise<InternalTreeExplorerNodeContent[]> {
|
||||
resolveChildren(node: InternalTreeNodeContent): TPromise<InternalTreeNodeContent[]> {
|
||||
return this._proxy.$resolveChildren(this.id, node).then(children => children, err => this.messageService.show(Severity.Error, err));
|
||||
}
|
||||
|
||||
executeCommand(node: InternalTreeExplorerNodeContent): TPromise<any> {
|
||||
executeCommand(node: InternalTreeNodeContent): TPromise<any> {
|
||||
return this._proxy.$getInternalCommand(this.id, node).then(command => {
|
||||
return this.commandService.executeCommand(command.id, ...command.arguments);
|
||||
});
|
||||
Reference in New Issue
Block a user