Add option to save and quit

Fixes #40
This commit is contained in:
Zachary Yedidia
2016-04-19 13:16:08 -04:00
parent ef89697b59
commit f0ad01d1ec
3 changed files with 6 additions and 3 deletions

View File

@@ -117,7 +117,7 @@ func HandleCommand(input string, view *View) {
case "set":
SetOption(view, args)
case "quit":
if view.CanClose("Quit anyway? ") {
if view.CanClose("Quit anyway? (yes, no, save) ") {
screen.Fini()
os.Exit(0)
}

View File

@@ -192,7 +192,7 @@ func main() {
switch e.Key() {
case tcell.KeyCtrlQ:
// Make sure not to quit if there are unsaved changes
if view.CanClose("Quit anyway? ") {
if view.CanClose("Quit anyway? (yes, no, save) ") {
screen.Fini()
os.Exit(0)
}

View File

@@ -196,6 +196,9 @@ func (v *View) CanClose(msg string) bool {
if !canceled {
if strings.ToLower(quit) == "yes" || strings.ToLower(quit) == "y" {
return true
} else if strings.ToLower(quit) == "save" || strings.ToLower(quit) == "s" {
v.Save()
return true
}
}
} else {
@@ -276,7 +279,7 @@ func (v *View) SelectAll() {
// OpenFile opens a new file in the current view
// It makes sure that the current buffer can be closed first (unsaved changes)
func (v *View) OpenFile() {
if v.CanClose("Continue? ") {
if v.CanClose("Continue? (yes, no, save) ") {
filename, canceled := messenger.Prompt("File to open: ")
if canceled {
return