Skip to content

Commit 1862284

Browse files
Vigilanstestforstephen
authored andcommitted
Support context value of view nodes (#215)
1 parent 034e557 commit 1862284

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/views/containerNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class ContainerNode extends DataNode {
2727
return result;
2828
}
2929

30+
protected get contextValue(): string {
31+
return `container/${this.name}`;
32+
}
33+
3034
protected get iconPath(): { light: string, dark: string } {
3135
return ExplorerNode.resolveIconPath("library");
3236
}

src/views/dataNode.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
import * as _ from "lodash";
45
import { ProviderResult, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
56
import { INodeData } from "../java/nodeData";
67
import { ExplorerNode } from "./explorerNode";
@@ -15,6 +16,7 @@ export abstract class DataNode extends ExplorerNode {
1516
const item = new TreeItem(this._nodeData.name, this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None);
1617
item.iconPath = this.iconPath;
1718
item.command = this.command;
19+
item.contextValue = this.computeContextValue();
1820
return item;
1921
}
2022
}
@@ -31,6 +33,10 @@ export abstract class DataNode extends ExplorerNode {
3133
return this._nodeData.path;
3234
}
3335

36+
public get name() { // return name like `referenced-library`
37+
return _.kebabCase(this._nodeData.name);
38+
}
39+
3440
public async revealPaths(paths: INodeData[]): Promise<DataNode> {
3541
const childNodeData = paths.shift();
3642
const children: ExplorerNode[] = await this.getChildren();
@@ -49,6 +55,17 @@ export abstract class DataNode extends ExplorerNode {
4955
return this.createChildNodeList();
5056
}
5157

58+
protected computeContextValue(): string {
59+
let contextValue = this.contextValue;
60+
if (this.uri) {
61+
contextValue = `${contextValue || ""}+uri`;
62+
}
63+
if (contextValue) {
64+
contextValue = `java:${contextValue}`;
65+
}
66+
return contextValue;
67+
}
68+
5269
protected sort() {
5370
this.nodeData.children.sort((a: INodeData, b: INodeData) => {
5471
if (a.kind === b.kind) {
@@ -63,6 +80,10 @@ export abstract class DataNode extends ExplorerNode {
6380
return true;
6481
}
6582

83+
protected get contextValue(): string {
84+
return undefined;
85+
}
86+
6687
protected abstract get iconPath(): string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon;
6788

6889
protected abstract loadData(): Thenable<any[]>;

src/views/packageRootNode.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { Jdtls } from "../java/jdtls";
55
import { INodeData, NodeKind } from "../java/nodeData";
66
import { IPackageRootNodeData, PackageRootKind } from "../java/packageRootNodeData";
7+
import { ContainerNode } from "./containerNode";
78
import { DataNode } from "./dataNode";
89
import { ExplorerNode } from "./explorerNode";
910
import { FileNode } from "./fileNode";
@@ -41,6 +42,16 @@ export class PackageRootNode extends DataNode {
4142
return result;
4243
}
4344

45+
protected get contextValue(): string {
46+
const data = <IPackageRootNodeData>this.nodeData;
47+
if (data.entryKind === PackageRootKind.K_BINARY) {
48+
const parent = <ContainerNode>this.getParent();
49+
return `jar/${parent.name}`;
50+
} else { // Currently PackageFolder does not use context value
51+
return undefined;
52+
}
53+
}
54+
4455
protected get iconPath(): { light: string; dark: string } {
4556
const data = <IPackageRootNodeData>this.nodeData;
4657
if (data.entryKind === PackageRootKind.K_BINARY) {

0 commit comments

Comments
 (0)