Skip to content

Commit 4c107dd

Browse files
committed
WIP: Add ToggleISEMode command
1 parent 2d3a3c2 commit 4c107dd

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"onCommand:PowerShell.OpenExamplesFolder",
4444
"onCommand:PowerShell.EnableISEMode",
4545
"onCommand:PowerShell.DisableISEMode",
46+
"onCommand:PowerShell.ToggleISEMode",
4647
"onView:PowerShellCommands"
4748
],
4849
"dependencies": {
@@ -156,6 +157,11 @@
156157
"title": "Disable ISE Mode (restore to defaults)",
157158
"category": "PowerShell"
158159
},
160+
{
161+
"command": "PowerShell.ToggleISEMode",
162+
"title": "Toggle ISE Mode",
163+
"category": "PowerShell"
164+
},
159165
{
160166
"command": "PowerShell.RefreshCommandsExplorer",
161167
"title": "Refresh Command Explorer",

src/features/ISECompatibility.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,33 @@ export class ISECompatibilityFeature implements vscode.Disposable {
2525
{ path: "editor", name: "wordSeparators", value: "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?" },
2626
{ path: "powershell.buttons", name: "showPanelMovementButtons", value: true }
2727
];
28-
private iseCommandRegistration: vscode.Disposable;
29-
private defaultCommandRegistration: vscode.Disposable;
28+
29+
private enableCommandRegistration: vscode.Disposable;
30+
private disableCommandRegistration: vscode.Disposable;
31+
private toggleCommandRegistration: vscode.Disposable;
32+
private iseToggled: boolean;
3033

3134
constructor() {
32-
this.iseCommandRegistration = vscode.commands.registerCommand(
33-
"PowerShell.EnableISEMode", this.EnableISEMode);
34-
this.defaultCommandRegistration = vscode.commands.registerCommand(
35-
"PowerShell.DisableISEMode", this.DisableISEMode);
35+
// TODO: This test isn't great.
36+
const testSetting = ISECompatibilityFeature.settings[ISECompatibilityFeature.settings.length - 1];
37+
this.iseToggled = vscode.workspace.getConfiguration(testSetting.path).get(testSetting.name) === testSetting.value;
38+
39+
this.enableCommandRegistration = vscode.commands.registerCommand(
40+
"PowerShell.EnableISEMode", () => { this.EnableISEMode(); });
41+
this.disableCommandRegistration = vscode.commands.registerCommand(
42+
"PowerShell.DisableISEMode", () => { this.DisableISEMode(); });
43+
this.toggleCommandRegistration = vscode.commands.registerCommand(
44+
"PowerShell.ToggleISEMode", () => { this.ToggleISEMode(); });
3645
}
3746

3847
public dispose() {
39-
this.iseCommandRegistration.dispose();
40-
this.defaultCommandRegistration.dispose();
48+
this.enableCommandRegistration.dispose();
49+
this.disableCommandRegistration.dispose();
50+
this.toggleCommandRegistration.dispose();
4151
}
4252

4353
private async EnableISEMode() {
54+
this.iseToggled = true;
4455
for (const iseSetting of ISECompatibilityFeature.settings) {
4556
try {
4657
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, iseSetting.value, true);
@@ -63,11 +74,20 @@ export class ISECompatibilityFeature implements vscode.Disposable {
6374
}
6475

6576
private async DisableISEMode() {
77+
this.iseToggled = false;
6678
for (const iseSetting of ISECompatibilityFeature.settings) {
6779
const currently = vscode.workspace.getConfiguration(iseSetting.path).get<string | boolean>(iseSetting.name);
6880
if (currently === iseSetting.value) {
6981
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, undefined, true);
7082
}
7183
}
7284
}
85+
86+
private async ToggleISEMode() {
87+
if (this.iseToggled) {
88+
await this.DisableISEMode();
89+
} else {
90+
await this.EnableISEMode();
91+
}
92+
}
7393
}

0 commit comments

Comments
 (0)