From d809daa20ae581436d7e80dabbd934e349309a8f Mon Sep 17 00:00:00 2001 From: jbicker Date: Fri, 23 Aug 2019 18:30:13 +0200 Subject: [PATCH] Use sketch folder as workspace Signed-off-by: jbicker --- .../browser/arduino-frontend-contribution.tsx | 37 +++++++++++++------ .../src/browser/sketch-factory.ts | 7 +++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx index 0872fc39..3915f297 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx +++ b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx @@ -133,21 +133,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C @inject(LabelProvider) protected readonly labelProvider: LabelProvider; - + @inject(QuickOpenService) protected readonly quickOpenService: QuickOpenService; + @inject(WorkspaceService) + protected readonly workspaceService: WorkspaceService; + protected boardsToolbarItem: BoardsToolBarItem | null; protected wsSketchCount: number = 0; - constructor(@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) { - this.workspaceService.onWorkspaceChanged(() => { - if (this.workspaceService.workspace) { - this.registerSketchesInMenu(this.menuRegistry); - } - }) - } - @postConstruct() protected async init(): Promise { // 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); updateStatusBar(this.boardsServiceClient.boardsConfig); + + this.registerSketchesInMenu(this.menuRegistry); } registerToolbarItems(registry: TabBarToolbarRegistry): void { @@ -453,7 +450,18 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C } protected async getWorkspaceSketches(): Promise { - 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; } @@ -461,13 +469,18 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C const url = new URL(window.location.href); const currentSketch = url.searchParams.get('sketch'); // 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()) { - this.messageService.info(`The '${this.labelProvider.getLongName(new URI(uri))}' is already opened.`); + const sketchUri = new URI(uri); + if (!!currentSketch && new URI(currentSketch).toString() === sketchUri.toString()) { + this.messageService.info(`The '${this.labelProvider.getLongName(sketchUri)}' is already opened.`); // NOOP. return; } // Preserve the current window if the `sketch` is not in the `searchParams`. url.searchParams.set('sketch', uri); + const hash = await this.fileSystem.getFsPath(sketchUri.toString()); + if (hash) { + url.hash = hash; + } if (!currentSketch) { setTimeout(() => window.location.href = url.toString(), 100); return; diff --git a/arduino-ide-extension/src/browser/sketch-factory.ts b/arduino-ide-extension/src/browser/sketch-factory.ts index efb70981..364c0d6b 100644 --- a/arduino-ide-extension/src/browser/sketch-factory.ts +++ b/arduino-ide-extension/src/browser/sketch-factory.ts @@ -38,7 +38,8 @@ export class SketchFactory { const sketchDir = parent.resolve(sketchName); const sketchFile = sketchDir.resolve(`${sketchName}.ino`); this.fileSystem.createFolder(sketchDir.toString()); - this.fileSystem.createFile(sketchFile.toString(), { content: ` + this.fileSystem.createFile(sketchFile.toString(), { + content: ` void setup() { // put your setup code here, to run once: @@ -51,6 +52,10 @@ void loop() { ` }); const location = new URL(window.location.href); location.searchParams.set('sketch', sketchFile.toString()); + const hash = await this.fileSystem.getFsPath(sketchDir.toString()); + if (hash) { + location.hash = hash; + } this.windowService.openNewWindow(location.toString()); } catch (e) { throw new Error("Cannot create new sketch: " + e);