mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 03:46:33 +00:00
Use sketch folder as workspace
Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
parent
f9641a3d76
commit
d809daa20a
@ -133,21 +133,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
|
|
||||||
@inject(LabelProvider)
|
@inject(LabelProvider)
|
||||||
protected readonly labelProvider: LabelProvider;
|
protected readonly labelProvider: LabelProvider;
|
||||||
|
|
||||||
@inject(QuickOpenService)
|
@inject(QuickOpenService)
|
||||||
protected readonly quickOpenService: QuickOpenService;
|
protected readonly quickOpenService: QuickOpenService;
|
||||||
|
|
||||||
|
@inject(WorkspaceService)
|
||||||
|
protected readonly workspaceService: WorkspaceService;
|
||||||
|
|
||||||
protected boardsToolbarItem: BoardsToolBarItem | null;
|
protected boardsToolbarItem: BoardsToolBarItem | null;
|
||||||
protected wsSketchCount: number = 0;
|
protected wsSketchCount: number = 0;
|
||||||
|
|
||||||
constructor(@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) {
|
|
||||||
this.workspaceService.onWorkspaceChanged(() => {
|
|
||||||
if (this.workspaceService.workspace) {
|
|
||||||
this.registerSketchesInMenu(this.menuRegistry);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
protected async init(): Promise<void> {
|
protected async init(): Promise<void> {
|
||||||
// This is a hack. Otherwise, the backend services won't bind.
|
// This is a hack. Otherwise, the backend services won't bind.
|
||||||
@ -161,6 +156,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
}
|
}
|
||||||
this.boardsServiceClient.onBoardsConfigChanged(updateStatusBar);
|
this.boardsServiceClient.onBoardsConfigChanged(updateStatusBar);
|
||||||
updateStatusBar(this.boardsServiceClient.boardsConfig);
|
updateStatusBar(this.boardsServiceClient.boardsConfig);
|
||||||
|
|
||||||
|
this.registerSketchesInMenu(this.menuRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
||||||
@ -453,7 +450,18 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async getWorkspaceSketches(): Promise<Sketch[]> {
|
protected async getWorkspaceSketches(): Promise<Sketch[]> {
|
||||||
const sketches = this.sketches.getSketches(this.workspaceService.workspace);
|
|
||||||
|
let sketches: Sketch[] = [];
|
||||||
|
const userHome = await this.fileSystem.getCurrentUserHome();
|
||||||
|
console.log('userHome', userHome);
|
||||||
|
if (!!userHome) {
|
||||||
|
// TODO: get this from the backend
|
||||||
|
const result = new URI(userHome.uri).resolve('Arduino-PoC').resolve('Sketches').toString();
|
||||||
|
const stat = await this.fileSystem.getFileStat(result);
|
||||||
|
if (!!stat) {
|
||||||
|
sketches = await this.sketches.getSketches(stat);
|
||||||
|
}
|
||||||
|
}
|
||||||
return sketches;
|
return sketches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,13 +469,18 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const currentSketch = url.searchParams.get('sketch');
|
const currentSketch = url.searchParams.get('sketch');
|
||||||
// Nothing to do if we want to open the same sketch which is already opened.
|
// Nothing to do if we want to open the same sketch which is already opened.
|
||||||
if (!!currentSketch && new URI(currentSketch).toString() === new URI(uri).toString()) {
|
const sketchUri = new URI(uri);
|
||||||
this.messageService.info(`The '${this.labelProvider.getLongName(new URI(uri))}' is already opened.`);
|
if (!!currentSketch && new URI(currentSketch).toString() === sketchUri.toString()) {
|
||||||
|
this.messageService.info(`The '${this.labelProvider.getLongName(sketchUri)}' is already opened.`);
|
||||||
// NOOP.
|
// NOOP.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Preserve the current window if the `sketch` is not in the `searchParams`.
|
// Preserve the current window if the `sketch` is not in the `searchParams`.
|
||||||
url.searchParams.set('sketch', uri);
|
url.searchParams.set('sketch', uri);
|
||||||
|
const hash = await this.fileSystem.getFsPath(sketchUri.toString());
|
||||||
|
if (hash) {
|
||||||
|
url.hash = hash;
|
||||||
|
}
|
||||||
if (!currentSketch) {
|
if (!currentSketch) {
|
||||||
setTimeout(() => window.location.href = url.toString(), 100);
|
setTimeout(() => window.location.href = url.toString(), 100);
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,8 @@ export class SketchFactory {
|
|||||||
const sketchDir = parent.resolve(sketchName);
|
const sketchDir = parent.resolve(sketchName);
|
||||||
const sketchFile = sketchDir.resolve(`${sketchName}.ino`);
|
const sketchFile = sketchDir.resolve(`${sketchName}.ino`);
|
||||||
this.fileSystem.createFolder(sketchDir.toString());
|
this.fileSystem.createFolder(sketchDir.toString());
|
||||||
this.fileSystem.createFile(sketchFile.toString(), { content: `
|
this.fileSystem.createFile(sketchFile.toString(), {
|
||||||
|
content: `
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
|
|
||||||
@ -51,6 +52,10 @@ void loop() {
|
|||||||
` });
|
` });
|
||||||
const location = new URL(window.location.href);
|
const location = new URL(window.location.href);
|
||||||
location.searchParams.set('sketch', sketchFile.toString());
|
location.searchParams.set('sketch', sketchFile.toString());
|
||||||
|
const hash = await this.fileSystem.getFsPath(sketchDir.toString());
|
||||||
|
if (hash) {
|
||||||
|
location.hash = hash;
|
||||||
|
}
|
||||||
this.windowService.openNewWindow(location.toString());
|
this.windowService.openNewWindow(location.toString());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("Cannot create new sketch: " + e);
|
throw new Error("Cannot create new sketch: " + e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user