@@ -11,7 +11,11 @@ import {
11
11
KeybindingRegistry ,
12
12
} from './contribution' ;
13
13
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' ;
15
19
import { WindowService } from '@theia/core/lib/browser/window/window-service' ;
16
20
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl' ;
17
21
import { WorkspaceInput } from '@theia/workspace/lib/browser' ;
@@ -58,7 +62,10 @@ export class SaveAsSketch extends SketchContribution {
58
62
markAsRecentlyOpened,
59
63
} : SaveAsSketch . Options = SaveAsSketch . Options . DEFAULT
60
64
) : 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
+ ] ) ;
62
69
if ( ! CurrentSketch . isValid ( sketch ) ) {
63
70
return false ;
64
71
}
@@ -68,15 +75,23 @@ export class SaveAsSketch extends SketchContribution {
68
75
return false ;
69
76
}
70
77
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 ;
76
88
const exists = await this . fileService . exists (
77
- sketchDirUri . resolve ( sketch . name )
89
+ containerDirUri . resolve ( sketch . name )
78
90
) ;
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 (
80
95
exists
81
96
? `${ sketch . name } _copy_${ dateFormat ( new Date ( ) , 'yyyymmddHHMMss' ) } `
82
97
: sketch . name
@@ -103,7 +118,11 @@ export class SaveAsSketch extends SketchContribution {
103
118
destinationUri,
104
119
} ) ;
105
120
if ( workspaceUri ) {
106
- await this . saveOntoCopiedSketch ( sketch . mainFileUri , sketch . uri , workspaceUri ) ;
121
+ await this . saveOntoCopiedSketch (
122
+ sketch . mainFileUri ,
123
+ sketch . uri ,
124
+ workspaceUri
125
+ ) ;
107
126
if ( markAsRecentlyOpened ) {
108
127
this . sketchService . markAsRecentlyOpened ( workspaceUri ) ;
109
128
}
0 commit comments