Skip to content

Commit c358802

Browse files
authored
feat(statusBar): open view on click (#5)
1 parent b06c168 commit c358802

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@
4444
{
4545
"command": "gitguardian.authenticate",
4646
"title": "gitguardian: Authenticate"
47+
},
48+
{
49+
"command": "gitguardian.showOutput",
50+
"title": "Show Output"
51+
},
52+
{
53+
"command": "gitguardian.openSidebar",
54+
"title": "Open Sidebar"
55+
},
56+
{
57+
"command": "gitguardian.openProblems",
58+
"title": "Open Problems"
4759
}
4860
],
4961
"viewsContainers": {

src/extension.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,38 @@ function cleanUpFileDiagnostics(fileUri: Uri): void {
7373
diagnosticCollection.delete(fileUri);
7474
}
7575

76+
function registerOpenViewsCommands(
77+
context: ExtensionContext,
78+
outputChannel: any
79+
) {
80+
const showOutputCommand = commands.registerCommand(
81+
"gitguardian.showOutput",
82+
() => {
83+
outputChannel.show();
84+
}
85+
);
86+
87+
const openSidebarCommand = commands.registerCommand(
88+
"gitguardian.openSidebar",
89+
() => {
90+
commands.executeCommand("workbench.view.extension.gitguardian");
91+
}
92+
);
93+
94+
const openProblemsCommand = commands.registerCommand(
95+
"gitguardian.openProblems",
96+
() => {
97+
commands.executeCommand("workbench.actions.view.problems");
98+
}
99+
);
100+
101+
context.subscriptions.push(
102+
showOutputCommand,
103+
openSidebarCommand,
104+
openProblemsCommand
105+
);
106+
}
107+
76108
export function activate(context: ExtensionContext) {
77109
// Check if ggshield if available
78110
const outputChannel = window.createOutputChannel("GGShield Resolver");
@@ -92,6 +124,9 @@ export function activate(context: ExtensionContext) {
92124

93125
statusBar = window.createStatusBarItem(StatusBarAlignment.Left, 0);
94126
updateStatusBarItem(StatusBarStatus.initialization, statusBar);
127+
128+
//generic commands to open correct view on status bar click
129+
registerOpenViewsCommands(context, outputChannel);
95130
context.subscriptions.push(statusBar);
96131

97132
ggshieldResolver

src/status-bar-utils.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StatusBarItem, ThemeColor } from "vscode";
33
export interface StatusBarConfig {
44
text: string;
55
color: string;
6+
command?: string;
67
}
78

89
export enum StatusBarStatus {
@@ -21,39 +22,40 @@ export function getStatusBarConfig(status: StatusBarStatus): StatusBarConfig {
2122
return {
2223
text: "GitGuardian - Initializing...",
2324
color: "statusBar.foreground",
24-
// TODO: onclick open output channel if the bar is frozen and I want to see what's going on
25+
command: "gitguardian.showOutput",
2526
};
2627
case StatusBarStatus.unauthenticated:
2728
return {
2829
text: "GitGuardian - Please authenticate",
2930
color: "statusBarItem.warningBackground",
30-
// TODO: onclick open sidebar
31+
command: "gitguardian.openSidebar",
3132
};
3233
case StatusBarStatus.ready:
3334
return { text: "GitGuardian is ready", color: "statusBar.foreground" };
3435
case StatusBarStatus.scanning:
3536
return {
3637
text: "GitGuardian - Scanning...",
3738
color: "statusBar.foreground",
38-
// TODO: onclick open output channel if the bar is frozen and I want to see what's going on
39+
command: "gitguardian.showOutput",
3940
};
4041
case StatusBarStatus.secretFound:
4142
return {
4243
text: "GitGuardian - Secret found",
4344
color: "statusBarItem.errorBackground",
45+
command: "gitguardian.openProblems",
4446
// TODO: onclick open problems panel
4547
};
4648
case StatusBarStatus.noSecretFound:
4749
return {
4850
text: "GitGuardian - No secret found",
4951
color: "statusBar.foreground",
50-
// TODO: onclick open sidebar
52+
command: "gitguardian.openSidebar",
5153
};
5254
case StatusBarStatus.error:
5355
return {
5456
text: "GitGuardian - error",
5557
color: "statusBarItem.errorBackground",
56-
// TODO: onclick open output channel panel
58+
command: "gitguardian.showOutput",
5759
};
5860
default:
5961
return { text: "", color: "statusBar.foreground" };
@@ -68,5 +70,12 @@ export function updateStatusBarItem(
6870
statusBarItem.text = config.text;
6971
statusBarItem.backgroundColor = new ThemeColor(config.color);
7072

73+
// If the command is defined, assign it to the status bar item
74+
if (config.command) {
75+
statusBarItem.command = config.command;
76+
} else {
77+
statusBarItem.command = undefined;
78+
}
79+
7180
statusBarItem.show();
7281
}

0 commit comments

Comments
 (0)