1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
+ import * as _ from "lodash" ;
4
5
import { ProviderResult , ThemeIcon , TreeItem , TreeItemCollapsibleState , Uri } from "vscode" ;
5
6
import { INodeData } from "../java/nodeData" ;
6
7
import { ExplorerNode } from "./explorerNode" ;
@@ -15,6 +16,7 @@ export abstract class DataNode extends ExplorerNode {
15
16
const item = new TreeItem ( this . _nodeData . name , this . hasChildren ( ) ? TreeItemCollapsibleState . Collapsed : TreeItemCollapsibleState . None ) ;
16
17
item . iconPath = this . iconPath ;
17
18
item . command = this . command ;
19
+ item . contextValue = this . computeContextValue ( ) ;
18
20
return item ;
19
21
}
20
22
}
@@ -31,6 +33,10 @@ export abstract class DataNode extends ExplorerNode {
31
33
return this . _nodeData . path ;
32
34
}
33
35
36
+ public get name ( ) { // return name like `referenced-library`
37
+ return _ . kebabCase ( this . _nodeData . name ) ;
38
+ }
39
+
34
40
public async revealPaths ( paths : INodeData [ ] ) : Promise < DataNode > {
35
41
const childNodeData = paths . shift ( ) ;
36
42
const children : ExplorerNode [ ] = await this . getChildren ( ) ;
@@ -49,6 +55,17 @@ export abstract class DataNode extends ExplorerNode {
49
55
return this . createChildNodeList ( ) ;
50
56
}
51
57
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
+
52
69
protected sort ( ) {
53
70
this . nodeData . children . sort ( ( a : INodeData , b : INodeData ) => {
54
71
if ( a . kind === b . kind ) {
@@ -63,6 +80,10 @@ export abstract class DataNode extends ExplorerNode {
63
80
return true ;
64
81
}
65
82
83
+ protected get contextValue ( ) : string {
84
+ return undefined ;
85
+ }
86
+
66
87
protected abstract get iconPath ( ) : string | Uri | { light : string | Uri ; dark : string | Uri } | ThemeIcon ;
67
88
68
89
protected abstract loadData ( ) : Thenable < any [ ] > ;
0 commit comments