diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-10 16:20:35 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-10 22:32:13 +1100 |
commit | e85310c0a92a89167530241bdc3fc5f66a48706d (patch) | |
tree | f7989a8b002d2d5aa847460cae112aac9f64b669 /pkg/gui/commit_files_panel.go | |
parent | cd17b46b55e312b3ba4e3ab9d3d96a8eeb20fded (diff) |
add mouse support
Diffstat (limited to 'pkg/gui/commit_files_panel.go')
-rw-r--r-- | pkg/gui/commit_files_panel.go | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 845f7b02d..ab7b56ae7 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -15,11 +15,21 @@ func (gui *Gui) getSelectedCommitFile(g *gocui.Gui) *commands.CommitFile { return gui.State.CommitFiles[selectedLine] } +func (gui *Gui) handleCommitFilesClick(g *gocui.Gui, v *gocui.View) error { + itemCount := len(gui.State.CommitFiles) + handleSelect := gui.handleCommitFileSelect + selectedLine := &gui.State.Panels.CommitFiles.SelectedLine + + return gui.handleClick(v, itemCount, selectedLine, handleSelect) +} + func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error { if gui.popupPanelFocused() { return nil } + gui.getMainView().Title = "Patch" + commitFile := gui.getSelectedCommitFile(g) if commitFile == nil { return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) @@ -96,7 +106,7 @@ func (gui *Gui) refreshCommitFilesView() error { return err } - if err := gui.refreshPatchBuildingPanel(); err != nil { + if err := gui.refreshPatchBuildingPanel(-1); err != nil { return err } @@ -177,16 +187,20 @@ func (gui *Gui) startPatchManager() error { } func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error { + return gui.enterCommitFile(-1) +} + +func (gui *Gui) enterCommitFile(selectedLineIdx int) error { if ok, err := gui.validateNormalWorkingTreeState(); !ok { return err } - commitFile := gui.getSelectedCommitFile(g) + commitFile := gui.getSelectedCommitFile(gui.g) if commitFile == nil { - return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + return gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) } - enterTheFile := func() error { + enterTheFile := func(selectedLineIdx int) error { if !gui.GitCommand.PatchManager.CommitSelected() { if err := gui.startPatchManager(); err != nil { return err @@ -196,18 +210,21 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error { if err := gui.changeContext("main", "patch-building"); err != nil { return err } - if err := gui.switchFocus(g, v, gui.getMainView()); err != nil { + if err := gui.changeContext("secondary", "patch-building"); err != nil { + return err + } + if err := gui.switchFocus(gui.g, gui.getCommitFilesView(), gui.getMainView()); err != nil { return err } - return gui.refreshPatchBuildingPanel() + return gui.refreshPatchBuildingPanel(selectedLineIdx) } if gui.GitCommand.PatchManager.CommitSelected() && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha { - return gui.createConfirmationPanel(g, v, false, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error { + return gui.createConfirmationPanel(gui.g, gui.getCommitFilesView(), false, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error { gui.GitCommand.PatchManager.Reset() - return enterTheFile() + return enterTheFile(selectedLineIdx) }, nil) } - return enterTheFile() + return enterTheFile(selectedLineIdx) } |