Skip to content

Add tooltips for sub-category folder #143

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 4 commits into from
Feb 20, 2019
Merged
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
32 changes: 32 additions & 0 deletions src/explorer/LeetCodeTreeDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.

import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import * as list from "../commands/list";
Expand Down Expand Up @@ -46,6 +47,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
const idPrefix: number = Date.now();
return {
label: element.isProblem ? `[${element.id}] ${element.name}` : element.name,
tooltip: this.getSubCategoryTooltip(element),
id: `${idPrefix}.${element.parentName}.${element.id}`,
collapsibleState: element.isProblem ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed,
contextValue: element.isProblem ? "problem" : element.id.toLowerCase(),
Expand Down Expand Up @@ -168,6 +170,36 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
}
}

private getSubCategoryTooltip(element: LeetCodeNode): string {
// return '' unless it is a sub-category node
if (element.isProblem || !this.treeData[element.parentName]) {
return "";
}

const problems: IProblem[] = this.treeData[element.parentName].get(element.id);

let acceptedNum: number = 0;
let failedNum: number = 0;
for (const prob of problems) {
switch (prob.state) {
case ProblemState.AC:
acceptedNum++;
break;
case ProblemState.NotAC:
failedNum++;
break;
default:
break;
}
}

return [
`AC: ${acceptedNum}`,
`Failed: ${failedNum}`,
`Total: ${problems.length}`,
].join(os.EOL);
}

private addProblemToTreeData(problem: IProblem): void {
this.putProblemToMap(this.treeData.Difficulty, problem.difficulty, problem);
for (const tag of problem.tags) {
Expand Down