Skip to content

Commit 71285cb

Browse files
committed
Fix renaming alerts
1 parent fe9ad32 commit 71285cb

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

ui/arduino2/store.js

+56-15
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ async function store(state, emitter) {
645645
log('finish-renaming', value)
646646

647647
// You can only rename one file, the selected one
648-
const fileName = state.selectedFiles[0].fileName
648+
const file = state.selectedFiles[0]
649649

650-
if (!value || fileName == value) {
650+
if (!value || file.fileName == value) {
651651
state.renamingFile = null
652652
emitter.emit('render')
653653
return
@@ -657,43 +657,84 @@ async function store(state, emitter) {
657657
emitter.emit('render')
658658

659659
// Check if new name overwrites something
660-
if (state.renamingFile == 'board') {
660+
if (state.renamingFile == 'board' && state.isConnected) {
661661
// Check if it will overwrite something
662662
const willOverwrite = await checkOverwrite({
663663
fileNames: [ value ],
664-
parentFolder: disk.getFullPath(state.boardNavigationRoot, state.boardNavigationPath, ''),
664+
parentPath: disk.getFullPath(
665+
state.boardNavigationRoot, state.boardNavigationPath, ''
666+
),
665667
source: 'board'
666668
})
667669
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`
671672
message += `Are you sure you want to proceed?`
672673
const confirmAction = confirm(message, 'Cancel', 'Yes')
673674
if (!confirmAction) {
674675
state.isSaving = false
676+
state.renamingFile = null
675677
emitter.emit('render')
676678
return
677679
}
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+
}
678698
}
679-
} else {
699+
} else if (state.renamingFile == 'disk') {
680700
// Check if it will overwrite something
681701
const willOverwrite = await checkOverwrite({
682702
fileNames: [ value ],
683-
parentFolder: disk.getFullPath(state.diskNavigationRoot, state.diskNavigationPath, ''),
703+
parentPath: disk.getFullPath(
704+
state.diskNavigationRoot, state.diskNavigationPath, ''
705+
),
684706
source: 'disk'
685707
})
686708
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`
690711
message += `Are you sure you want to proceed?`
691712
const confirmAction = confirm(message, 'Cancel', 'Yes')
692713
if (!confirmAction) {
693714
state.isSaving = false
715+
state.renamingFile = null
694716
emitter.emit('render')
695717
return
696718
}
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+
697738
}
698739
}
699740

@@ -703,7 +744,7 @@ async function store(state, emitter) {
703744
serial.getFullPath(
704745
state.boardNavigationRoot,
705746
state.boardNavigationPath,
706-
fileName
747+
file.fileName
707748
),
708749
serial.getFullPath(
709750
state.boardNavigationRoot,
@@ -716,7 +757,7 @@ async function store(state, emitter) {
716757
disk.getFullPath(
717758
state.diskNavigationRoot,
718759
state.diskNavigationPath,
719-
fileName
760+
file.fileName
720761
),
721762
disk.getFullPath(
722763
state.diskNavigationRoot,
@@ -726,7 +767,7 @@ async function store(state, emitter) {
726767
)
727768
}
728769
} 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}`)
730771
}
731772

732773
state.isSaving = false

0 commit comments

Comments
 (0)