Skip to content

Commit 066b767

Browse files
author
Akos Kitta
committed
Use the parent of the existing sketch if not temp.
Signed-off-by: Akos Kitta <[email protected]>
1 parent feb6b89 commit 066b767

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/save-as-sketch.ts

+29-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
KeybindingRegistry,
1212
} from './contribution';
1313
import { nls } from '@theia/core/lib/common';
14-
import { ApplicationShell, NavigatableWidget, Saveable } from '@theia/core/lib/browser';
14+
import {
15+
ApplicationShell,
16+
NavigatableWidget,
17+
Saveable,
18+
} from '@theia/core/lib/browser';
1519
import { WindowService } from '@theia/core/lib/browser/window/window-service';
1620
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
1721
import { WorkspaceInput } from '@theia/workspace/lib/browser';
@@ -58,7 +62,10 @@ export class SaveAsSketch extends SketchContribution {
5862
markAsRecentlyOpened,
5963
}: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT
6064
): Promise<boolean> {
61-
const sketch = await this.sketchServiceClient.currentSketch();
65+
const [sketch, configuration] = await Promise.all([
66+
this.sketchServiceClient.currentSketch(),
67+
this.configService.getConfiguration(),
68+
]);
6269
if (!CurrentSketch.isValid(sketch)) {
6370
return false;
6471
}
@@ -68,15 +75,23 @@ export class SaveAsSketch extends SketchContribution {
6875
return false;
6976
}
7077

71-
// If target does not exist, propose a `directories.user`/${sketch.name} path
72-
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
73-
const sketchDirUri = new URI(
74-
(await this.configService.getConfiguration()).sketchDirUri
75-
);
78+
const sketchUri = new URI(sketch.uri);
79+
const sketchbookDirUri = new URI(configuration.sketchDirUri);
80+
// If the sketch is temp, IDE2 proposes the default sketchbook folder URI.
81+
// If the sketch is not temp, but not contained in the default sketchbook folder, IDE2 proposes the default location.
82+
// Otherwise, it proposes the parent folder of the current sketch.
83+
const containerDirUri = isTemp
84+
? sketchbookDirUri
85+
: !sketchbookDirUri.isEqualOrParent(sketchUri)
86+
? sketchbookDirUri
87+
: sketchUri.parent;
7688
const exists = await this.fileService.exists(
77-
sketchDirUri.resolve(sketch.name)
89+
containerDirUri.resolve(sketch.name)
7890
);
79-
const defaultUri = sketchDirUri.resolve(
91+
92+
// If target does not exist, propose a `directories.user`/${sketch.name} path
93+
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
94+
const defaultUri = containerDirUri.resolve(
8095
exists
8196
? `${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`
8297
: sketch.name
@@ -103,7 +118,11 @@ export class SaveAsSketch extends SketchContribution {
103118
destinationUri,
104119
});
105120
if (workspaceUri) {
106-
await this.saveOntoCopiedSketch(sketch.mainFileUri, sketch.uri, workspaceUri);
121+
await this.saveOntoCopiedSketch(
122+
sketch.mainFileUri,
123+
sketch.uri,
124+
workspaceUri
125+
);
107126
if (markAsRecentlyOpened) {
108127
this.sketchService.markAsRecentlyOpened(workspaceUri);
109128
}

0 commit comments

Comments
 (0)