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

Commit 6d83eb0

Browse files
authored
Extract open simulator command (#30)
Task: 29809, 29812 PBI: 27370
1 parent 902557f commit 6d83eb0

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

src/extension.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,56 @@ export function activate(context: vscode.ExtensionContext) {
2121

2222
// Add our library path to settings.json for autocomplete functionality
2323
updatePythonExtraPaths();
24-
25-
// Opening the output panel
24+
2625
if (outChannel === undefined) {
2726
outChannel = vscode.window.createOutputChannel(CONSTANTS.NAME);
2827
logToOutputChannel(outChannel, CONSTANTS.INFO.WELCOME_OUTPUT_TAB, true);
2928
}
3029

31-
// Open Simulator on the webview
32-
let openSimulator = vscode.commands.registerCommand(
33-
"pacifica.openSimulator",
34-
() => {
35-
if (currentPanel) {
36-
currentPanel.reveal(vscode.ViewColumn.Two);
37-
} else {
38-
currentPanel = vscode.window.createWebviewPanel(
39-
"adafruitSimulator",
40-
CONSTANTS.LABEL.WEBVIEW_PANEL,
41-
vscode.ViewColumn.Two,
42-
{
43-
// Only allow the webview to access resources in our extension's media directory
44-
localResourceRoots: [
45-
vscode.Uri.file(path.join(context.extensionPath, "out"))
46-
],
47-
enableScripts: true
48-
}
49-
);
50-
51-
currentPanel.webview.html = getWebviewContent(context);
30+
const openWebview = () => {
31+
if (currentPanel) {
32+
currentPanel.reveal(vscode.ViewColumn.Two);
33+
} else {
34+
currentPanel = vscode.window.createWebviewPanel(
35+
"adafruitSimulator",
36+
CONSTANTS.LABEL.WEBVIEW_PANEL,
37+
vscode.ViewColumn.Two,
38+
{
39+
// Only allow the webview to access resources in our extension's media directory
40+
localResourceRoots: [
41+
vscode.Uri.file(path.join(context.extensionPath, "out"))
42+
],
43+
enableScripts: true
44+
}
45+
);
46+
47+
currentPanel.webview.html = getWebviewContent(context);
5248

53-
currentPanel.onDidDispose(
54-
() => {
55-
currentPanel = undefined;
56-
},
57-
undefined,
58-
context.subscriptions
59-
);
60-
}
49+
currentPanel.onDidDispose(
50+
() => {
51+
currentPanel = undefined;
52+
},
53+
undefined,
54+
context.subscriptions
55+
);
6156
}
57+
};
58+
59+
// Open Simulator on the webview
60+
const openSimulator = vscode.commands.registerCommand(
61+
"pacifica.openSimulator",
62+
openWebview
6263
);
6364

64-
let newProject = vscode.commands.registerCommand(
65+
const newProject = vscode.commands.registerCommand(
6566
"pacifica.newProject",
6667
() => {
6768
const fileName = "template.py";
6869
const filePath = __dirname + path.sep + fileName;
6970
const file = fs.readFileSync(filePath, "utf8");
7071

72+
openWebview();
73+
7174
vscode.workspace
7275
.openTextDocument({ content: file, language: "en" })
7376
.then((template: vscode.TextDocument) => {
@@ -83,10 +86,11 @@ export function activate(context: vscode.ExtensionContext) {
8386
const runSimulator = vscode.commands.registerCommand(
8487
"pacifica.runSimulator",
8588
() => {
89+
openWebview();
90+
8691
if (!currentPanel) {
8792
return;
8893
}
89-
9094
console.info(CONSTANTS.INFO.RUNNING_CODE);
9195
const activeTextEditor: vscode.TextEditor | undefined =
9296
vscode.window.activeTextEditor;

0 commit comments

Comments
 (0)