mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-15 15:26:32 +00:00
Use the parent of the existing sketch if not temp.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
6a35bbfa7e
commit
878395221a
@ -58,7 +58,10 @@ export class SaveAsSketch extends SketchContribution {
|
|||||||
markAsRecentlyOpened,
|
markAsRecentlyOpened,
|
||||||
}: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT
|
}: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
const [sketch, configuration] = await Promise.all([
|
||||||
|
this.sketchServiceClient.currentSketch(),
|
||||||
|
this.configService.getConfiguration(),
|
||||||
|
]);
|
||||||
if (!CurrentSketch.isValid(sketch)) {
|
if (!CurrentSketch.isValid(sketch)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -68,15 +71,23 @@ export class SaveAsSketch extends SketchContribution {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sketchUri = new URI(sketch.uri);
|
||||||
|
const sketchbookDirUri = new URI(configuration.sketchDirUri);
|
||||||
|
// If the sketch is temp, IDE2 proposes the default sketchbook folder URI.
|
||||||
|
// If the sketch is not temp, but not contained in the default sketchbook folder, IDE2 proposes the default location.
|
||||||
|
// Otherwise, it proposes the parent folder of the current sketch.
|
||||||
|
const containerDirUri = isTemp
|
||||||
|
? sketchbookDirUri
|
||||||
|
: !sketchbookDirUri.isEqualOrParent(sketchUri)
|
||||||
|
? sketchbookDirUri
|
||||||
|
: sketchUri.parent;
|
||||||
|
const exists = await this.fileService.exists(
|
||||||
|
containerDirUri.resolve(sketch.name)
|
||||||
|
);
|
||||||
|
|
||||||
// If target does not exist, propose a `directories.user`/${sketch.name} path
|
// If target does not exist, propose a `directories.user`/${sketch.name} path
|
||||||
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
|
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
|
||||||
const sketchDirUri = new URI(
|
const defaultUri = containerDirUri.resolve(
|
||||||
(await this.configService.getConfiguration()).sketchDirUri
|
|
||||||
);
|
|
||||||
const exists = await this.fileService.exists(
|
|
||||||
sketchDirUri.resolve(sketch.name)
|
|
||||||
);
|
|
||||||
const defaultUri = sketchDirUri.resolve(
|
|
||||||
exists
|
exists
|
||||||
? `${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`
|
? `${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`
|
||||||
: sketch.name
|
: sketch.name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user