Skip to content

Support context value of view nodes #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
21 changes: 21 additions & 0 deletions src/views/dataNode.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
}
}
Expand All @@ -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<DataNode> {
const childNodeData = paths.shift();
const children: ExplorerNode[] = await this.getChildren();
Expand All @@ -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) {
Expand All @@ -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<any[]>;
Expand Down
11 changes: 11 additions & 0 deletions src/views/packageRootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -41,6 +42,16 @@ export class PackageRootNode extends DataNode {
return result;
}

protected get contextValue(): string {
const data = <IPackageRootNodeData>this.nodeData;
if (data.entryKind === PackageRootKind.K_BINARY) {
const parent = <ContainerNode>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 = <IPackageRootNodeData>this.nodeData;
if (data.entryKind === PackageRootKind.K_BINARY) {
Expand Down