Skip to content

Commit 7e7bc90

Browse files
committed
Clean "rename file" store event
1 parent 642db1a commit 7e7bc90

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

ui/arduino/store.js

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ function store(state, emitter) {
526526
let contents = cleanCharacters(editor.getValue())
527527
editor.setValue(contents)
528528

529-
if (state.selectedDevice === 'serial') {
529+
if (state.isConnected && state.selectedDevice === 'serial') {
530530
// Ask for confirmation to overwrite existing file
531531
let confirmation = true
532532
if (state.serialFiles.find(f => f.path === filename)) {
@@ -535,6 +535,11 @@ function store(state, emitter) {
535535

536536
if (confirmation) {
537537
emitter.emit('message', `Saving ${filename} on ${deviceName}.`)
538+
const newPath = serial.getFullPath(
539+
state.serialPath,
540+
state.serialNavigation,
541+
filename
542+
)
538543
if (state.serialFiles.find(f => f.path === oldFilename)) {
539544
const oldPath = serial.getFullPath(
540545
state.serialPath,
@@ -547,20 +552,8 @@ function store(state, emitter) {
547552
contents,
548553
(e) => emitter.emit('message', `Saving ${filename} on ${deviceName}. ${e}`)
549554
)
550-
await serial.renameFile(
551-
oldPath,
552-
serial.getFullPath(
553-
state.serialPath,
554-
state.serialNavigation,
555-
filename
556-
)
557-
)
555+
await serial.renameFile(oldPath, newPath)
558556
} else {
559-
const newPath = serial.getFullPath(
560-
state.serialPath,
561-
state.serialNavigation,
562-
filename
563-
)
564557
// If old name doesn't exist create new file
565558
await serial.saveFileContent(
566559
newPath,
@@ -587,38 +580,23 @@ function store(state, emitter) {
587580
}
588581
if (confirmation) {
589582
emitter.emit('message', `Renaming`)
583+
const newPath = disk.getFullPath(
584+
state.diskPath,
585+
state.diskNavigation,
586+
filename
587+
)
590588
if (state.diskFiles.find((f) => f.path === oldFilename)) {
591589
// If old name exists, save old file and rename
592-
await disk.saveFileContent(
593-
disk.getFullPath(
594-
state.diskPath,
595-
state.diskNavigation,
596-
oldFilename
597-
),
598-
contents
599-
)
600-
await disk.renameFile(
601-
disk.getFullPath(
602-
state.diskPath,
603-
state.diskNavigation,
604-
oldFilename
605-
),
606-
disk.getFullPath(
607-
state.diskPath,
608-
state.diskNavigation,
609-
filename
610-
)
590+
const oldPath = disk.getFullPath(
591+
state.diskPath,
592+
state.diskNavigation,
593+
oldFilename
611594
)
595+
await disk.saveFileContent(oldPath, contents)
596+
await disk.renameFile(oldPath, newPath)
612597
} else {
613598
// If old name doesn't exist create new file
614-
await disk.saveFileContent(
615-
disk.getFullPath(
616-
state.diskPath,
617-
state.diskNavigation,
618-
filename
619-
),
620-
contents
621-
)
599+
await disk.saveFileContent(newPath, contents)
622600
}
623601
state.isEditingFilename = false
624602
emitter.emit('message', `Saved`, 500)

0 commit comments

Comments
 (0)