forked from microsoft/vscode-cpptools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattachQuickPick.ts
More file actions
71 lines (56 loc) · 2.88 KB
/
Copy pathattachQuickPick.ts
File metadata and controls
71 lines (56 loc) · 2.88 KB
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
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as util from '../common';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
class RefreshButton implements vscode.QuickInputButton {
get iconPath(): { dark: vscode.Uri; light: vscode.Uri } {
const refreshImagePathDark: string = util.getExtensionFilePath("assets/Refresh_inverse.svg");
const refreshImagePathLight: string = util.getExtensionFilePath("assets/Refresh.svg");
return {
dark: vscode.Uri.file(refreshImagePathDark),
light: vscode.Uri.file(refreshImagePathLight)
};
}
get tooltip(): string {
return localize("refresh.process.list.tooltip", "Refresh process list");
}
}
export interface AttachItem extends vscode.QuickPickItem {
id?: string;
}
// We should not await on this function.
export async function showQuickPick(getAttachItems: () => Promise<AttachItem[]>): Promise<string | undefined> {
const processEntries: AttachItem[] = await getAttachItems();
return new Promise<string | undefined>((resolve, reject) => {
const quickPick: vscode.QuickPick<AttachItem> = vscode.window.createQuickPick<AttachItem>();
quickPick.title = localize("attach.to.process", "Attach to process");
quickPick.canSelectMany = false;
quickPick.matchOnDescription = true;
quickPick.matchOnDetail = true;
quickPick.placeholder = localize("select.process.attach", "Select the process to attach to");
quickPick.buttons = [new RefreshButton()];
quickPick.items = processEntries;
const disposables: vscode.Disposable[] = [];
quickPick.onDidTriggerButton(async () => { quickPick.items = await getAttachItems(); }, undefined, disposables);
quickPick.onDidAccept(() => {
if (quickPick.selectedItems.length !== 1) {
reject(new Error(localize("process.not.selected", "Process not selected.")));
}
const selectedId: string | undefined = quickPick.selectedItems[0].id;
disposables.forEach(item => item.dispose());
quickPick.dispose();
resolve(selectedId);
}, undefined, disposables);
quickPick.onDidHide(() => {
disposables.forEach(item => item.dispose());
quickPick.dispose();
reject(new Error(localize("process.not.selected", "Process not selected.")));
}, undefined, disposables);
quickPick.show();
});
}