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

Commit

Permalink
Extract open simulator command (#30)
Browse files Browse the repository at this point in the history
Task: 29809, 29812
PBI: 27370
  • Loading branch information
LukeSlev authored Jul 5, 2019
1 parent 902557f commit 6d83eb0
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,56 @@ export function activate(context: vscode.ExtensionContext) {

// Add our library path to settings.json for autocomplete functionality
updatePythonExtraPaths();

// Opening the output panel

if (outChannel === undefined) {
outChannel = vscode.window.createOutputChannel(CONSTANTS.NAME);
logToOutputChannel(outChannel, CONSTANTS.INFO.WELCOME_OUTPUT_TAB, true);
}

// Open Simulator on the webview
let openSimulator = vscode.commands.registerCommand(
"pacifica.openSimulator",
() => {
if (currentPanel) {
currentPanel.reveal(vscode.ViewColumn.Two);
} else {
currentPanel = vscode.window.createWebviewPanel(
"adafruitSimulator",
CONSTANTS.LABEL.WEBVIEW_PANEL,
vscode.ViewColumn.Two,
{
// Only allow the webview to access resources in our extension's media directory
localResourceRoots: [
vscode.Uri.file(path.join(context.extensionPath, "out"))
],
enableScripts: true
}
);

currentPanel.webview.html = getWebviewContent(context);
const openWebview = () => {
if (currentPanel) {
currentPanel.reveal(vscode.ViewColumn.Two);
} else {
currentPanel = vscode.window.createWebviewPanel(
"adafruitSimulator",
CONSTANTS.LABEL.WEBVIEW_PANEL,
vscode.ViewColumn.Two,
{
// Only allow the webview to access resources in our extension's media directory
localResourceRoots: [
vscode.Uri.file(path.join(context.extensionPath, "out"))
],
enableScripts: true
}
);

currentPanel.webview.html = getWebviewContent(context);

currentPanel.onDidDispose(
() => {
currentPanel = undefined;
},
undefined,
context.subscriptions
);
}
currentPanel.onDidDispose(
() => {
currentPanel = undefined;
},
undefined,
context.subscriptions
);
}
};

// Open Simulator on the webview
const openSimulator = vscode.commands.registerCommand(
"pacifica.openSimulator",
openWebview
);

let newProject = vscode.commands.registerCommand(
const newProject = vscode.commands.registerCommand(
"pacifica.newProject",
() => {
const fileName = "template.py";
const filePath = __dirname + path.sep + fileName;
const file = fs.readFileSync(filePath, "utf8");

openWebview();

vscode.workspace
.openTextDocument({ content: file, language: "en" })
.then((template: vscode.TextDocument) => {
Expand All @@ -83,10 +86,11 @@ export function activate(context: vscode.ExtensionContext) {
const runSimulator = vscode.commands.registerCommand(
"pacifica.runSimulator",
() => {
openWebview();

if (!currentPanel) {
return;
}

console.info(CONSTANTS.INFO.RUNNING_CODE);
const activeTextEditor: vscode.TextEditor | undefined =
vscode.window.activeTextEditor;
Expand Down

0 comments on commit 6d83eb0

Please sign in to comment.