Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 48daf24

Browse files
New command for starting a new project (#26)
PBI: 29090 Task: 29812, 29121 * Basic functionality of template file working * Update template file content * Small refactoring * Address PR concerns. * Update localization for commands
1 parent 377bc3e commit 48daf24

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@
2424
},
2525
"activationEvents": [
2626
"onCommand:pacifica.openSimulator",
27-
"onCommand:pacifica.runSimulator"
27+
"onCommand:pacifica.runSimulator",
28+
"onCommand:pacifica.newProject"
2829
],
2930
"main": "./out/extension.js",
3031
"contributes": {
3132
"commands": [
3233
{
3334
"command": "pacifica.openSimulator",
34-
"title": "Open Simulator",
35+
"title": "%pacificaExtension.commands.openSimulator%",
3536
"category": "%pacificaExtension.commands.label%"
3637
},
3738
{
3839
"command": "pacifica.runSimulator",
39-
"title": "Run the Simulator",
40+
"title": "%pacificaExtension.commands.runSimulator%",
41+
"category": "%pacificaExtension.commands.label%"
42+
},
43+
{
44+
"command": "pacifica.newProject",
45+
"title": "%pacificaExtension.commands.newProject%",
4046
"category": "%pacificaExtension.commands.label%"
4147
}
4248
]

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"pacificaExtension.commands.label": "Adafruit",
33
"pacificaExtension.commands.openSimulator": "Open Simulator",
4-
"pacificaExtension.commands.runSimulator": "Run Simulator"
4+
"pacificaExtension.commands.runSimulator": "Run Simulator",
5+
"pacificaExtension.commands.newProject": "New Project"
56
}

src/extension.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import * as path from "path";
33
import * as cp from "child_process";
4+
import * as fs from "fs";
45
import { CONSTANTS } from "./constants";
56

67
function loadScript(context: vscode.ExtensionContext, path: string) {
@@ -54,8 +55,24 @@ export function activate(context: vscode.ExtensionContext) {
5455
}
5556
);
5657

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+
5774
// Send message to the webview
58-
let runSimulator = vscode.commands.registerCommand(
75+
const runSimulator = vscode.commands.registerCommand(
5976
"pacifica.runSimulator",
6077
() => {
6178
if (!currentPanel) {
@@ -186,7 +203,7 @@ export function activate(context: vscode.ExtensionContext) {
186203
}
187204
);
188205

189-
context.subscriptions.push(openSimulator, runSimulator);
206+
context.subscriptions.push(openSimulator, runSimulator, newProject);
190207
}
191208

192209
const updatePythonExtraPaths = () => {

src/template.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
Save your file as "code.py" or "main.py" to run on the actual device
3+
4+
Getting started with CPX and CircuitPython intro on: https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library
5+
6+
Find example code for CPX on: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples
7+
'''
8+
9+
# import CPX library
10+
from adafruit_circuitplayground.express import cpx
11+
12+
while True:
13+
# start your code here
14+
pass

0 commit comments

Comments
 (0)