2019-10-07 12:34:12 +11:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/gocui"
|
2022-01-29 19:09:20 +11:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2019-10-07 12:34:12 +11:00
|
|
|
)
|
|
|
|
|
2021-04-02 19:20:40 +11:00
|
|
|
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()
|
2019-10-07 12:34:12 +11:00
|
|
|
}
|
|
|
|
|
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()
|
2019-10-07 12:34:12 +11:00
|
|
|
}
|
|
|
|
|
2021-04-02 19:20:40 +11:00
|
|
|
func (gui *Gui) handleTopLevelReturn() error {
|
2022-12-30 23:24:24 +11:00
|
|
|
currentContext := gui.c.CurrentContext()
|
2020-08-24 08:26:42 +10:00
|
|
|
|
|
|
|
parentContext, hasParent := currentContext.GetParentContext()
|
|
|
|
if hasParent && currentContext != nil && parentContext != nil {
|
2020-08-21 21:05:21 +10:00
|
|
|
// TODO: think about whether this should be marked as a return rather than adding to the stack
|
2022-01-16 14:46:53 +11:00
|
|
|
return gui.c.PushContext(parentContext)
|
2020-08-21 21:05:21 +10:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:44:03 +10:00
|
|
|
for _, mode := range gui.modeStatuses() {
|
|
|
|
if mode.isActive() {
|
2020-08-23 09:23:59 +10:00
|
|
|
return mode.reset()
|
2020-08-22 11:44:03 +10:00
|
|
|
}
|
2020-08-21 09:12:45 +10:00
|
|
|
}
|
|
|
|
|
2022-12-30 23:24:24 +11:00
|
|
|
repoPathStack := gui.c.State().GetRepoPathStack()
|
2022-01-28 20:44:36 +11:00
|
|
|
if !repoPathStack.IsEmpty() {
|
2022-12-30 23:24:24 +11:00
|
|
|
return gui.helpers.Repos.DispatchSwitchToRepo(repoPathStack.Pop(), true)
|
2020-09-29 09:02:44 +10:00
|
|
|
}
|
|
|
|
|
2022-01-16 14:46:53 +11:00
|
|
|
if gui.c.UserConfig.QuitOnTopLevelReturn {
|
2020-08-15 17:23:16 +10:00
|
|
|
return gui.handleQuit()
|
2020-07-18 19:41:13 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-15 17:23:16 +10:00
|
|
|
func (gui *Gui) quit() error {
|
2022-12-30 23:24:24 +11:00
|
|
|
if gui.c.State().GetUpdating() {
|
2020-08-15 17:23:16 +10:00
|
|
|
return gui.createUpdateQuitConfirmation()
|
2019-10-07 12:34:12 +11:00
|
|
|
}
|
2020-08-12 20:30:28 +10:00
|
|
|
|
2022-01-16 14:46:53 +11:00
|
|
|
if gui.c.UserConfig.ConfirmOnQuit {
|
2022-03-30 08:48:29 +02:00
|
|
|
return gui.c.Confirm(types.ConfirmOpts{
|
2022-01-28 20:44:36 +11:00
|
|
|
Title: "",
|
2022-01-16 14:46:53 +11:00
|
|
|
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
|
|
|
|
},
|
|
|
|
})
|
2019-10-07 12:34:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return gocui.ErrQuit
|
|
|
|
}
|
2022-12-30 23:24:24 +11:00
|
|
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|