Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit c792acb

Browse files
authored
add change sketch config (#550)
1 parent 1cb9bf8 commit c792acb

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

src/arduinoActivator.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ArduinoActivator {
2929
// TODO: After use the device.json config, should remove the dependency on the ArduinoApp object.
3030
const deviceContext = DeviceContext.getInstance();
3131
await deviceContext.loadContext();
32+
// Show sketch status bar, and allow user to change sketch in config file
33+
deviceContext.showStatusBar();
3234
// Arduino board manager & library manager
3335
arduinoApp.boardManager = new BoardManager(arduinoSettings, arduinoApp);
3436
ArduinoContext.boardManager = arduinoApp.boardManager;

src/common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ export const statusBarPriority = {
3434
BAUD_RATE: 40,
3535
BOARD: 60,
3636
ENDING: 70,
37+
SKETCH: 80,
3738
};

src/deviceContext.ts

+14
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
8484

8585
private _vscodeWatcher: vscode.FileSystemWatcher;
8686

87+
private _sketchStatusBar: vscode.StatusBarItem;
88+
8789
/**
8890
* @constructor
8991
*/
@@ -97,6 +99,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
9799
this._watcher.onDidChange(() => this.loadContext());
98100
this._watcher.onDidDelete(() => this.loadContext());
99101
this._vscodeWatcher.onDidDelete(() => this.loadContext());
102+
this._sketchStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.SKETCH);
103+
this._sketchStatusBar.command = "arduino.setSketchFile";
104+
this._sketchStatusBar.tooltip = "Sketch File";
100105
}
101106
}
102107

@@ -169,6 +174,15 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
169174
});
170175
}
171176

177+
public showStatusBar() {
178+
if (!this._sketch) {
179+
return false;
180+
}
181+
182+
this._sketchStatusBar.text = this._sketch;
183+
this._sketchStatusBar.show();
184+
}
185+
172186
public saveContext() {
173187
if (!ArduinoWorkspace.rootPath) {
174188
return;

src/extension.ts

+21
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,27 @@ export async function activate(context: vscode.ExtensionContext) {
172172
return { board: ArduinoContext.boardManager.currentBoard.name };
173173
});
174174

175+
registerArduinoCommand("arduino.setSketchFile", async () => {
176+
const sketchFileName = deviceContext.sketch;
177+
const newSketchFileName = await vscode.window.showInputBox({
178+
placeHolder: sketchFileName,
179+
validateInput: (value) => {
180+
if (value && /^\w+\.((ino)|(cpp)|c)$/.test(value.trim())) {
181+
return null;
182+
} else {
183+
return "Invalid sketch file name. Should be *.ino/*.cpp/*.c";
184+
}
185+
},
186+
});
187+
188+
if (!newSketchFileName) {
189+
return;
190+
}
191+
192+
deviceContext.sketch = newSketchFileName;
193+
deviceContext.showStatusBar();
194+
});
195+
175196
registerArduinoCommand("arduino.addLibPath", (path) => ArduinoContext.arduinoApp.addLibPath(path));
176197
registerArduinoCommand("arduino.openExample", (path) => ArduinoContext.arduinoApp.openExample(path));
177198
registerArduinoCommand("arduino.loadPackages", async () => await ArduinoContext.boardManager.loadPackages(true));

test/extension.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ suite("Arduino: Extension Tests", () => {
5151
"arduino.showExampleExplorer",
5252
"arduino.loadPackages",
5353
"arduino.installBoard",
54+
"arduino.setSketchFile",
5455
];
5556

5657
const foundArduinoCommands = commands.filter((value) => {

0 commit comments

Comments
 (0)