1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-23 21:51:07 +02:00
lazygit/pkg/gui/quitting.go

72 lines
1.6 KiB
Go
Raw Normal View History

package gui
import (
"github.com/jesseduffield/gocui"
2022-01-29 19:09:20 +11:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
func (gui *Gui) handleQuitWithoutChangingDirectory() error {
2022-01-28 20:44:36 +11:00
gui.RetainOriginalDir = true
2020-08-15 17:23:16 +10:00
return gui.quit()
}
2020-08-15 17:23:16 +10:00
func (gui *Gui) handleQuit() error {
2022-01-28 20:44:36 +11:00
gui.RetainOriginalDir = false
2020-08-15 17:23:16 +10:00
return gui.quit()
}
func (gui *Gui) handleTopLevelReturn() error {
currentContext := gui.c.CurrentContext()
parentContext, hasParent := currentContext.GetParentContext()
if hasParent && currentContext != nil && parentContext != nil {
// TODO: think about whether this should be marked as a return rather than adding to the stack
return gui.c.PushContext(parentContext)
}
for _, mode := range gui.modeStatuses() {
if mode.isActive() {
2020-08-23 09:23:59 +10:00
return mode.reset()
}
}
repoPathStack := gui.c.State().GetRepoPathStack()
2022-01-28 20:44:36 +11:00
if !repoPathStack.IsEmpty() {
return gui.helpers.Repos.DispatchSwitchToRepo(repoPathStack.Pop(), true)
}
if gui.c.UserConfig.QuitOnTopLevelReturn {
2020-08-15 17:23:16 +10:00
return gui.handleQuit()
}
return nil
}
2020-08-15 17:23:16 +10:00
func (gui *Gui) quit() error {
if gui.c.State().GetUpdating() {
2020-08-15 17:23:16 +10:00
return gui.createUpdateQuitConfirmation()
}
if gui.c.UserConfig.ConfirmOnQuit {
return gui.c.Confirm(types.ConfirmOpts{
2022-01-28 20:44:36 +11:00
Title: "",
Prompt: gui.c.Tr.ConfirmQuit,
2022-01-28 20:44:36 +11:00
HandleConfirm: func() error {
2020-08-15 16:36:39 +10:00
return gocui.ErrQuit
},
})
}
return gocui.ErrQuit
}
func (gui *Gui) createUpdateQuitConfirmation() error {
return gui.c.Confirm(types.ConfirmOpts{
Title: gui.Tr.ConfirmQuitDuringUpdateTitle,
Prompt: gui.Tr.ConfirmQuitDuringUpdate,
HandleConfirm: func() error {
return gocui.ErrQuit
},
})
}