mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 07:45:30 +03:00
editor now complains about unsaved files being closed; added exit command properly
This commit is contained in:
parent
de7def17c5
commit
e4dd07aead
@ -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),
|
||||
}
|
||||
|
@ -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
20
gui/exit_action.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user