editor now complains about unsaved files being closed; added exit command properly

This commit is contained in:
Felix Angell 2018-05-14 18:35:23 +01:00
parent de7def17c5
commit e4dd07aead
3 changed files with 39 additions and 8 deletions

View File

@ -2,7 +2,6 @@ package gui
import (
"log"
"os"
"strconv"
)
@ -115,9 +114,5 @@ var actions = map[string]BufferAction{
"close_buffer": NewBufferAction("close_buffer", CloseBuffer),
"paste": NewBufferAction("paste", Paste),
"show_palette": NewBufferAction("show_palette", ShowPalette),
"exit": NewBufferAction("exit", func(*View, []string) bool {
// TODO do this properly lol
os.Exit(0)
return false
}),
"exit": NewBufferAction("exit", ExitPhi),
}

View File

@ -1,14 +1,30 @@
package gui
import (
"fmt"
"github.com/sqweek/dialog"
)
func CloseBuffer(v *View, commands []string) bool {
b := v.getCurrentBuff()
if b == nil {
return false
}
// TODO eventually we should have our own
// little dialog IO message thingies.
if b.modified {
// do command palette thing!
return false
// TODO basename?
text := fmt.Sprintf("Do you want to save the changes you made to %s?", b.filePath)
dontSave := dialog.Message("%s", text).YesNo()
if !dontSave {
return false
}
// save the buffer!
Save(v, []string{})
}
v.removeBuffer(b.index)

20
gui/exit_action.go Normal file
View File

@ -0,0 +1,20 @@
package gui
import (
"log"
"os"
)
func ExitPhi(v *View, commands []string) bool {
// todo this probably wont work...
// would also be nice to have a thing
// that asks if we want to save all buffers
// rather than going thru each one specifically?
for i, _ := range v.buffers {
CloseBuffer(v, []string{})
log.Println("Closing buffer ", i)
}
os.Exit(0)
return false
}