1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/quitting.go
Jesse Duffield 1dd7307fde start moving commit panel handlers into controller
more

and more

move rebase commit refreshing into existing abstraction

and more

and more

WIP

and more

handling clicks

properly fix merge conflicts

update cheatsheet

lots more preparation to start moving things into controllers

WIP

better typing

expand on remotes controller

moving more code into controllers
2022-03-17 19:13:40 +11:00

87 lines
2.0 KiB
Go

package gui
import (
"os"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/popup"
)
// when a user runs lazygit with the LAZYGIT_NEW_DIR_FILE env variable defined
// we will write the current directory to that file on exit so that their
// shell can then change to that directory. That means you don't get kicked
// back to the directory that you started with.
func (gui *Gui) recordCurrentDirectory() error {
// determine current directory, set it in LAZYGIT_NEW_DIR_FILE
dirName, err := os.Getwd()
if err != nil {
return err
}
return gui.recordDirectory(dirName)
}
func (gui *Gui) recordDirectory(dirName string) error {
newDirFilePath := os.Getenv("LAZYGIT_NEW_DIR_FILE")
if newDirFilePath == "" {
return nil
}
return gui.OSCommand.CreateFileWithContent(newDirFilePath, dirName)
}
func (gui *Gui) handleQuitWithoutChangingDirectory() error {
gui.RetainOriginalDir = true
return gui.quit()
}
func (gui *Gui) handleQuit() error {
gui.RetainOriginalDir = false
return gui.quit()
}
func (gui *Gui) handleTopLevelReturn() error {
currentContext := gui.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() {
return mode.reset()
}
}
repoPathStack := gui.RepoPathStack
if !repoPathStack.IsEmpty() {
path := repoPathStack.Pop()
return gui.dispatchSwitchToRepo(path, true)
}
if gui.c.UserConfig.QuitOnTopLevelReturn {
return gui.handleQuit()
}
return nil
}
func (gui *Gui) quit() error {
if gui.State.Updating {
return gui.createUpdateQuitConfirmation()
}
if gui.c.UserConfig.ConfirmOnQuit {
return gui.c.Ask(popup.AskOpts{
Title: "",
Prompt: gui.c.Tr.ConfirmQuit,
HandleConfirm: func() error {
return gocui.ErrQuit
},
})
}
return gocui.ErrQuit
}