forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISECompatibility.ts
63 lines (55 loc) · 2.64 KB
/
ISECompatibility.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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as vscode from "vscode";
import * as Settings from "../settings";
interface ISetting {
path: string;
name: string;
value: string | boolean;
}
/**
* A feature to implement commands to make code like the ISE and reset the settings.
*/
export class ISECompatibilityFeature implements vscode.Disposable {
// Marking settings as public so we can use it within the tests without needing to duplicate the list of settings.
public static settings: ISetting[] = [
{ path: "workbench.activityBar", name: "visible", value: false },
{ path: "debug", name: "openDebug", value: "neverOpen" },
{ path: "editor", name: "tabCompletion", value: "on" },
{ path: "powershell.integratedConsole", name: "focusConsoleOnExecute", value: false },
{ path: "files", name: "defaultLanguage", value: "powershell" },
{ path: "workbench", name: "colorTheme", value: "PowerShell ISE" },
];
private iseCommandRegistration: vscode.Disposable;
private defaultCommandRegistration: vscode.Disposable;
constructor() {
this.iseCommandRegistration = vscode.commands.registerCommand(
"PowerShell.EnableISEMode", this.EnableISEMode);
this.defaultCommandRegistration = vscode.commands.registerCommand(
"PowerShell.DisableISEMode", this.DisableISEMode);
}
public dispose() {
this.iseCommandRegistration.dispose();
this.defaultCommandRegistration.dispose();
}
private async EnableISEMode() {
for (const iseSetting of ISECompatibilityFeature.settings) {
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, iseSetting.value, true);
}
// Show the PowerShell Command Explorer
await vscode.commands.executeCommand("workbench.view.extension.PowerShellCommandExplorer");
if (!Settings.load().sideBar.CommandExplorerVisibility) {
// Hide the explorer if the setting says so.
await vscode.commands.executeCommand("workbench.action.toggleSidebarVisibility");
}
}
private async DisableISEMode() {
for (const iseSetting of ISECompatibilityFeature.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get<string | boolean>(iseSetting.name);
if (currently === iseSetting.value) {
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, undefined, true);
}
}
}
}