From 437caeb348e379642fb83473ba4b7c496cf83f06 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Wed, 10 Nov 2021 12:46:24 -0300 Subject: [PATCH] Open Save as... dialog when saving sketches for the first time (#579) * Properly recognize temporary sketches in macOS Without this fix, sketches report their URI path as /private/var/xxx whereas `os.tmpdir()` returns /var/xxx. The second path can be turned into the first by resolving symlinks, which gives a canonical path to compare against. * Open Save as... dialog when saving sketches for the first time --- .../src/browser/contributions/save-sketch.ts | 17 +++++++++++++++++ .../src/node/sketches-service-impl.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/arduino-ide-extension/src/browser/contributions/save-sketch.ts b/arduino-ide-extension/src/browser/contributions/save-sketch.ts index 0d95c36b0..a9f578632 100644 --- a/arduino-ide-extension/src/browser/contributions/save-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/save-sketch.ts @@ -2,6 +2,7 @@ import { injectable } from 'inversify'; import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution'; import { ArduinoMenus } from '../menu/arduino-menus'; import { ArduinoToolbar } from '../toolbar/arduino-toolbar'; +import { SaveAsSketch } from './save-as-sketch'; import { SketchContribution, Command, @@ -51,6 +52,22 @@ export class SaveSketch extends SketchContribution { } async saveSketch(): Promise { + const sketch = await this.sketchServiceClient.currentSketch(); + if (!sketch) { + return; + } + const isTemp = await this.sketchService.isTemp(sketch); + if (isTemp) { + return this.commandService.executeCommand( + SaveAsSketch.Commands.SAVE_AS_SKETCH.id, + { + execOnlyIfTemp: false, + openAfterMove: true, + wipeOriginal: true, + } + ); + } + return this.commandService.executeCommand(CommonCommands.SAVE_ALL.id); } } diff --git a/arduino-ide-extension/src/node/sketches-service-impl.ts b/arduino-ide-extension/src/node/sketches-service-impl.ts index 02280050d..f16cc7f91 100644 --- a/arduino-ide-extension/src/node/sketches-service-impl.ts +++ b/arduino-ide-extension/src/node/sketches-service-impl.ts @@ -387,7 +387,7 @@ void loop() { async isTemp(sketch: Sketch): Promise { let sketchPath = FileUri.fsPath(sketch.uri); - let temp = os.tmpdir(); + let temp = await promisify(fs.realpath)(os.tmpdir()); // Note: VS Code URI normalizes the drive letter. `C:` will be converted into `c:`. // https://github.com/Microsoft/vscode/issues/68325#issuecomment-462239992 if (isWindows) {