@@ -645,9 +645,9 @@ async function store(state, emitter) {
645
645
log ( 'finish-renaming' , value )
646
646
647
647
// You can only rename one file, the selected one
648
- const fileName = state . selectedFiles [ 0 ] . fileName
648
+ const file = state . selectedFiles [ 0 ]
649
649
650
- if ( ! value || fileName == value ) {
650
+ if ( ! value || file . fileName == value ) {
651
651
state . renamingFile = null
652
652
emitter . emit ( 'render' )
653
653
return
@@ -657,43 +657,84 @@ async function store(state, emitter) {
657
657
emitter . emit ( 'render' )
658
658
659
659
// Check if new name overwrites something
660
- if ( state . renamingFile == 'board' ) {
660
+ if ( state . renamingFile == 'board' && state . isConnected ) {
661
661
// Check if it will overwrite something
662
662
const willOverwrite = await checkOverwrite ( {
663
663
fileNames : [ value ] ,
664
- parentFolder : disk . getFullPath ( state . boardNavigationRoot , state . boardNavigationPath , '' ) ,
664
+ parentPath : disk . getFullPath (
665
+ state . boardNavigationRoot , state . boardNavigationPath , ''
666
+ ) ,
665
667
source : 'board'
666
668
} )
667
669
if ( willOverwrite . length > 0 ) {
668
- let message = `You are about to overwrite the following files/folders on your board:\n\n`
669
- willOverwrite . forEach ( f => message += `${ f . fileName } \n` )
670
- message += `\n`
670
+ let message = `You are about to overwrite the following file/folder on your board:\n\n`
671
+ message += `${ value } \n\n`
671
672
message += `Are you sure you want to proceed?`
672
673
const confirmAction = confirm ( message , 'Cancel' , 'Yes' )
673
674
if ( ! confirmAction ) {
674
675
state . isSaving = false
676
+ state . renamingFile = null
675
677
emitter . emit ( 'render' )
676
678
return
677
679
}
680
+
681
+ if ( file . type == 'folder' ) {
682
+ await removeBoardFolder (
683
+ serial . getFullPath (
684
+ state . boardNavigationRoot ,
685
+ state . boardNavigationPath ,
686
+ value
687
+ )
688
+ )
689
+ } else if ( file . type == 'file' ) {
690
+ await serial . removeFile (
691
+ serial . getFullPath (
692
+ state . boardNavigationRoot ,
693
+ state . boardNavigationPath ,
694
+ value
695
+ )
696
+ )
697
+ }
678
698
}
679
- } else {
699
+ } else if ( state . renamingFile == 'disk' ) {
680
700
// Check if it will overwrite something
681
701
const willOverwrite = await checkOverwrite ( {
682
702
fileNames : [ value ] ,
683
- parentFolder : disk . getFullPath ( state . diskNavigationRoot , state . diskNavigationPath , '' ) ,
703
+ parentPath : disk . getFullPath (
704
+ state . diskNavigationRoot , state . diskNavigationPath , ''
705
+ ) ,
684
706
source : 'disk'
685
707
} )
686
708
if ( willOverwrite . length > 0 ) {
687
- let message = `You are about to overwrite the following files/folders on your disk:\n\n`
688
- willOverwrite . forEach ( f => message += `${ f . fileName } \n` )
689
- message += `\n`
709
+ let message = `You are about to overwrite the following file/folder on your disk:\n\n`
710
+ message += `${ value } \n\n`
690
711
message += `Are you sure you want to proceed?`
691
712
const confirmAction = confirm ( message , 'Cancel' , 'Yes' )
692
713
if ( ! confirmAction ) {
693
714
state . isSaving = false
715
+ state . renamingFile = null
694
716
emitter . emit ( 'render' )
695
717
return
696
718
}
719
+
720
+ if ( file . type == 'folder' ) {
721
+ await disk . removeFolder (
722
+ disk . getFullPath (
723
+ state . diskNavigationRoot ,
724
+ state . diskNavigationPath ,
725
+ value
726
+ )
727
+ )
728
+ } else if ( file . type == 'file' ) {
729
+ await disk . removeFile (
730
+ disk . getFullPath (
731
+ state . diskNavigationRoot ,
732
+ state . diskNavigationPath ,
733
+ value
734
+ )
735
+ )
736
+ }
737
+
697
738
}
698
739
}
699
740
@@ -703,7 +744,7 @@ async function store(state, emitter) {
703
744
serial . getFullPath (
704
745
state . boardNavigationRoot ,
705
746
state . boardNavigationPath ,
706
- fileName
747
+ file . fileName
707
748
) ,
708
749
serial . getFullPath (
709
750
state . boardNavigationRoot ,
@@ -716,7 +757,7 @@ async function store(state, emitter) {
716
757
disk . getFullPath (
717
758
state . diskNavigationRoot ,
718
759
state . diskNavigationPath ,
719
- fileName
760
+ file . fileName
720
761
) ,
721
762
disk . getFullPath (
722
763
state . diskNavigationRoot ,
@@ -726,7 +767,7 @@ async function store(state, emitter) {
726
767
)
727
768
}
728
769
} catch ( e ) {
729
- alert ( `The file ${ fileName } could not be renamed to ${ value } ` )
770
+ alert ( `The file ${ file . fileName } could not be renamed to ${ value } ` )
730
771
}
731
772
732
773
state . isSaving = false
0 commit comments