2019-10-07 03:34:12 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
if os.Getenv("LAZYGIT_NEW_DIR_FILE") == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine current directory, set it in LAZYGIT_NEW_DIR_FILE
|
|
|
|
dirName, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return gui.OSCommand.CreateFileWithContent(os.Getenv("LAZYGIT_NEW_DIR_FILE"), dirName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleQuitWithoutChangingDirectory(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
gui.State.RetainOriginalDir = true
|
2020-08-15 09:23:16 +02:00
|
|
|
return gui.quit()
|
2019-10-07 03:34:12 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 09:23:16 +02:00
|
|
|
func (gui *Gui) handleQuit() error {
|
2019-10-07 03:34:12 +02:00
|
|
|
gui.State.RetainOriginalDir = false
|
2020-08-15 09:23:16 +02:00
|
|
|
return gui.quit()
|
2019-10-07 03:34:12 +02:00
|
|
|
}
|
|
|
|
|
2020-07-18 11:41:13 +02:00
|
|
|
func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error {
|
2020-08-21 13:05:21 +02:00
|
|
|
currentContext := gui.currentContext()
|
|
|
|
if currentContext != nil && currentContext.GetParentContext() != nil {
|
|
|
|
// TODO: think about whether this should be marked as a return rather than adding to the stack
|
|
|
|
return gui.switchContext(currentContext.GetParentContext())
|
|
|
|
}
|
|
|
|
|
2020-08-22 03:44:03 +02:00
|
|
|
for _, mode := range gui.modeStatuses() {
|
|
|
|
if mode.isActive() {
|
|
|
|
return mode.onReset()
|
|
|
|
}
|
2020-08-21 01:12:45 +02:00
|
|
|
}
|
|
|
|
|
2020-07-18 11:41:13 +02:00
|
|
|
if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
|
2020-08-15 09:23:16 +02:00
|
|
|
return gui.handleQuit()
|
2020-07-18 11:41:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-15 09:23:16 +02:00
|
|
|
func (gui *Gui) quit() error {
|
2019-10-07 03:34:12 +02:00
|
|
|
if gui.State.Updating {
|
2020-08-15 09:23:16 +02:00
|
|
|
return gui.createUpdateQuitConfirmation()
|
2019-10-07 03:34:12 +02:00
|
|
|
}
|
2020-08-12 12:30:28 +02:00
|
|
|
|
2019-10-07 03:34:12 +02:00
|
|
|
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-08-15 09:23:16 +02:00
|
|
|
returnToView: gui.g.CurrentView(),
|
2020-08-15 08:36:39 +02:00
|
|
|
returnFocusOnClose: true,
|
|
|
|
title: "",
|
|
|
|
prompt: gui.Tr.SLocalize("ConfirmQuit"),
|
|
|
|
handleConfirm: func() error {
|
|
|
|
return gocui.ErrQuit
|
|
|
|
},
|
|
|
|
})
|
2019-10-07 03:34:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return gocui.ErrQuit
|
|
|
|
}
|