From c2bdd6a853480e213d0ac042ec29e1c21e5bbf87 Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Wed, 28 Sep 2016 11:11:22 -0700 Subject: [PATCH] Refactor and put id as property of TreeContentProvider --- .../actions/browser/menusExtensionPoint.ts | 6 +-- src/vs/vscode.d.ts | 18 +++++++ src/vs/workbench/api/node/extHost.api.impl.ts | 3 ++ .../api/node/extHost.contribution.ts | 2 + src/vs/workbench/api/node/extHost.protocol.ts | 11 ++++ src/vs/workbench/api/node/extHostExplorers.ts | 51 +++++++++++++++++++ .../workbench/api/node/mainThreadDocuments.ts | 1 + .../workbench/api/node/mainThreadExplorers.ts | 22 ++++++++ .../treeExplorerViewlet.contribution.css | 2 +- 9 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 src/vs/workbench/api/node/extHostExplorers.ts create mode 100644 src/vs/workbench/api/node/mainThreadExplorers.ts diff --git a/src/vs/platform/actions/browser/menusExtensionPoint.ts b/src/vs/platform/actions/browser/menusExtensionPoint.ts index 8ffafaec1d0..bb2e096b51b 100644 --- a/src/vs/platform/actions/browser/menusExtensionPoint.ts +++ b/src/vs/platform/actions/browser/menusExtensionPoint.ts @@ -340,9 +340,9 @@ ExtensionsRegistry.registerExtensionPoint('explorer', schema.e Registry.as(ViewletExtensions.Viewlets).registerViewlet(new ViewletDescriptor( 'vs/workbench/parts/explorers/browser/treeExplorerViewlet', 'TreeExplorerViewlet', - 'workbench.view.treeExplorer', // Later change this to make it unique - localize('treeExplorer', 'treeExplorer'), - 'treeExplorer', + 'workbench.view.customViewlet.' + treeContentProviderId, + treeContentProviderId, + treeContentProviderId, 125 )); } diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index e37e0d0f218..9c867df6750 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -1348,6 +1348,22 @@ declare module 'vscode' { provideTextDocumentContent(uri: Uri, token: CancellationToken): string | Thenable; } + export interface TreeContentProvider { + id: string; + provideTreeContent(): ITree; + } + + export interface ITree { + root: ITreeNode; + } + + export interface ITreeNode { + label: string; + isExpanded: boolean; + parent: ITreeNode; + children: ITreeNode[] + } + /** * Represents an item that can be selected from * a list of items. @@ -3803,6 +3819,8 @@ declare module 'vscode' { */ export function registerTextDocumentContentProvider(scheme: string, provider: TextDocumentContentProvider): Disposable; + export function registerTreeContentProvider(provider: TreeContentProvider): Disposable; + /** * An event that is emitted when a [text document](#TextDocument) is opened. */ diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 060ac66a02f..565b3dccdb8 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -12,11 +12,13 @@ import { IThreadService } from 'vs/workbench/services/thread/common/threadServic import * as errors from 'vs/base/common/errors'; import product from 'vs/platform/product'; import pkg from 'vs/platform/package'; + import { ExtHostFileSystemEventService } from 'vs/workbench/api/node/extHostFileSystemEventService'; 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 { ExtHostExplorers } from 'vs/workbench/api/node/extHostExplorers'; import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; import { ExtHostQuickOpen } from 'vs/workbench/api/node/extHostQuickOpen'; import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService'; @@ -64,6 +66,7 @@ export function createApiFactory(threadService: IThreadService, extensionService const extHostDocuments = col.define(ExtHostContext.ExtHostDocuments).set(new ExtHostDocuments(threadService)); const extHostDocumentSaveParticipant = col.define(ExtHostContext.ExtHostDocumentSaveParticipant).set(new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadWorkspace))); const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set(new ExtHostEditors(threadService, extHostDocuments)); + const extHostExplorers = col.define(ExtHostContext.ExtHostExplorers).set(new ExtHostExplorers(threadService)); const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set(new ExtHostCommands(threadService, extHostEditors, extHostHeapService)); const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration))); const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set(new ExtHostDiagnostics(threadService)); diff --git a/src/vs/workbench/api/node/extHost.contribution.ts b/src/vs/workbench/api/node/extHost.contribution.ts index 0c08d17a796..040b1453475 100644 --- a/src/vs/workbench/api/node/extHost.contribution.ts +++ b/src/vs/workbench/api/node/extHost.contribution.ts @@ -20,6 +20,7 @@ import { MainThreadDiagnostics } from './mainThreadDiagnostics'; import { MainThreadDocuments } from './mainThreadDocuments'; import { MainThreadEditors } from './mainThreadEditors'; import { MainThreadErrors } from './mainThreadErrors'; +import { MainThreadExplorers } from './mainThreadExplorers'; import { MainThreadLanguageFeatures } from './mainThreadLanguageFeatures'; import { MainThreadLanguages } from './mainThreadLanguages'; import { MainThreadMessageService } from './mainThreadMessageService'; @@ -70,6 +71,7 @@ export class ExtHostContribution implements IWorkbenchContribution { col.define(MainContext.MainThreadDocuments).set(create(MainThreadDocuments)); col.define(MainContext.MainThreadEditors).set(create(MainThreadEditors)); col.define(MainContext.MainThreadErrors).set(create(MainThreadErrors)); + col.define(MainContext.MainThreadExplorers).set(create(MainThreadExplorers)); col.define(MainContext.MainThreadLanguageFeatures).set(create(MainThreadLanguageFeatures)); col.define(MainContext.MainThreadLanguages).set(create(MainThreadLanguages)); col.define(MainContext.MainThreadMessageService).set(create(MainThreadMessageService)); diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 8813c2da060..1f52b3d8cb5 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -115,6 +115,11 @@ export abstract class MainThreadEditorsShape { $tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], opts: IApplyEditsOptions): TPromise { throw ni(); } } +export abstract class MainThreadExplorersShape { + $registerTreeContentProvider(treeContentProviderId: string): void { throw ni(); } + $unregisterTreeContentProvider(treeContentProviderId: string): void { throw ni(); } +} + export abstract class MainThreadErrorsShape { onUnexpectedExtHostError(err: any): void { throw ni(); } } @@ -257,6 +262,10 @@ export abstract class ExtHostEditorsShape { $acceptTextEditorRemove(id: string): void { throw ni(); } } +export abstract class ExtHostExplorersShape { + $provideTextDocumentContent(treeContentProviderId: string): vscode.ITree { throw ni(); }; +} + export abstract class ExtHostExtensionServiceShape { $localShowMessage(severity: Severity, msg: string): void { throw ni(); } $activateExtension(extensionDescription: IExtensionDescription): TPromise { throw ni(); } @@ -331,6 +340,7 @@ export const MainContext = { MainThreadDocuments: createMainId('MainThreadDocuments', MainThreadDocumentsShape), MainThreadEditors: createMainId('MainThreadEditors', MainThreadEditorsShape), MainThreadErrors: createMainId('MainThreadErrors', MainThreadErrorsShape), + MainThreadExplorers: createMainId('MainThreadExplorers', MainThreadExplorersShape), MainThreadLanguageFeatures: createMainId('MainThreadLanguageFeatures', MainThreadLanguageFeaturesShape), MainThreadLanguages: createMainId('MainThreadLanguages', MainThreadLanguagesShape), MainThreadMessageService: createMainId('MainThreadMessageService', MainThreadMessageServiceShape), @@ -351,6 +361,7 @@ export const ExtHostContext = { ExtHostDocuments: createExtId('ExtHostDocuments', ExtHostDocumentsShape), ExtHostDocumentSaveParticipant: createExtId('ExtHostDocumentSaveParticipant', ExtHostDocumentSaveParticipantShape), ExtHostEditors: createExtId('ExtHostEditors', ExtHostEditorsShape), + ExtHostExplorers: createExtId('ExtHostExplorers',ExtHostExplorersShape), ExtHostFileSystemEventService: createExtId('ExtHostFileSystemEventService', ExtHostFileSystemEventServiceShape), ExtHostHeapService: createExtId('ExtHostHeapMonitor', ExtHostHeapServiceShape), ExtHostLanguageFeatures: createExtId('ExtHostLanguageFeatures', ExtHostLanguageFeaturesShape), diff --git a/src/vs/workbench/api/node/extHostExplorers.ts b/src/vs/workbench/api/node/extHostExplorers.ts new file mode 100644 index 00000000000..7c9cbce1a77 --- /dev/null +++ b/src/vs/workbench/api/node/extHostExplorers.ts @@ -0,0 +1,51 @@ +/*--------------------------------------------------------------------------------------------- + * 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 * as vscode 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, ExtHostExplorersShape, MainThreadExplorersShape} from './extHost.protocol'; + +export class ExtHostExplorers extends ExtHostExplorersShape { + private _proxy: MainThreadExplorersShape; + + private _treeContentProviders: { [treeContentProviderId: string]: vscode.TreeContentProvider; }; + + constructor(threadService: IThreadService) { + super(); + + this._proxy = threadService.get(MainContext.MainThreadExplorers); + + this._treeContentProviders = Object.create(null); + } + + public registerTreeContentProvider(provider: vscode.TreeContentProvider): vscode.Disposable { + const treeContentProviderId = provider.id; + + if (this._treeContentProviders[treeContentProviderId]) { + throw new Error(`TreeContentProvider with id '${provider.id} already registered`); + } + + this._treeContentProviders[treeContentProviderId] = provider; + this._proxy.$registerTreeContentProvider(treeContentProviderId); + + return new Disposable(() => { + if (delete this._treeContentProviders[treeContentProviderId]) { + this._proxy.$unregisterTreeContentProvider(treeContentProviderId); + } + }); + } + + $provideTextDocumentContent(treeContentProviderId: string): vscode.ITree { + const provider = this._treeContentProviders[treeContentProviderId]; + if (!provider) { + throw new Error(`no TreeContentProvider registered with id '${treeContentProviderId}'`); + } + + return provider.provideTreeContent(); + } +} diff --git a/src/vs/workbench/api/node/mainThreadDocuments.ts b/src/vs/workbench/api/node/mainThreadDocuments.ts index b39faff7845..2f5c1ff3583 100644 --- a/src/vs/workbench/api/node/mainThreadDocuments.ts +++ b/src/vs/workbench/api/node/mainThreadDocuments.ts @@ -264,4 +264,5 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { } }, onUnexpectedError); } + } diff --git a/src/vs/workbench/api/node/mainThreadExplorers.ts b/src/vs/workbench/api/node/mainThreadExplorers.ts new file mode 100644 index 00000000000..42f68184b19 --- /dev/null +++ b/src/vs/workbench/api/node/mainThreadExplorers.ts @@ -0,0 +1,22 @@ +import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; +import {ExtHostContext, MainThreadExplorersShape, ExtHostExplorersShape} from './extHost.protocol'; + +export class MainThreadExplorers extends MainThreadExplorersShape { + private _proxy: ExtHostExplorersShape; + + constructor( + @IThreadService threadService: IThreadService + ) { + super(); + + this._proxy = threadService.get(ExtHostContext.ExtHostExplorers); + } + + $registerTreeContentProvider(treeContentProviderId: string): void { + const tree = this._proxy.$provideTextDocumentContent(treeContentProviderId); + } + + $unregisterTreeContentProvider(treeContentProviderId: string): void { + + } +} \ No newline at end of file diff --git a/src/vs/workbench/parts/explorers/browser/media/treeExplorerViewlet.contribution.css b/src/vs/workbench/parts/explorers/browser/media/treeExplorerViewlet.contribution.css index fe7d7722e73..255fb5a7d8b 100644 --- a/src/vs/workbench/parts/explorers/browser/media/treeExplorerViewlet.contribution.css +++ b/src/vs/workbench/parts/explorers/browser/media/treeExplorerViewlet.contribution.css @@ -4,6 +4,6 @@ *--------------------------------------------------------------------------------------------*/ /* Activity Bar */ -.monaco-workbench > .activitybar .monaco-action-bar .action-label.treeExplorer { +.monaco-workbench > .activitybar .monaco-action-bar .action-label.pineTree { background-image: url('files-dark.svg'); } \ No newline at end of file -- GitLab