@@ -6,7 +6,7 @@ import { Progress } from '@theia/core/lib/common/message-service-protocol';
66import { nls } from '@theia/core/lib/common/nls' ;
77import { injectable } from '@theia/core/shared/inversify' ;
88import { CreateUri } from '../create/create-uri' ;
9- import { isConflict } from '../create/typings' ;
9+ import { Create , isConflict } from '../create/typings' ;
1010import { ArduinoMenus } from '../menu/arduino-menus' ;
1111import {
1212 TaskFactoryImpl ,
@@ -15,13 +15,36 @@ import {
1515import { CloudSketchbookTree } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree' ;
1616import { CloudSketchbookTreeModel } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-model' ;
1717import { SketchbookCommands } from '../widgets/sketchbook/sketchbook-commands' ;
18- import { Command , CommandRegistry , Sketch } from './contribution' ;
1918import {
2019 CloudSketchContribution ,
2120 pullingSketch ,
2221 sketchAlreadyExists ,
2322 synchronizingSketchbook ,
2423} 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+ /**
44+ * If `true`, the validation error message will not be visible in the input dialog, but the `OK` button will be disabled. Defaults to `true`.
45+ */
46+ readonly skipShowErrorMessageOnOpen ?: boolean ;
47+ }
2548
2649@injectable ( )
2750export class NewCloudSketch extends CloudSketchContribution {
@@ -43,7 +66,14 @@ export class NewCloudSketch extends CloudSketchContribution {
4366
4467 override registerCommands ( registry : CommandRegistry ) : void {
4568 registry . registerCommand ( NewCloudSketch . Commands . NEW_CLOUD_SKETCH , {
46- execute : ( ) => this . createNewSketch ( true ) ,
69+ execute : ( params : NewCloudSketchParams ) =>
70+ this . createNewSketch (
71+ typeof params ?. skipShowErrorMessageOnOpen === 'boolean'
72+ ? params . skipShowErrorMessageOnOpen
73+ : true ,
74+ params ?. initialValue ,
75+ params ?. callback
76+ ) ,
4777 isEnabled : ( ) => Boolean ( this . createFeatures . session ) ,
4878 isVisible : ( ) => this . createFeatures . enabled ,
4979 } ) ;
@@ -66,7 +96,8 @@ export class NewCloudSketch extends CloudSketchContribution {
6696
6797 private async createNewSketch (
6898 skipShowErrorMessageOnOpen : boolean ,
69- initialValue ?: string | undefined
99+ initialValue ?: string | undefined ,
100+ callback ?: CreateNewCloudSketchCallback
70101 ) : Promise < void > {
71102 const treeModel = await this . treeModel ( ) ;
72103 if ( treeModel ) {
@@ -75,7 +106,8 @@ export class NewCloudSketch extends CloudSketchContribution {
75106 rootNode ,
76107 treeModel ,
77108 skipShowErrorMessageOnOpen ,
78- initialValue
109+ initialValue ,
110+ callback
79111 ) ;
80112 }
81113 }
@@ -84,13 +116,14 @@ export class NewCloudSketch extends CloudSketchContribution {
84116 rootNode : CompositeTreeNode ,
85117 treeModel : CloudSketchbookTreeModel ,
86118 skipShowErrorMessageOnOpen : boolean ,
87- initialValue ?: string | undefined
119+ initialValue ?: string | undefined ,
120+ callback ?: CreateNewCloudSketchCallback
88121 ) : Promise < void > {
89122 const existingNames = rootNode . children
90123 . filter ( CloudSketchbookTree . CloudSketchDirNode . is )
91124 . map ( ( { fileStat } ) => fileStat . name ) ;
92125 const taskFactory = new TaskFactoryImpl ( ( value ) =>
93- this . createNewSketchWithProgress ( treeModel , value )
126+ this . createNewSketchWithProgress ( treeModel , value , callback )
94127 ) ;
95128 try {
96129 const dialog = new WorkspaceInputDialogWithProgress (
@@ -118,15 +151,20 @@ export class NewCloudSketch extends CloudSketchContribution {
118151 } catch ( err ) {
119152 if ( isConflict ( err ) ) {
120153 await treeModel . refresh ( ) ;
121- return this . createNewSketch ( false , taskFactory . value ?? initialValue ) ;
154+ return this . createNewSketch (
155+ false ,
156+ taskFactory . value ?? initialValue ,
157+ callback
158+ ) ;
122159 }
123160 throw err ;
124161 }
125162 }
126163
127164 private createNewSketchWithProgress (
128165 treeModel : CloudSketchbookTreeModel ,
129- value : string
166+ value : string ,
167+ callback ?: CreateNewCloudSketchCallback
130168 ) : (
131169 progress : Progress
132170 ) => Promise < CloudSketchbookTree . CloudSketchDirNode | undefined > {
@@ -143,6 +181,9 @@ export class NewCloudSketch extends CloudSketchContribution {
143181 await treeModel . refresh ( ) ;
144182 progress . report ( { message : pullingSketch ( sketch . name ) } ) ;
145183 const node = await this . pull ( sketch ) ;
184+ if ( callback && node ) {
185+ await callback ( sketch , node , progress ) ;
186+ }
146187 return node ;
147188 } ;
148189 }
@@ -152,7 +193,7 @@ export class NewCloudSketch extends CloudSketchContribution {
152193 ) : Promise < void > {
153194 return this . commandService . executeCommand (
154195 SketchbookCommands . OPEN_NEW_WINDOW . id ,
155- { node }
196+ { node, treeWidgetId : 'cloud-sketchbook-composite-widget' }
156197 ) ;
157198 }
158199}
0 commit comments