@@ -6,7 +6,7 @@ import { Progress } from '@theia/core/lib/common/message-service-protocol';
6
6
import { nls } from '@theia/core/lib/common/nls' ;
7
7
import { injectable } from '@theia/core/shared/inversify' ;
8
8
import { CreateUri } from '../create/create-uri' ;
9
- import { isConflict } from '../create/typings' ;
9
+ import { Create , isConflict } from '../create/typings' ;
10
10
import { ArduinoMenus } from '../menu/arduino-menus' ;
11
11
import {
12
12
TaskFactoryImpl ,
@@ -15,13 +15,32 @@ import {
15
15
import { CloudSketchbookTree } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree' ;
16
16
import { CloudSketchbookTreeModel } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-model' ;
17
17
import { SketchbookCommands } from '../widgets/sketchbook/sketchbook-commands' ;
18
- import { Command , CommandRegistry , Sketch } from './contribution' ;
19
18
import {
20
19
CloudSketchContribution ,
21
20
pullingSketch ,
22
21
sketchAlreadyExists ,
23
22
synchronizingSketchbook ,
24
23
} from './cloud-contribution' ;
24
+ import { Command , CommandRegistry , Sketch } from './contribution' ;
25
+
26
+ export interface CreateNewCloudSketchCallback {
27
+ (
28
+ newSketch : Create . Sketch ,
29
+ newNode : CloudSketchbookTree . CloudSketchDirNode ,
30
+ progress : Progress
31
+ ) : Promise < void > ;
32
+ }
33
+
34
+ export interface NewCloudSketchParams {
35
+ /**
36
+ * Value to populate the dialog `<input>` when it opens.
37
+ */
38
+ readonly initialValue ?: string | undefined ;
39
+ /**
40
+ * Additional callback to call when the new cloud sketch has been created.
41
+ */
42
+ readonly callback ?: CreateNewCloudSketchCallback ;
43
+ }
25
44
26
45
@injectable ( )
27
46
export class NewCloudSketch extends CloudSketchContribution {
@@ -43,7 +62,8 @@ export class NewCloudSketch extends CloudSketchContribution {
43
62
44
63
override registerCommands ( registry : CommandRegistry ) : void {
45
64
registry . registerCommand ( NewCloudSketch . Commands . NEW_CLOUD_SKETCH , {
46
- execute : ( ) => this . createNewSketch ( true ) ,
65
+ execute : ( params : NewCloudSketchParams ) =>
66
+ this . createNewSketch ( true , params . initialValue , params . callback ) ,
47
67
isEnabled : ( ) => Boolean ( this . createFeatures . session ) ,
48
68
isVisible : ( ) => this . createFeatures . enabled ,
49
69
} ) ;
@@ -66,7 +86,8 @@ export class NewCloudSketch extends CloudSketchContribution {
66
86
67
87
private async createNewSketch (
68
88
skipShowErrorMessageOnOpen : boolean ,
69
- initialValue ?: string | undefined
89
+ initialValue ?: string | undefined ,
90
+ callback ?: CreateNewCloudSketchCallback
70
91
) : Promise < void > {
71
92
const treeModel = await this . treeModel ( ) ;
72
93
if ( treeModel ) {
@@ -75,7 +96,8 @@ export class NewCloudSketch extends CloudSketchContribution {
75
96
rootNode ,
76
97
treeModel ,
77
98
skipShowErrorMessageOnOpen ,
78
- initialValue
99
+ initialValue ,
100
+ callback
79
101
) ;
80
102
}
81
103
}
@@ -84,13 +106,14 @@ export class NewCloudSketch extends CloudSketchContribution {
84
106
rootNode : CompositeTreeNode ,
85
107
treeModel : CloudSketchbookTreeModel ,
86
108
skipShowErrorMessageOnOpen : boolean ,
87
- initialValue ?: string | undefined
109
+ initialValue ?: string | undefined ,
110
+ callback ?: CreateNewCloudSketchCallback
88
111
) : Promise < void > {
89
112
const existingNames = rootNode . children
90
113
. filter ( CloudSketchbookTree . CloudSketchDirNode . is )
91
114
. map ( ( { fileStat } ) => fileStat . name ) ;
92
115
const taskFactory = new TaskFactoryImpl ( ( value ) =>
93
- this . createNewSketchWithProgress ( treeModel , value )
116
+ this . createNewSketchWithProgress ( treeModel , value , callback )
94
117
) ;
95
118
try {
96
119
const dialog = new WorkspaceInputDialogWithProgress (
@@ -118,15 +141,20 @@ export class NewCloudSketch extends CloudSketchContribution {
118
141
} catch ( err ) {
119
142
if ( isConflict ( err ) ) {
120
143
await treeModel . refresh ( ) ;
121
- return this . createNewSketch ( false , taskFactory . value ?? initialValue ) ;
144
+ return this . createNewSketch (
145
+ false ,
146
+ taskFactory . value ?? initialValue ,
147
+ callback
148
+ ) ;
122
149
}
123
150
throw err ;
124
151
}
125
152
}
126
153
127
154
private createNewSketchWithProgress (
128
155
treeModel : CloudSketchbookTreeModel ,
129
- value : string
156
+ value : string ,
157
+ callback ?: CreateNewCloudSketchCallback
130
158
) : (
131
159
progress : Progress
132
160
) => Promise < CloudSketchbookTree . CloudSketchDirNode | undefined > {
@@ -143,6 +171,9 @@ export class NewCloudSketch extends CloudSketchContribution {
143
171
await treeModel . refresh ( ) ;
144
172
progress . report ( { message : pullingSketch ( sketch . name ) } ) ;
145
173
const node = await this . pull ( sketch ) ;
174
+ if ( callback && node ) {
175
+ await callback ( sketch , node , progress ) ;
176
+ }
146
177
return node ;
147
178
} ;
148
179
}
0 commit comments