diff --git a/src/views/containerNode.ts b/src/views/containerNode.ts index 5cc1ffd5..39c43257 100644 --- a/src/views/containerNode.ts +++ b/src/views/containerNode.ts @@ -27,6 +27,10 @@ export class ContainerNode extends DataNode { return result; } + protected get contextValue(): string { + return `container/${this.name}`; + } + protected get iconPath(): { light: string, dark: string } { return ExplorerNode.resolveIconPath("library"); } diff --git a/src/views/dataNode.ts b/src/views/dataNode.ts index d9624eab..93d72c9c 100644 --- a/src/views/dataNode.ts +++ b/src/views/dataNode.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +import * as _ from "lodash"; import { ProviderResult, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode"; import { INodeData } from "../java/nodeData"; import { ExplorerNode } from "./explorerNode"; @@ -15,6 +16,7 @@ export abstract class DataNode extends ExplorerNode { const item = new TreeItem(this._nodeData.name, this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None); item.iconPath = this.iconPath; item.command = this.command; + item.contextValue = this.computeContextValue(); return item; } } @@ -31,6 +33,10 @@ export abstract class DataNode extends ExplorerNode { return this._nodeData.path; } + public get name() { // return name like `referenced-library` + return _.kebabCase(this._nodeData.name); + } + public async revealPaths(paths: INodeData[]): Promise { const childNodeData = paths.shift(); const children: ExplorerNode[] = await this.getChildren(); @@ -49,6 +55,17 @@ export abstract class DataNode extends ExplorerNode { return this.createChildNodeList(); } + protected computeContextValue(): string { + let contextValue = this.contextValue; + if (this.uri) { + contextValue = `${contextValue || ""}+uri`; + } + if (contextValue) { + contextValue = `java:${contextValue}`; + } + return contextValue; + } + protected sort() { this.nodeData.children.sort((a: INodeData, b: INodeData) => { if (a.kind === b.kind) { @@ -63,6 +80,10 @@ export abstract class DataNode extends ExplorerNode { return true; } + protected get contextValue(): string { + return undefined; + } + protected abstract get iconPath(): string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon; protected abstract loadData(): Thenable; diff --git a/src/views/packageRootNode.ts b/src/views/packageRootNode.ts index 0f7e9c2e..72dc2a94 100644 --- a/src/views/packageRootNode.ts +++ b/src/views/packageRootNode.ts @@ -4,6 +4,7 @@ import { Jdtls } from "../java/jdtls"; import { INodeData, NodeKind } from "../java/nodeData"; import { IPackageRootNodeData, PackageRootKind } from "../java/packageRootNodeData"; +import { ContainerNode } from "./containerNode"; import { DataNode } from "./dataNode"; import { ExplorerNode } from "./explorerNode"; import { FileNode } from "./fileNode"; @@ -41,6 +42,16 @@ export class PackageRootNode extends DataNode { return result; } + protected get contextValue(): string { + const data = this.nodeData; + if (data.entryKind === PackageRootKind.K_BINARY) { + const parent = this.getParent(); + return `jar/${parent.name}`; + } else { // Currently PackageFolder does not use context value + return undefined; + } + } + protected get iconPath(): { light: string; dark: string } { const data = this.nodeData; if (data.entryKind === PackageRootKind.K_BINARY) {