2018-08-14 11:05:26 +02:00
|
|
|
package gui
|
|
|
|
|
2018-08-14 14:12:07 +02:00
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
)
|
2018-08-14 11:05:26 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
message := gui.trimmedContent(v)
|
|
|
|
if message == "" {
|
2018-08-15 09:15:31 +02:00
|
|
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr", "You cannot commit without a commit message"))
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
sub, err := gui.GitCommand.Commit(g, message)
|
|
|
|
if err != nil {
|
|
|
|
// TODO need to find a way to send through this error
|
2018-08-14 15:47:14 +02:00
|
|
|
if err != gui.Errors.ErrSubProcess {
|
2018-08-14 11:05:26 +02:00
|
|
|
return gui.createErrorPanel(g, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if sub != nil {
|
|
|
|
gui.SubProcess = sub
|
2018-08-14 15:47:14 +02:00
|
|
|
return gui.Errors.ErrSubProcess
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
gui.refreshFiles(g)
|
|
|
|
v.Clear()
|
|
|
|
v.SetCursor(0, 0)
|
|
|
|
g.SetViewOnBottom("commitMessage")
|
|
|
|
gui.switchFocus(g, v, gui.getFilesView(g))
|
|
|
|
return gui.refreshCommits(g)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
g.SetViewOnBottom("commitMessage")
|
|
|
|
return gui.switchFocus(g, v, gui.getFilesView(g))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleNewlineCommitMessage(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
// resising ahead of time so that the top line doesn't get hidden to make
|
|
|
|
// room for the cursor on the second line
|
|
|
|
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, v.Buffer())
|
|
|
|
if _, err := g.SetView("commitMessage", x0, y0, x1, y1+1, 0); err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v.EditNewLine()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error {
|
2018-08-15 09:15:31 +02:00
|
|
|
message := gui.Tr.TemplateLocalize(
|
|
|
|
"CloseConfirm",
|
|
|
|
"{{.keyBindClose}}: close, {{.keyBindConfirm}}: confirm",
|
|
|
|
map[string]interface{}{
|
|
|
|
"keyBindClose": "esc",
|
|
|
|
"keyBindConfirm": "enter",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gui.renderString(g, "options", message)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|