Prompt on save/ existing file (#2714)

* Update for fixing bug issue

Adds YNprompt when user tries save new file as existing file name in current directory.

https://github.com/zyedidia/micro/issues/2709

* Update actions.go

error handled. gonna have to be tested on permission errors, etc
This commit is contained in:
Preston Thorpe
2023-01-29 21:11:34 -05:00
committed by GitHub
parent e31f5ed26e
commit d5caf84788

View File

@@ -791,10 +791,27 @@ func (h *BufPane) SaveAsCB(action string, callback func()) bool {
return
}
filename := strings.Join(args, " ")
noPrompt := h.saveBufToFile(filename, action, callback)
if noPrompt {
h.completeAction(action)
fileinfo, err := os.Stat(filename)
if err != nil {
if os.IsNotExist(err) {
noPrompt := h.saveBufToFile(filename, action, callback)
if noPrompt {
h.completeAction(action)
return
}
}
}
InfoBar.YNPrompt(
fmt.Sprintf("the file %s already exists in the directory, would you like to overwrite? Y/n", fileinfo.Name()),
func(yes, canceled bool) {
if yes && !canceled {
noPrompt := h.saveBufToFile(filename, action, callback)
if noPrompt {
h.completeAction(action)
}
}
},
)
}
})
return false