@@ -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,28 +62,42 @@ 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 ( ) ;
62
- if ( ! CurrentSketch . isValid ( sketch ) ) {
65
+ const [ currentSketch , configuration ] = await Promise . all ( [
66
+ this . sketchServiceClient . currentSketch ( ) ,
67
+ this . configService . getConfiguration ( ) ,
68
+ ] ) ;
69
+ if ( ! CurrentSketch . isValid ( currentSketch ) ) {
63
70
return false ;
64
71
}
65
72
66
- const isTemp = await this . sketchService . isTemp ( sketch ) ;
73
+ const isTemp = await this . sketchService . isTemp ( currentSketch ) ;
67
74
if ( ! isTemp && ! ! execOnlyIfTemp ) {
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 currentSketchUri = new URI ( currentSketch . 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 ( currentSketchUri )
86
+ ? sketchbookDirUri
87
+ : currentSketchUri . parent ;
76
88
const exists = await this . fileService . exists (
77
- sketchDirUri . resolve ( sketch . name )
89
+ containerDirUri . resolve ( currentSketch . 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
- ? `${ sketch . name } _copy_${ dateFormat ( new Date ( ) , 'yyyymmddHHMMss' ) } `
82
- : sketch . name
96
+ ? `${ currentSketch . name } _copy_${ dateFormat (
97
+ new Date ( ) ,
98
+ 'yyyymmddHHMMss'
99
+ ) } `
100
+ : currentSketch . name
83
101
) ;
84
102
const defaultPath = await this . fileService . fsPath ( defaultUri ) ;
85
103
const { filePath, canceled } = await remote . dialog . showSaveDialog (
@@ -99,11 +117,15 @@ export class SaveAsSketch extends SketchContribution {
99
117
if ( ! destinationUri ) {
100
118
return false ;
101
119
}
102
- const workspaceUri = await this . sketchService . copy ( sketch , {
120
+ const workspaceUri = await this . sketchService . copy ( currentSketch , {
103
121
destinationUri,
104
122
} ) ;
105
123
if ( workspaceUri ) {
106
- await this . saveOntoCopiedSketch ( sketch . mainFileUri , sketch . uri , workspaceUri ) ;
124
+ await this . saveOntoCopiedSketch (
125
+ currentSketch . mainFileUri ,
126
+ currentSketch . uri ,
127
+ workspaceUri
128
+ ) ;
107
129
if ( markAsRecentlyOpened ) {
108
130
this . sketchService . markAsRecentlyOpened ( workspaceUri ) ;
109
131
}
@@ -117,7 +139,7 @@ export class SaveAsSketch extends SketchContribution {
117
139
if ( wipeOriginal || ( openAfterMove && execOnlyIfTemp ) ) {
118
140
options . tasks . push ( {
119
141
command : DeleteSketch . Commands . DELETE_SKETCH . id ,
120
- args : [ sketch . uri ] ,
142
+ args : [ currentSketch . uri ] ,
121
143
} ) ;
122
144
}
123
145
this . workspaceService . open ( new URI ( workspaceUri ) , options ) ;
0 commit comments