|
1 | 1 | import * as vscode from "vscode";
|
2 | 2 | import * as path from "path";
|
3 | 3 | import * as cp from "child_process";
|
| 4 | +import * as fs from "fs"; |
4 | 5 | import { CONSTANTS } from "./constants";
|
5 | 6 |
|
6 | 7 | function loadScript(context: vscode.ExtensionContext, path: string) {
|
@@ -54,8 +55,24 @@ export function activate(context: vscode.ExtensionContext) {
|
54 | 55 | }
|
55 | 56 | );
|
56 | 57 |
|
| 58 | + let newProject = vscode.commands.registerCommand( |
| 59 | + "pacifica.newProject", |
| 60 | + () => { |
| 61 | + const fileName = "template.py"; |
| 62 | + const filePath = __dirname + path.sep + fileName; |
| 63 | + const file = fs.readFileSync(filePath, "utf8"); |
| 64 | + |
| 65 | + vscode.workspace.openTextDocument({content: file, language: "en"}) |
| 66 | + .then((template: vscode.TextDocument) => { |
| 67 | + vscode.window.showTextDocument(template, 1, false); |
| 68 | + }), (error: any) => { |
| 69 | + console.error(`Failed to open a new text document: ${error}`); |
| 70 | + } |
| 71 | + } |
| 72 | + ); |
| 73 | + |
57 | 74 | // Send message to the webview
|
58 |
| - let runSimulator = vscode.commands.registerCommand( |
| 75 | + const runSimulator = vscode.commands.registerCommand( |
59 | 76 | "pacifica.runSimulator",
|
60 | 77 | () => {
|
61 | 78 | if (!currentPanel) {
|
@@ -186,7 +203,7 @@ export function activate(context: vscode.ExtensionContext) {
|
186 | 203 | }
|
187 | 204 | );
|
188 | 205 |
|
189 |
| - context.subscriptions.push(openSimulator, runSimulator); |
| 206 | + context.subscriptions.push(openSimulator, runSimulator, newProject); |
190 | 207 | }
|
191 | 208 |
|
192 | 209 | const updatePythonExtraPaths = () => {
|
|
0 commit comments