@@ -154,7 +154,7 @@ export class TreeView implements ITreeInterface {
154
154
1 ,
155
155
{
156
156
...node ,
157
- ...extra
157
+ ...extra ,
158
158
}
159
159
) ;
160
160
this . updateChildren ( parentIndex [ this . childNodeName ] ) ;
@@ -164,14 +164,12 @@ export class TreeView implements ITreeInterface {
164
164
165
165
updateChildren ( children : IIndex ) {
166
166
const self = this ;
167
- children . forEach (
168
- function ( id , i ) {
169
- const index = self . getIndex ( id ) ;
170
- index . prev = index . next = null ;
171
- if ( i > 0 ) index . prev = children [ i - 1 ] ;
172
- if ( i < children . length - 1 ) index . next = children [ i + 1 ] ;
173
- }
174
- ) ;
167
+ children . forEach ( function ( id , i ) {
168
+ const index = self . getIndex ( id ) ;
169
+ index . prev = index . next = null ;
170
+ if ( i > 0 ) index . prev = children [ i - 1 ] ;
171
+ if ( i < children . length - 1 ) index . next = children [ i + 1 ] ;
172
+ } ) ;
175
173
}
176
174
177
175
insert ( obj : ITreeNodeItem , parentId : number , i : number ) {
@@ -222,7 +220,6 @@ export class TreeView implements ITreeInterface {
222
220
}
223
221
}
224
222
225
-
226
223
export interface IExplorerService extends Component < IExplorer > {
227
224
addPanel ( panel : IPanelItem | IPanelItem [ ] ) : void ;
228
225
reset ( ) : void ;
@@ -275,13 +272,16 @@ export class ExplorerService
275
272
next . splice ( index , 1 ) ;
276
273
}
277
274
this . setState ( {
278
- data : next
275
+ data : next ,
279
276
} ) ;
280
277
}
281
278
282
279
/* ============================Tree============================ */
283
280
284
- private getFileIconByExtensionName ( name : string , fileType : FileType ) : string {
281
+ private getFileIconByExtensionName (
282
+ name : string ,
283
+ fileType : FileType
284
+ ) : string {
285
285
if ( fileType === FileTypes . FOLDER ) return '' ;
286
286
const fileExtension = name && name . split ( '.' ) ?. [ 1 ] ;
287
287
let icon = 'symbol-file' ;
@@ -310,15 +310,19 @@ export class ExplorerService
310
310
311
311
private getCurrentRootFolderAndIndex ( id : number ) {
312
312
const currentRootFolder : ITreeNodeItem = this . getRootFolderById ( id ) ;
313
- const index = this . getRootFolderIndexByRootId ( ( currentRootFolder as any ) . id ) as number ;
313
+ const index = this . getRootFolderIndexByRootId (
314
+ ( currentRootFolder as any ) . id
315
+ ) as number ;
314
316
return {
315
317
index,
316
- currentRootFolder
317
- }
318
+ currentRootFolder,
319
+ } ;
318
320
}
319
321
320
322
public getRootFolderIndexByRootId ( id : number ) : number | undefined {
321
- return this . state . folderTree ?. data ! . findIndex ( ( folder ) => folder . id === id ) ;
323
+ return this . state . folderTree ?. data ! . findIndex (
324
+ ( folder ) => folder . id === id
325
+ ) ;
322
326
}
323
327
324
328
public getRootFolderByRootId ( id : number ) : ITreeNodeItem | undefined {
@@ -327,12 +331,12 @@ export class ExplorerService
327
331
328
332
public getRootFolderById ( id : number ) : ITreeNodeItem {
329
333
let rootNode = { } ;
330
- this . state . folderTree ?. data ?. forEach ( folder => {
334
+ this . state . folderTree ?. data ?. forEach ( ( folder ) => {
331
335
const treeInstance = new TreeView ( folder ) ;
332
336
if ( treeInstance . get ( id ) ) {
333
337
rootNode = folder ;
334
338
}
335
- } )
339
+ } ) ;
336
340
return rootNode ;
337
341
}
338
342
@@ -345,7 +349,7 @@ export class ExplorerService
345
349
next ?. push ( folder ) ;
346
350
}
347
351
this . setState ( {
348
- folderTree : { ...folderTree , data : next }
352
+ folderTree : { ...folderTree , data : next } ,
349
353
} ) ;
350
354
}
351
355
@@ -357,95 +361,111 @@ export class ExplorerService
357
361
next . splice ( index , 1 ) ;
358
362
}
359
363
this . setState ( {
360
- folderTree : { ...folderTree , data : next }
364
+ folderTree : { ...folderTree , data : next } ,
361
365
} ) ;
362
366
}
363
367
364
368
public updateFile ( file , callback ) {
365
369
const { folderTree } = this . state ;
366
370
const { id, name, fileType } = file ;
367
371
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
368
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( id )
372
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
373
+ id
374
+ ) ;
369
375
const tree = new TreeView ( currentRootFolder ) ;
370
376
if ( name ) {
371
377
tree . update ( id , {
372
378
...file ,
373
379
icon : this . getFileIconByExtensionName ( name , fileType ) ,
374
- modify : false
375
- } )
380
+ modify : false ,
381
+ } ) ;
376
382
} else {
377
- tree . remove ( id )
383
+ tree . remove ( id ) ;
378
384
}
379
385
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
380
386
this . setState ( {
381
- folderTree : { ...folderTree , data : cloneData }
387
+ folderTree : { ...folderTree , data : cloneData } ,
382
388
} ) ;
383
389
if ( callback ) callback ( ) ;
384
390
}
385
391
386
392
public rename ( id : number , callback ?: Function ) {
387
393
const { folderTree } = this . state ;
388
394
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
389
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( id )
395
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
396
+ id
397
+ ) ;
390
398
const tree = new TreeView ( currentRootFolder ) ;
391
399
tree . update ( id , {
392
- modify : true
393
- } )
400
+ modify : true ,
401
+ } ) ;
394
402
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
395
403
this . setState ( {
396
- folderTree : { ...folderTree , data : cloneData }
404
+ folderTree : { ...folderTree , data : cloneData } ,
397
405
} ) ;
398
406
if ( callback ) callback ( ) ;
399
407
}
400
408
401
409
public delete ( id : number , callback ?: Function ) {
402
410
const { folderTree } = this . state ;
403
411
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
404
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( id )
412
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
413
+ id
414
+ ) ;
405
415
const tree = new TreeView ( currentRootFolder ) ;
406
416
tree . remove ( id ) ;
407
417
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
408
418
this . setState ( {
409
- folderTree : { ...folderTree , data : cloneData }
419
+ folderTree : { ...folderTree , data : cloneData } ,
410
420
} ) ;
411
421
if ( callback ) callback ( ) ;
412
422
}
413
423
414
424
public newFile ( parentId : number , callback ?: Function ) {
415
425
const { folderTree } = this . state ;
416
426
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
417
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( parentId )
427
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
428
+ parentId
429
+ ) ;
418
430
const tree = new TreeView ( currentRootFolder ) ;
419
431
if ( ! parentId ) {
420
432
const tabData = {
421
433
id : `${ Math . random ( ) * 10 + 1 } ` ,
422
434
name : `Untitled` ,
423
- modified : false
435
+ modified : false ,
424
436
} ;
425
- editorService . open ( tabData )
437
+ editorService . open ( tabData ) ;
426
438
}
427
- tree . append ( new TreeNodeModel ( {
428
- modify : true
429
- } ) , parentId )
439
+ tree . append (
440
+ new TreeNodeModel ( {
441
+ modify : true ,
442
+ } ) ,
443
+ parentId
444
+ ) ;
430
445
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
431
446
this . setState ( {
432
- folderTree : { ...folderTree , data : cloneData }
447
+ folderTree : { ...folderTree , data : cloneData } ,
433
448
} ) ;
434
449
if ( callback ) callback ( ) ;
435
450
}
436
451
437
452
public newFolder ( parentId , callback : Function ) {
438
453
const { folderTree } = this . state ;
439
454
const cloneData : ITreeNodeItem [ ] = folderTree ?. data || [ ] ;
440
- const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex ( parentId )
455
+ const { currentRootFolder, index } = this . getCurrentRootFolderAndIndex (
456
+ parentId
457
+ ) ;
441
458
const tree = new TreeView ( currentRootFolder ) ;
442
- tree . append ( new TreeNodeModel ( {
443
- fileType : FileTypes . FOLDER as FileType ,
444
- modify : true
445
- } ) , parentId )
459
+ tree . append (
460
+ new TreeNodeModel ( {
461
+ fileType : FileTypes . FOLDER as FileType ,
462
+ modify : true ,
463
+ } ) ,
464
+ parentId
465
+ ) ;
446
466
if ( index > - 1 ) cloneData [ index ] = tree . obj ;
447
467
this . setState ( {
448
- folderTree : { ...folderTree , data : cloneData }
468
+ folderTree : { ...folderTree , data : cloneData } ,
449
469
} ) ;
450
470
if ( callback ) callback ( ) ;
451
471
}
@@ -457,5 +477,4 @@ export class ExplorerService
457
477
} ) ,
458
478
} ) ;
459
479
} ;
460
-
461
480
}
0 commit comments