forked from LeetCode-OpenSource/vscode-leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuiUtils.ts
80 lines (72 loc) · 2.71 KB
/
uiUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { getLeetCodeEndpoint } from "../commands/plugin";
import { leetCodeChannel } from "../leetCodeChannel";
export namespace DialogOptions {
export const open: vscode.MessageItem = { title: "Open" };
export const yes: vscode.MessageItem = { title: "Yes" };
export const no: vscode.MessageItem = { title: "No", isCloseAffordance: true };
export const never: vscode.MessageItem = { title: "Never" };
export const singUp: vscode.MessageItem = { title: "Sign up" };
}
export async function promptForOpenOutputChannel(message: string, type: DialogType): Promise<void> {
let result: vscode.MessageItem | undefined;
switch (type) {
case DialogType.info:
result = await vscode.window.showInformationMessage(message, DialogOptions.open, DialogOptions.no);
break;
case DialogType.warning:
result = await vscode.window.showWarningMessage(message, DialogOptions.open, DialogOptions.no);
break;
case DialogType.error:
result = await vscode.window.showErrorMessage(message, DialogOptions.open, DialogOptions.no);
break;
default:
break;
}
if (result === DialogOptions.open) {
leetCodeChannel.show();
}
}
export async function promptForSignIn(): Promise<void> {
const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
"Please sign in to LeetCode.",
DialogOptions.yes,
DialogOptions.no,
DialogOptions.singUp,
);
switch (choice) {
case DialogOptions.yes:
await vscode.commands.executeCommand("leetcode.signin");
break;
case DialogOptions.singUp:
if (getLeetCodeEndpoint()) {
openUrl("https://leetcode-cn.com");
} else {
openUrl("https://leetcode.com");
}
break;
default:
break;
}
}
export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined> {
const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined;
const options: vscode.OpenDialogOptions = {
defaultUri,
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
openLabel: "Select",
};
return await vscode.window.showOpenDialog(options);
}
export async function openUrl(url: string): Promise<void> {
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(url));
}
export enum DialogType {
info = "info",
warning = "warning",
error = "error",
}