mirror of
https://github.com/EnumeratedDev/Typer.git
synced 2025-07-01 07:48:20 +00:00
Implement File->Save dropdown option
This commit is contained in:
parent
448ebe27cf
commit
6b3ef29515
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user