Implement File->Save dropdown option

This commit is contained in:
EnumDev 2025-06-07 21:57:26 +03:00
parent 448ebe27cf
commit 6b3ef29515
2 changed files with 37 additions and 5 deletions

View File

@ -13,10 +13,10 @@ type TyperInputRequest struct {
var currentInputRequest *TyperInputRequest
func RequestInput(window *Window, text string) chan string {
func RequestInput(window *Window, text string, defaultInput string) chan string {
request := &TyperInputRequest{
Text: text,
input: "",
input: defaultInput,
cursorPos: 0,
inputChannel: make(chan string),
}
@ -25,6 +25,8 @@ func RequestInput(window *Window, text string) chan string {
window.CursorMode = CursorModeInputBar
_ = window.screen.PostEvent(tcell.NewEventInterrupt(nil))
return request.inputChannel
}

View File

@ -38,10 +38,40 @@ func initTopMenu() {
window.SetCursorPos(0)
window.CursorMode = CursorModeBuffer
case 1:
_ = RequestInput(window, "Save buffer to:")
PrintMessage(window, "Input requested...")
if !window.textArea.CurrentBuffer.canSave {
PrintMessage(window, "Cannot save this buffer!")
return
}
inputChannel := RequestInput(window, "Save file [y\\N]:", "")
go func() {
input := <-inputChannel
if strings.ToLower(input) != "y" && strings.ToLower(input) != "yes" {
return
}
inputChannel = RequestInput(window, "Save buffer to:", window.textArea.CurrentBuffer.filename)
input = <-inputChannel
if strings.TrimSpace(input) == "" {
PrintMessage(window, "No save location was given!")
return
}
window.textArea.CurrentBuffer.filename = strings.TrimSpace(input)
err := window.textArea.CurrentBuffer.Save()
if err != nil {
PrintMessage(window, fmt.Sprintf("Could not save file: %s", err))
window.textArea.CurrentBuffer.filename = ""
return
}
PrintMessage(window, "File saved.")
}()
case 2:
inputChannel := RequestInput(window, "File to open:")
inputChannel := RequestInput(window, "File to open:", "")
go func() {
input := <-inputChannel