Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 923c695

Browse files
authored
Merge pull request #484 from PowerShell/rkeithhill/improve-find-ps-module-ui
Find module display quick pick list first.
2 parents 09534d9 + 9feebed commit 923c695

File tree

1 file changed

+61
-29
lines changed

1 file changed

+61
-29
lines changed

‎src/features/PowerShellFindModule.ts‎

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,35 @@ export class FindModuleFeature implements IFeature {
2020

2121
private command: vscode.Disposable;
2222
private languageClient: LanguageClient;
23+
private cancelFindToken: vscode.CancellationTokenSource;
2324

2425
constructor() {
2526
this.command = vscode.commands.registerCommand('PowerShell.PowerShellFindModule', () => {
26-
var items: QuickPickItem[] = [];
27+
// It takes a while to get the list of PowerShell modules, display some UI to let user know
28+
this.cancelFindToken = new vscode.CancellationTokenSource();
29+
vscode.window
30+
.showQuickPick(
31+
["Cancel"],
32+
{ placeHolder: "Please wait, retrieving list of PowerShell modules. This can take some time..." },
33+
this.cancelFindToken.token)
34+
.then(response => { if (response === "Cancel") { this.clearCancelFindToken(); } });
35+
36+
// Cancel the loading prompt after 60 seconds
37+
setTimeout(() => {
38+
if (this.cancelFindToken) {
39+
this.clearCancelFindToken();
40+
41+
vscode.window.showErrorMessage(
42+
"The online source for PowerShell modules is not responding. Cancelling Find/Install PowerShell command.");
43+
}
44+
}, 60000);
2745

28-
vscode.window.setStatusBarMessage(this.getCurrentTime() + " Initializing...");
29-
this.languageClient.sendRequest(FindModuleRequest.type, null).then((modules) => {
30-
for(var item in modules) {
31-
items.push({ label: modules[item].name, description: modules[item].description });
32-
};
33-
34-
vscode.window.setStatusBarMessage("");
35-
Window.showQuickPick(items,{placeHolder: "Results: (" + modules.length + ")"}).then((selection) => {
36-
if (!selection) { return; }
37-
switch (selection.label) {
38-
default :
39-
var moduleName = selection.label;
40-
//vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
41-
this.languageClient.sendRequest(InstallModuleRequest.type, moduleName);
42-
}
43-
});
44-
});
46+
this.pickPowerShellModule().then((moduleName) => {
47+
if (moduleName) {
48+
// vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
49+
this.languageClient.sendRequest(InstallModuleRequest.type, moduleName);
50+
}
51+
});
4552
});
4653
}
4754

@@ -53,18 +60,43 @@ export class FindModuleFeature implements IFeature {
5360
this.command.dispose();
5461
}
5562

56-
private getCurrentTime() {
63+
private pickPowerShellModule(): Thenable<string> {
64+
return this.languageClient.sendRequest(FindModuleRequest.type, null).then((modules) => {
65+
var items: QuickPickItem[] = [];
66+
67+
// We've got the modules info, let's cancel the timeout unless it's already been cancelled
68+
if (this.cancelFindToken) {
69+
this.clearCancelFindToken();
70+
}
71+
else {
72+
// Already timed out, would be weird to dislay modules after we said it timed out.
73+
return Promise.resolve("");
74+
}
5775

58-
var timeNow = new Date();
59-
var hours = timeNow.getHours();
60-
var minutes = timeNow.getMinutes();
61-
var seconds = timeNow.getSeconds();
76+
for (var item in modules) {
77+
items.push({ label: modules[item].name, description: modules[item].description });
78+
};
6279

63-
var timeString = "" + ((hours > 12) ? hours - 12 : hours);
64-
timeString += ((minutes < 10) ? ":0" : ":") + minutes;
65-
timeString += ((seconds < 10) ? ":0" : ":") + seconds;
66-
timeString += (hours >= 12) ? " PM" : " AM";
80+
if (items.length === 0) {
81+
return Promise.reject("No PowerShell modules were found.");
82+
}
6783

68-
return timeString;
84+
let options: vscode.QuickPickOptions = {
85+
placeHolder: "Select a PowerShell module to install",
86+
matchOnDescription: true,
87+
matchOnDetail: true
88+
};
89+
90+
return vscode.window.showQuickPick(items, options).then(item => {
91+
return item ? item.label : "";
92+
});
93+
});
6994
}
70-
}
95+
96+
private clearCancelFindToken() {
97+
if (this.cancelFindToken) {
98+
this.cancelFindToken.dispose();
99+
this.cancelFindToken = undefined;
100+
}
101+
}
102+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /