Skip to content

Commit d12faba

Browse files
authored
Can hide the status bar (LeetCode-OpenSource#230)
1 parent 358bca3 commit d12faba

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
| `leetcode.useWsl` | Specify whether to use WSL or not | `false` |
138138
| `leetcode.endpoint` | Specify the active endpoint. Supported endpoints are: `leetcode`, `leetcode-cn` | `leetcode` |
139139
| `leetcode.outputFolder`| Specify the relative path to save the problem files. Besides using customized path, there are also several reserved words which can be used here: <ul><li>`${tag}`: Categorize the problem according to their tags.<li>`${language}`: Categorize the problem according to their language.</li><li>`${difficulty}`: Categorize the problem according to their difficulty.</li></ul> | N/A |
140+
| `leetcode.enableStatusBar` | Specify whether the LeetCode status bar will be shown or not. | `true` |
140141

141142
## Troubleshooting
142143
When you meet any problem, you can check the [Troubleshooting Page](https://github.com/jdneo/vscode-leetcode/wiki/Troubleshooting) first.

docs/README_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
| `leetcode.useWsl` | 指定是否启用 WSL | `false` |
138138
| `leetcode.endpoint` | 指定使用的终端,可用终端有:`leetcode`, `leetcode-cn` | `leetcode` |
139139
| `leetcode.outputFolder` | 指定保存文件时所用的相对文件夹路径。除了用户自定义路径外,也可以使用保留项,包括:<ul><li>`${tag}`: 根据题目的类别进行分类。<li>`${language}`: 根据题目的语言进行分类。</li><li>`${difficulty}`: 根据题目的难度进行分类。</li></ul> | N/A |
140+
| `leetcode.enableStatusBar` | 指定是否在 VS Code 下方显示插件状态栏。 | `true` |
140141

141142
## 疑难解答
142143
在遇到任何问题时,可以先查看一下[疑难解答](https://github.com/jdneo/vscode-leetcode/wiki/%E7%96%91%E9%9A%BE%E8%A7%A3%E7%AD%94)文档寻求帮助。

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@
287287
"type": "string",
288288
"scope": "application",
289289
"description": "Specify the relative path to save the problem files."
290+
},
291+
"leetcode.enableStatusBar": {
292+
"type": "boolean",
293+
"default": true,
294+
"scope": "application",
295+
"description": "Specify whether the LeetCode status bar will be shown or not."
290296
}
291297
}
292298
}

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { LeetCodeTreeDataProvider } from "./explorer/LeetCodeTreeDataProvider";
1515
import { leetCodeChannel } from "./leetCodeChannel";
1616
import { leetCodeExecutor } from "./leetCodeExecutor";
1717
import { leetCodeManager } from "./leetCodeManager";
18-
import { leetCodeStatusBarItem } from "./leetCodeStatusBarItem";
18+
import { leetCodeStatusBarController } from "./statusbar/leetCodeStatusBarController";
1919
import { leetCodePreviewProvider } from "./webview/leetCodePreviewProvider";
2020
import { leetCodeResultProvider } from "./webview/leetCodeResultProvider";
2121
import { leetCodeSolutionProvider } from "./webview/leetCodeSolutionProvider";
@@ -26,7 +26,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
2626
}
2727

2828
leetCodeManager.on("statusChanged", () => {
29-
leetCodeStatusBarItem.updateStatusBar(leetCodeManager.getStatus(), leetCodeManager.getUser());
29+
leetCodeStatusBarController.updateStatusBar(leetCodeManager.getStatus(), leetCodeManager.getUser());
3030
leetCodeTreeDataProvider.refresh();
3131
});
3232

@@ -36,7 +36,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
3636
leetCodeSolutionProvider.initialize(context);
3737

3838
context.subscriptions.push(
39-
leetCodeStatusBarItem,
39+
leetCodeStatusBarController,
4040
leetCodeChannel,
4141
leetCodePreviewProvider,
4242
leetCodeResultProvider,

src/leetCodeStatusBarItem.ts renamed to src/statusbar/LeetCodeStatusBarItem.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the MIT license.
33

44
import * as vscode from "vscode";
5-
import { UserStatus } from "./shared";
5+
import { UserStatus } from "../shared";
66

7-
class LeetCodeStatusBarItem implements vscode.Disposable {
7+
export class LeetCodeStatusBarItem implements vscode.Disposable {
88
private readonly statusBarItem: vscode.StatusBarItem;
99

1010
constructor() {
@@ -25,9 +25,15 @@ class LeetCodeStatusBarItem implements vscode.Disposable {
2525
}
2626
}
2727

28+
public show(): void {
29+
this.statusBarItem.show();
30+
}
31+
32+
public hide(): void {
33+
this.statusBarItem.hide();
34+
}
35+
2836
public dispose(): void {
2937
this.statusBarItem.dispose();
3038
}
3139
}
32-
33-
export const leetCodeStatusBarItem: LeetCodeStatusBarItem = new LeetCodeStatusBarItem();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) jdneo. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import { ConfigurationChangeEvent, Disposable, workspace, WorkspaceConfiguration } from "vscode";
5+
import { UserStatus } from "../shared";
6+
import { LeetCodeStatusBarItem } from "./LeetCodeStatusBarItem";
7+
8+
class LeetCodeStatusBarController implements Disposable {
9+
private statusBar: LeetCodeStatusBarItem;
10+
private configurationChangeListener: Disposable;
11+
12+
constructor() {
13+
this.statusBar = new LeetCodeStatusBarItem();
14+
this.setStatusBarVisibility();
15+
16+
this.configurationChangeListener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
17+
if (event.affectsConfiguration("leetcode.enableStatusBar")) {
18+
this.setStatusBarVisibility();
19+
}
20+
}, this);
21+
}
22+
23+
public updateStatusBar(status: UserStatus, user?: string): void {
24+
if (this.statusBar) {
25+
this.statusBar.updateStatusBar(status, user);
26+
}
27+
}
28+
29+
public dispose(): void {
30+
this.statusBar.dispose();
31+
this.configurationChangeListener.dispose();
32+
}
33+
34+
private setStatusBarVisibility(): void {
35+
if (this.isStatusBarEnabled()) {
36+
this.statusBar.show();
37+
} else {
38+
this.statusBar.hide();
39+
}
40+
}
41+
42+
private isStatusBarEnabled(): boolean {
43+
const configuration: WorkspaceConfiguration = workspace.getConfiguration();
44+
return configuration.get<boolean>("leetcode.enableStatusBar", false);
45+
}
46+
}
47+
48+
export const leetCodeStatusBarController: LeetCodeStatusBarController = new LeetCodeStatusBarController();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy