Skip to content

Commit 16f3f9e

Browse files
committed
Get clipboard content JSON|CSV and convert to PS|C# class
1 parent 4650195 commit 16f3f9e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
},
104104
{
105105
"command": "PowerShell.PowerShellPasteAsClass",
106-
"title": "Pasted from clipboard as PowerShell class",
106+
"title": "Paste from clipboard as PowerShell|C# class",
107107
"category": "PowerShell"
108108
}
109109
],

src/features/PowerShellPasteAsClass.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,37 @@ import * as clipboard from 'copy-paste';
33
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
44
import Window = vscode.window;
55

6+
export namespace ConvertToCSharpClassRequest {
7+
export const type: RequestType<string, any, void> = { get method() { return 'powerShell/convertToCSharpClass'; } };
8+
}
9+
10+
export namespace ConvertToPowerShellClassRequest {
11+
export const type: RequestType<string, any, void> = { get method() { return 'powerShell/convertToPowerShellClass'; } };
12+
}
13+
614
export function registerPowerShellPasteAsClass(client: LanguageClient): void {
715
var disposable = vscode.commands.registerCommand('PowerShell.PowerShellPasteAsClass', () => {
8-
Window.showInformationMessage(clipboard.paste());
16+
let items: vscode.QuickPickItem[] = [];
17+
items.push({ label: 'PowerShell', description: 'Paste from clipboard as a PowerShell class' });
18+
items.push({ label: 'C#', description: 'Paste from clipboard as a C# class' });
19+
20+
vscode.window.showQuickPick(items).then((qpSelection) => {
21+
if (!qpSelection) {
22+
return;
23+
}
24+
25+
var targetRequest = ConvertToPowerShellClassRequest.type;
26+
if(qpSelection.label == 'C#') {
27+
targetRequest = ConvertToCSharpClassRequest.type;
28+
}
29+
30+
client.sendRequest(targetRequest, clipboard.paste()).then((result) => {
31+
var editor = Window.activeTextEditor;
32+
var selection = editor.selection;
33+
editor.edit((editBuilder) => {
34+
editBuilder.insert(new vscode.Position(selection.start.line, 0), result)
35+
});
36+
});
37+
});
938
});
1039
}

0 commit comments

Comments
 (0)