@@ -183,11 +183,11 @@ export class VirtualSource implements SourceProvider {
183183
184184 // get
185185
186- getFolder ( path ?: string ) : VirtualFolder | undefined {
187- if ( path === undefined || path === VirtualSource . rootName ) {
186+ getFolder ( vpath ?: string ) : VirtualFolder | undefined {
187+ if ( vpath === undefined || vpath === VirtualSource . rootName ) {
188188 return this . getRoot ( ) ;
189189 } else {
190- const nameList = path . split ( '/' ) ;
190+ const nameList = vpath . split ( '/' ) ;
191191 let cur_folder : VirtualFolder = {
192192 name : '/' ,
193193 files : [ ] ,
@@ -205,11 +205,11 @@ export class VirtualSource implements SourceProvider {
205205 }
206206 }
207207
208- getFile ( path : string ) : VirtualFile | undefined {
209- const vFolder = this . getFolder ( NodePath . dirname ( path ) ) ;
208+ getFile ( vpath : string ) : VirtualFile | undefined {
209+ const vFolder = this . getFolder ( NodePath . dirname ( vpath ) ) ;
210210 if ( vFolder ) {
211- const fileName = NodePath . basename ( path ) ;
212- const index = vFolder . files . findIndex ( ( file ) => { return NodePath . basename ( file . path ) === fileName ; } ) ;
211+ const fileName = NodePath . basename ( vpath ) ;
212+ const index = vFolder . files . findIndex ( ( file ) => NodePath . basename ( file . path ) == fileName ) ;
213213 if ( index !== - 1 ) {
214214 return vFolder . files [ index ] ;
215215 }
@@ -267,51 +267,48 @@ export class VirtualSource implements SourceProvider {
267267
268268 // set
269269
270- addFile ( folder_path : string , file_path : string ) : VirtualFile | undefined {
271-
272- const folder = this . getFolder ( folder_path ) ;
273- if ( folder === undefined ) { throw new Error ( `not found virtual folder '${ folder_path } '` ) ; }
274-
275- // file is not existed, add it
276- const vFilePath = `${ folder_path } /${ NodePath . basename ( file_path ) } ` ;
277- if ( this . getFile ( vFilePath ) === undefined ) {
278- const vFile : VirtualFile = { path : this . project . toRelativePath ( file_path ) } ;
279- folder . files . push ( vFile ) ;
280- this . emit ( 'dataChanged' , 'folderChanged' ) ;
281- return vFile ;
270+ addFile ( vfolder_path : string , fspath : string ) : VirtualFile | undefined {
271+ const folder = this . getFolder ( vfolder_path ) ;
272+ if ( folder ) {
273+ const vFilePath = `${ vfolder_path } /${ NodePath . basename ( fspath ) } ` ;
274+ if ( this . getFile ( vFilePath ) === undefined ) { // file is not existed, add it
275+ const vFile : VirtualFile = { path : this . project . toRelativePath ( fspath ) } ;
276+ folder . files . push ( vFile ) ;
277+ this . emit ( 'dataChanged' , 'folderChanged' ) ;
278+ return vFile ;
279+ }
282280 }
283281 }
284282
285- addFiles ( folder_path : string , pathList : string [ ] ) : VirtualFile [ ] {
283+ addFiles ( folder_path : string , pathList : string [ ] ) : VirtualFile [ ] | undefined {
286284
287285 const folder = this . getFolder ( folder_path ) ;
288- if ( folder === undefined ) { throw new Error ( `not found virtual folder ' ${ folder_path } '` ) ; }
286+ if ( folder ) {
289287
290- const doneList : VirtualFile [ ] = [ ] ;
288+ const doneList : VirtualFile [ ] = [ ] ;
291289
292- for ( const abspath of pathList ) {
293- const vFilePath = `${ folder_path } /${ NodePath . basename ( abspath ) } ` ;
294- // file is not existed, add it
295- if ( this . getFile ( vFilePath ) === undefined ) {
296- const vFile : VirtualFile = { path : this . project . toRelativePath ( abspath ) } ;
297- folder . files . push ( vFile ) ;
298- doneList . push ( vFile ) ;
290+ for ( const abspath of pathList ) {
291+ const vFilePath = `${ folder_path } /${ NodePath . basename ( abspath ) } ` ;
292+ if ( this . getFile ( vFilePath ) === undefined ) { // file is not existed, add it
293+ const vFile : VirtualFile = { path : this . project . toRelativePath ( abspath ) } ;
294+ folder . files . push ( vFile ) ;
295+ doneList . push ( vFile ) ;
296+ }
299297 }
300- }
301298
302- if ( doneList . length > 0 ) {
303- this . emit ( 'dataChanged' , 'folderChanged' ) ;
304- }
299+ if ( doneList . length > 0 ) {
300+ this . emit ( 'dataChanged' , 'folderChanged' ) ;
301+ }
305302
306- return doneList ;
303+ return doneList ;
304+ }
307305 }
308306
309- removeFile ( path : string ) : VirtualFile | undefined {
310- const basename = NodePath . basename ( path ) ;
311- const vFolder = this . getFolder ( NodePath . dirname ( path ) ) ;
307+ removeFile ( vpath : string ) : VirtualFile | undefined {
308+ const basename = NodePath . basename ( vpath ) ;
309+ const vFolder = this . getFolder ( NodePath . dirname ( vpath ) ) ;
312310 if ( vFolder ) {
313- const index = vFolder . files .
314- findIndex ( ( f ) => { return NodePath . basename ( f . path ) === basename ; } ) ;
311+ const index = vFolder . files . findIndex ( ( f ) => NodePath . basename ( f . path ) == basename ) ;
315312 if ( index !== - 1 ) {
316313 const rmFile = vFolder . files . splice ( index , 1 ) [ 0 ] ;
317314 this . emit ( 'dataChanged' , 'folderChanged' ) ;
@@ -334,6 +331,18 @@ export class VirtualSource implements SourceProvider {
334331 }
335332 }
336333
334+ insertFolder ( parentvPath : string , nFolder : VirtualFolder ) : string | undefined {
335+ const vFolder = this . getFolder ( parentvPath ) ;
336+ if ( vFolder ) {
337+ const index = vFolder . folders . findIndex ( ( f ) => f . name == nFolder . name ) ;
338+ if ( index === - 1 ) {
339+ vFolder . folders . push ( nFolder ) ;
340+ this . emit ( 'dataChanged' , 'folderChanged' ) ;
341+ return `${ parentvPath } /${ nFolder . name } ` ;
342+ }
343+ }
344+ }
345+
337346 removeFolder ( path : string ) : VirtualFolder | undefined {
338347 const name = NodePath . basename ( path ) ;
339348 const vFolder = this . getFolder ( NodePath . dirname ( path ) ) ;
@@ -352,8 +361,8 @@ export class VirtualSource implements SourceProvider {
352361 return this . getFolder ( path ) !== undefined ;
353362 }
354363
355- renameFolder ( path : string , newName : string ) : VirtualFolder | undefined {
356- const vFolder = this . getFolder ( path ) ;
364+ renameFolder ( vpath : string , newName : string ) : VirtualFolder | undefined {
365+ const vFolder = this . getFolder ( vpath ) ;
357366 if ( vFolder ) {
358367 vFolder . name = newName ;
359368 this . emit ( 'dataChanged' , 'folderChanged' ) ;
@@ -639,6 +648,8 @@ class SourceRootList implements SourceProvider {
639648
640649 private updateFolder ( rootFolderInfo : SourceRootInfo , targetFolderList ?: string [ ] ) {
641650
651+ console . log ( `[cl.eide] update source folder: '${ rootFolderInfo . fileWatcher . file . path } ' (${ targetFolderList ?. join ( ',' ) } )` ) ;
652+
642653 const rootFolder = rootFolderInfo . fileWatcher . file ;
643654 const folderStack : File [ ] = [ ] ;
644655
@@ -815,6 +826,10 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
815826 return this . GetConfiguration ( ) . config . name ;
816827 }
817828
829+ public getProjectCurrentTargetName ( ) : string {
830+ return this . getCurrentTarget ( ) ;
831+ }
832+
818833 public getProjectType ( ) : ProjectType {
819834 return this . GetConfiguration ( ) . config . type ;
820835 }
0 commit comments