Skip to content

Commit

Permalink
Open Save as... dialog when saving sketches for the first time (ardui…
Browse files Browse the repository at this point in the history
…no#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
  • Loading branch information
federicobond authored Nov 10, 2021
1 parent 3b04d8d commit 437caeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions arduino-ide-extension/src/browser/contributions/save-sketch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -51,6 +52,22 @@ export class SaveSketch extends SketchContribution {
}

async saveSketch(): Promise<void> {
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion arduino-ide-extension/src/node/sketches-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void loop() {

async isTemp(sketch: Sketch): Promise<boolean> {
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) {
Expand Down

0 comments on commit 437caeb

Please sign in to comment.