summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-02-22 20:13:11 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-17 19:13:40 +1100
commitecaff7fc6cc3d2e510a88e336abcb74567de3f12 (patch)
tree4c896b81f194659708062a9fa5979f54e7a2ed3e
parent85f23198971de56195a4a1790d70e9d3b4ea1908 (diff)
add commit files controller
-rw-r--r--pkg/gui/commit_files_panel.go210
-rw-r--r--pkg/gui/controllers/commits_files_controller.go259
-rw-r--r--pkg/gui/controllers/helpers/helpers.go2
-rw-r--r--pkg/gui/controllers/helpers/patch_building_helper.go33
-rw-r--r--pkg/gui/controllers/local_commits_controller.go14
-rw-r--r--pkg/gui/controllers/reflog_controller.go8
-rw-r--r--pkg/gui/controllers/sub_commits_controller.go8
-rw-r--r--pkg/gui/global_handlers.go9
-rw-r--r--pkg/gui/gui.go15
-rw-r--r--pkg/gui/keybindings.go49
-rw-r--r--pkg/gui/line_by_line_panel.go9
-rw-r--r--pkg/gui/modes/diffing/diffing.go18
-rw-r--r--pkg/gui/patch_building_panel.go15
13 files changed, 343 insertions, 306 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index df37f6b41..be8ec1a53 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -2,10 +2,8 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
- "github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
- "github.com/jesseduffield/lazygit/pkg/gui/types"
)
func (gui *Gui) getSelectedCommitFile() *models.CommitFile {
@@ -37,7 +35,7 @@ func (gui *Gui) commitFilesRenderToMain() error {
}
to := gui.State.Contexts.CommitFiles.GetRefName()
- from, reverse := gui.getFromAndReverseArgsForDiff(to)
+ from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(to)
cmdObj := gui.git.WorkingTree.ShowFileDiffCmdObj(from, to, reverse, node.GetPath(), false)
task := NewRunPtyTask(cmdObj.GetCmd())
@@ -57,43 +55,22 @@ func (gui *Gui) commitFilesRenderToMain() error {
})
}
-func (gui *Gui) handleCheckoutCommitFile() error {
- node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
- if node == nil {
- return nil
- }
-
- gui.c.LogAction(gui.c.Tr.Actions.CheckoutFile)
- if err := gui.git.WorkingTree.CheckoutFile(gui.State.Contexts.CommitFiles.GetRefName(), node.GetPath()); err != nil {
- return gui.c.Error(err)
- }
+func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesContextOpts) error {
+ // sometimes the commitFiles view is already shown in another window, so we need to ensure that window
+ // no longer considers the commitFiles view as its main view.
+ gui.resetWindowContext(gui.State.Contexts.CommitFiles)
- return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
-}
+ gui.State.Contexts.CommitFiles.SetSelectedLineIdx(0)
+ gui.State.Contexts.CommitFiles.SetRefName(opts.RefName)
+ gui.State.Contexts.CommitFiles.SetCanRebase(opts.CanRebase)
+ gui.State.Contexts.CommitFiles.SetParentContext(opts.Context)
+ gui.State.Contexts.CommitFiles.SetWindowName(opts.Context.GetWindowName())
-func (gui *Gui) handleDiscardOldFileChange() error {
- if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ if err := gui.refreshCommitFilesView(); err != nil {
return err
}
- fileName := gui.getSelectedCommitFileName()
-
- return gui.c.Ask(types.AskOpts{
- Title: gui.c.Tr.DiscardFileChangesTitle,
- Prompt: gui.c.Tr.DiscardFileChangesPrompt,
- HandleConfirm: func() error {
- return gui.c.WithWaitingStatus(gui.c.Tr.RebasingStatus, func() error {
- gui.c.LogAction(gui.c.Tr.Actions.DiscardOldFileChange)
- if err := gui.git.Rebase.DiscardOldFileChanges(gui.State.Model.Commits, gui.State.Contexts.LocalCommits.GetSelectedLineIdx(), fileName); err != nil {
- if err := gui.helpers.MergeAndRebase.CheckMergeOrRebase(err); err != nil {
- return err
- }
- }
-
- return gui.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI})
- })
- },
- })
+ return gui.c.PushContext(gui.State.Contexts.CommitFiles)
}
func (gui *Gui) refreshCommitFilesView() error {
@@ -105,7 +82,7 @@ func (gui *Gui) refreshCommitFilesView() error {
}
to := gui.State.Contexts.CommitFiles.GetRefName()
- from, reverse := gui.getFromAndReverseArgsForDiff(to)
+ from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(to)
files, err := gui.git.Loaders.CommitFiles.GetFilesInDiff(from, to, reverse)
if err != nil {
@@ -117,166 +94,11 @@ func (gui *Gui) refreshCommitFilesView() error {
return gui.c.PostRefreshUpdate(gui.State.Contexts.CommitFiles)
}
-func (gui *Gui) handleOpenOldCommitFile() error {
+func (gui *Gui) getSelectedCommitFileName() string {
node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
if node == nil {
- return nil
- }
-
- return gui.helpers.Files.OpenFile(node.GetPath())
-}
-
-func (gui *Gui) handleEditCommitFile() error {
- node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
- if node == nil {
- return nil
- }
-
- if node.File == nil {
- return gui.c.ErrorMsg(gui.c.Tr.ErrCannotEditDirectory)
- }
-
- return gui.helpers.Files.EditFile(node.GetPath())
-}
-
-func (gui *Gui) handleToggleFileForPatch() error {
- node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
- if node == nil {
- return nil
- }
-
- toggleTheFile := func() error {
- if !gui.git.Patch.PatchManager.Active() {
- if err := gui.startPatchManager(); err != nil {
- return err
- }
- }
-
- // if there is any file that hasn't been fully added we'll fully add everything,
- // otherwise we'll remove everything
- adding := node.AnyFile(func(file *models.CommitFile) bool {
- return gui.git.Patch.PatchManager.GetFileStatus(file.Name, gui.State.Contexts.CommitFiles.GetRefName()) != patch.WHOLE
- })
-
- err := node.ForEachFile(func(file *models.CommitFile) error {
- if adding {
- return gui.git.Patch.PatchManager.AddFileWhole(file.Name)
- } else {
- return gui.git.Patch.PatchManager.RemoveFile(file.Name)
- }
- })
-
- if err != nil {
- return gui.c.Error(err)
- }
-
- if gui.git.Patch.PatchManager.IsEmpty() {
- gui.git.Patch.PatchManager.Reset()
- }
-
- return gui.c.PostRefreshUpdate(gui.State.Contexts.CommitFiles)
- }
-
- if gui.git.Patch.PatchManager.Active() && gui.git.Patch.PatchManager.To != gui.State.Contexts.CommitFiles.GetRefName() {
- return gui.c.Ask(types.AskOpts{
- Title: gui.c.Tr.DiscardPatch,
- Prompt: gui.c.Tr.DiscardPatchConfirm,
- HandleConfirm: func() error {
- gui.git.Patch.PatchManager.Reset()
- return toggleTheFile()
- },
- })
- }
-
- return toggleTheFile()
-}
-
-func (gui *Gui) startPatchManager() error {
- commitFilesContext := gui.State.Contexts.CommitFiles
-
- canRebase := commitFilesContext.GetCanRebase()
- to := commitFilesContext.GetRefName()
-
- from, reverse := gui.getFromAndReverseArgsForDiff(to)
-
- gui.git.Patch.PatchManager.Start(from, to, reverse, canRebase)
- return nil
-}
-
-func (gui *Gui) handleEnterCommitFile() error {
- return gui.enterCommitFile(types.OnFocusOpts{ClickedViewName: "", ClickedViewLineIdx: -1})
-}
-
-func (gui *Gui) enterCommitFile(opts types.OnFocusOpts) error {
- node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
- if node == nil {
- return nil
- }
-
- if node.File == nil {
- return gui.handleToggleCommitFileDirCollapsed()
- }
-
- enterTheFile := func() error {
- if !gui.git.Patch.PatchManager.Active() {
- if err := gui.startPatchManager(); err != nil {
- return err
- }
- }
-
- return gui.c.PushContext(gui.State.Contexts.PatchBuilding, opts)
- }
-
- if gui.git.Patch.PatchManager.Active() && gui.git.Patch.PatchManager.To != gui.State.Contexts.CommitFiles.GetRefName() {
- return gui.c.Ask(types.AskOpts{
- Title: gui.c.Tr.DiscardPatch,
- Prompt: gui.c.Tr.DiscardPatchConfirm,
- HandleConfirm: func() error {
- gui.git.Patch.PatchManager.Reset()
- return enterTheFile()
- },
- })
- }
-
- return enterTheFile()
-}
-
-func (gui *Gui) handleToggleCommitFileDirCollapsed() error {
- node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
- if node == nil {
- return nil
- }
-
- gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.ToggleCollapsed(node.GetPath())
-
- if err := gui.c.PostRefreshUpdate(gui.State.Contexts.CommitFiles); err != nil {
- gui.c.Log.Error(err)
- }
-
- return nil
-}
-
-// NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics
-func (gui *Gui) handleToggleCommitFileTreeView() error {
- gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.ToggleShowTree()
-
- return gui.c.PostRefreshUpdate(gui.State.Contexts.CommitFiles)
-}
-
-func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesContextOpts) error {
- // sometimes the commitFiles view is already shown in another window, so we need to ensure that window
- // no longer considers the commitFiles view as its main view.
- gui.resetWindowContext(gui.State.Contexts.CommitFiles)
-
- gui.State.Contexts.CommitFiles.SetSelectedLineIdx(0)
- gui.State.Contexts.CommitFiles.SetRefName(opts.RefName)
- gui.State.Contexts.CommitFiles.SetCanRebase(opts.CanRebase)
- gui.State.Contexts.CommitFiles.SetParentContext(opts.Context)
- gui.State.Contexts.CommitFiles.SetWindowName(opts.Context.GetWindowName())
-
- if err := gui.refreshCommitFilesView(); err != nil {
- return err
+ return ""
}
- return gui.c.PushContext(gui.State.Contexts.CommitFiles)
+ return node.Path
}
diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go
new file mode 100644
index 000000000..33d4ff4c1
--- /dev/null
+++ b/pkg/gui/controllers/commits_files_controller.go
@@ -0,0 +1,259 @@
+package controllers
+
+import (
+ "github.com/jesseduffield/gocui"
+ "github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/commands/patch"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
+ "github.com/jesseduffield/lazygit/pkg/gui/filetree"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
+)
+
+type CommitFilesController struct {
+ baseController
+ *controllerCommon
+}
+
+var _ types.IController = &CommitFilesController{}
+
+func NewCommitFilesController(
+ common *controllerCommon,
+) *CommitFilesController {
+ return &CommitFilesController{
+ baseController: baseController{},
+ controllerCommon: common,
+ }
+}
+
+func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
+ bindings := []*types.Binding{
+ {
+ Key: opts.GetKey(opts.Config.CommitFiles.CheckoutCommitFile),
+ Handler: self.checkSelected(self.handleCheckoutCommitFile),
+ Description: self.c.Tr.LcCheckoutCommitFile,
+ },
+ {
+ Key: opts.GetKey(opts.Config.Universal.Remove),
+ Handler: self.checkSelected(self.handleDiscardOldFileChange),
+ Description: self.c.Tr.LcDiscardOldFileChange,
+ },
+ {
+ Key: opts.GetKey(opts.Config.Universal.OpenFile),
+ Handler: self.checkSelected(self.handleOpenOldCommitFile),
+ Description: self.c.Tr.LcOpenFile,
+ },
+ {
+ Key: opts.GetKey(opts.Config.Universal.Edit),
+ Handler: self.checkSelected(self.handleEditCommitFile),
+ Description: self.c.Tr.LcEditFile,
+ },
+ {
+ Key: opts.GetKey(opts.Config.Universal.Select),
+ Handler: self.checkSelected(self.handleToggleFileForPatch),
+ Description: self.c.Tr.LcToggleAddToPatch,
+ },
+ {
+ Key: opts.GetKey(opts.Config.Universal.GoInto),
+ Handler: self.checkSelected(self.handleEnterCommitFile),
+ Description: self.c.Tr.LcEnterFile,
+ },
+ {
+ Key: opts.GetKey(opts.Config.Files.ToggleTreeView),
+ Handler: self.handleToggleCommitFileTreeView,
+ Description: self.c.Tr.LcToggleTreeView,
+ },
+ }
+
+ return bindings
+}
+
+func (self *CommitFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
+ return []*gocui.ViewMouseBinding{
+ {
+ ViewName: "main",
+ Key: gocui.MouseLeft,
+ Handler: self.onClickMain,
+ },
+ }
+}
+
+func (self *CommitFilesController) checkSelected(callback func(*filetree.CommitFileNode) error) func() error {
+ return func() error {
+ selected := self.context().GetSelectedFileNode()
+ if selected == nil {
+ return nil
+ }
+
+ return callback(selected)
+ }
+}
+
+func (self *CommitFilesController) Context() types.Context {
+ return self.context()
+}
+
+func (self *CommitFilesController) context() *context.CommitFilesContext {
+ return self.contexts.CommitFiles
+}
+
+func (self *CommitFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
+ clickedViewLineIdx := opts.Cy + opts.Oy
+ node := self.context().GetSelectedFileNode()
+ if node == nil {
+ return nil
+ }
+ return self.enterCommitFile(node, types.OnFocusOpts{ClickedViewName: "main", ClickedViewLineIdx: clickedViewLineIdx})
+}
+
+func (self *CommitFilesController) handleCheckoutCommitFile(node *filetree.CommitFileNode) error {
+ self.c.LogAction(self.c.Tr.Actions.CheckoutFile)
+ if err := self.git.WorkingTree.CheckoutFile(self.context().GetRefName(), node.GetPath()); err != nil {
+ return self.c.Error(err)
+ }
+
+ return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
+}
+
+func (self *CommitFilesController) handleDiscardOldFileChange(node *filetree.CommitFileNode) error {
+ if ok, err := self.helpers.PatchBuilding.ValidateNormalWorkingTreeState(); !ok {
+ return err
+ }
+
+ return self.c.Ask(types.AskOpts{
+ Title: self.c.Tr.DiscardFileChangesTitle,
+ Prompt: self.c.Tr.DiscardFileChangesPrompt,
+ HandleConfirm: func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
+ self.c.LogAction(self.c.Tr.Actions.DiscardOldFileChange)
+ if err := self.git.Rebase.DiscardOldFileChanges(self.model.Commits, self.contexts.LocalCommits.GetSelectedLineIdx(), node.GetPath()); err != nil {
+ if err := self.helpers.MergeAndRebase.CheckMergeOrRebase(err); err != nil {
+ return err
+ }
+ }
+
+ return self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI})
+ })
+ },
+ })
+}
+
+func (self *CommitFilesController) handleOpenOldCommitFile(node *filetree.CommitFileNode) error {
+ return self.helpers.Files.OpenFile(node.GetPath())
+}
+
+func (self *CommitFilesController) handleEditCommitFile(node *filetree.CommitFileNode) error {
+ if node.File == nil {
+ return self.c.ErrorMsg(self.c.Tr.ErrCannotEditDirectory)
+ }
+
+ return self.helpers.Files.EditFile(node.GetPath())
+}
+
+func (self *CommitFilesController) handleToggleFileForPatch(node *filetree.CommitFileNode) error {
+ toggleTheFile := func() error {
+ if !self.git.Patch.PatchManager.Active() {
+ if err := self.startPatchManager(); err != nil {
+ return err
+ }
+ }
+
+ // if there is any file that hasn't been fully added we'll fully add everything,
+ // otherwise we'll remove everything
+ adding := node.AnyFile(func(file *models.CommitFile) bool {
+ return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRefName()) != patch.WHOLE
+ })
+
+ err := node.ForEachFile(func(file *models.CommitFile) error {
+ if adding {
+ return self.git.Patch.PatchManager.AddFileWhole(file.Name)
+ } else {
+ return self.git.Patch.PatchManager.RemoveFile(file.Name)
+ }
+ })
+
+ if err != nil {
+ return self.c.Error(err)
+ }
+
+ if self.git.Patch.PatchManager.IsEmpty() {
+ self.git.Patch.PatchManager.Reset()
+ }
+
+ return self.c.PostRefreshUpdate(self.context())
+ }
+
+ if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRefName() {
+ return self.c.Ask(types.AskOpts{
+ Title: self.c.Tr.DiscardPatch,
+ Prompt: self.c.Tr.DiscardPatchConfirm,
+ HandleConfirm: func() error {
+ self.git.Patch.PatchManager.Reset()
+ return toggleTheFile()
+ },
+ })
+ }
+
+ return toggleTheFile()
+}
+
+func (self *CommitFilesController) startPatchManager() error {
+ commitFilesContext := self.context()
+
+ canRebase := commitFilesContext.GetCanRebase()
+ to := commitFilesContext.GetRefName()
+
+ from, reverse := self.modes.Diffing.GetFromAndReverseArgsForDiff(to)
+
+ self.git.Patch.PatchManager.Start(from, to, reverse, canRebase)
+ return nil
+}
+
+func (self *CommitFilesController) handleEnterCommitFile(node *filetree.CommitFileNode) error {
+ return self.enterCommitFile(node, types.OnFocusOpts{ClickedViewName: "", ClickedViewLineIdx: -1})
+}
+
+func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode, opts types.OnFocusOpts) error {
+ if node.File == nil {
+ return self.handleToggleCommitFileDirCollapsed(node)
+ }
+
+ enterTheFile := func() error {
+ if !self.git.Patch.PatchManager.Active() {
+ if err := self.startPatchManager(); err != nil {
+ return err
+ }
+ }
+
+ return self.c.PushContext(self.contexts.PatchBuilding, opts)
+ }
+
+ if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRefName() {
+ return self.c.Ask(types.AskOpts{
+ Title: self.c.Tr.DiscardPatch,
+ Prompt: self.c.Tr.DiscardPatchConfirm,
+ HandleConfirm: func() error {
+ self.git.Patch.PatchManager.Reset()
+ return enterTheFile()
+ },
+ })
+ }
+
+ return enterTheFile()
+}
+
+func (self *CommitFilesController) handleToggleCommitFileDirCollapsed(node *filetree.CommitFileNode) error {
+ self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetPath())
+
+ if err := self.c.PostRefreshUpdate(self.context()); err != nil {
+ self.c.Log.Error(err)
+ }
+
+ return nil
+}
+
+// NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics
+func (self *CommitFilesController) handleToggleCommitFileTreeView() error {
+ self.context().CommitFileTreeViewModel.ToggleShowTree()
+
+ return self.c.PostRefreshUpdate(self.context())
+}
diff --git a/pkg/gui/controllers/helpers/helpers.go b/pkg/gui/controllers/helpers/helpers.go
index 2ca4fbd40..2a7c43ff0 100644
--- a/pkg/gui/controllers/helpers/helpers.go
+++ b/pkg/gui/controllers/helpers/helpers.go
@@ -10,6 +10,7 @@ type Helpers struct {
MergeAndRebase *MergeAndRebaseHelper
CherryPick *CherryPickHelper
Host *HostHelper
+ PatchBuilding *PatchBuildingHelper
}
func NewStubHelpers() *Helpers {
@@ -23,5 +24,6 @@ func NewStubHelpers() *Helpers {
MergeAndRebase: &MergeAndRebaseHelper{},
CherryPick: &CherryPickHelper{},
Host: &HostHelper{},
+ PatchBuilding: &PatchBuildingHelper{},
}
}
diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go
new file mode 100644
index 000000000..efb8ec671
--- /dev/null
+++ b/pkg/gui/controllers/helpers/patch_building_helper.go
@@ -0,0 +1,33 @@
+package helpers
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
+)
+
+type IPatchBuildingHelper interface {
+ ValidateNormalWorkingTreeState() (bool, error)
+}
+
+type PatchBuildingHelper struct {
+ c *types.HelperCommon
+ git *commands.GitCommand
+}
+
+func NewPatchBuildingHelper(
+ c *types.HelperCommon,
+ git *commands.GitCommand,
+) *PatchBuildingHelper {
+ return &PatchBuildingHelper{
+ c: c,
+ git: git,
+ }
+}
+
+func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) {
+ if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE {
+ return false, self.c.ErrorMsg(self.c.Tr.CantPatchWhileRebasingError)
+ }
+ return true, nil
+}
diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go
index 694d7396f..b905e948e 100644
--- a/pkg/gui/controllers/local_commits_controller.go
+++ b/pkg/gui/controllers/local_commits_controller.go
@@ -11,16 +11,14 @@ import (
)
type (
- SwitchToCommitFilesContextFn func(SwitchToCommitFilesContextOpts) error
- PullFilesFn func() error
+ PullFilesFn func() error
)
type LocalCommitsController struct {
baseController
*controllerCommon
- pullFiles PullFilesFn
- switchToCommitFilesContext SwitchToCommitFilesContextFn
+ pullFiles PullFilesFn
}
var _ types.IController = &LocalCommitsController{}
@@ -28,13 +26,11 @@ var _ types.IController = &LocalCommitsController{}
func NewLocalCommitsController(
common *controllerCommon,
pullFiles PullFilesFn,
- switchToCommitFilesContext SwitchToCommitFilesContextFn,
) *LocalCommitsController {
return &LocalCommitsController{
- baseController: baseController{},
- controllerCommon: common,
- pullFiles: pullFiles,
- switchToCommitFilesContext: switchToCommitFilesContext,
+ baseController: baseController{},
+ controllerCommon: common,
+ pullFiles: pullFiles,
}
}
diff --git a/pkg/gui/controllers/reflog_controller.go b/pkg/gui/controllers/reflog_controller.go
index 43413a6ac..4085df635 100644
--- a/pkg/gui/controllers/reflog_controller.go
+++ b/pkg/gui/controllers/reflog_controller.go
@@ -9,20 +9,16 @@ import (
type ReflogController struct {
baseController
*controllerCommon
-
- switchToCommitFilesContext SwitchToCommitFilesContextFn
}
var _ types.IController = &ReflogController{}
func NewReflogController(
common *controllerCommon,
- switchToCommitFilesContext SwitchToCommitFilesContextFn,
) *ReflogController {
return &ReflogController{
- baseController: baseController{},
- controllerCommon: common,
- switchToCommitFilesContext: switchToCommitFilesContext,
+ baseController: baseController{},
+ controllerCommon: common,
}
}
diff --git a/pkg/gui/controllers/sub_commits_controller.go b/pkg/gui/controllers/sub_commits_controller.go
index 300f5b3fa..55b0795c1 100644
--- a/pkg/gui/controllers/sub_commits_controller.go
+++ b/pkg/gui/controllers/sub_commits_controller.go
@@ -9,20 +9,16 @@ import (
type SubCommitsController struct {
baseController
*controllerCommon
-
- switchToCommitFilesContext SwitchToCommitFilesContextFn
}
var _ types.IController = &SubCommitsController{}
func NewSubCommitsController(
common *controllerCommon,
- switchToCommitFilesContext SwitchToCommitFilesContextFn,
) *SubCommitsController {
return &SubCommitsController{
- baseController: baseController{},
- controllerCommon: common,
- switchToCommitFilesContext: switchToCommitFilesContext,
+ baseController: baseController{},
+ controllerCommon: common,
}
}
diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go
index d03723743..e76c9f1a6 100644
--- a/pkg/gui/global_handlers.go
+++ b/pkg/gui/global_handlers.go
@@ -180,15 +180,6 @@ func (gui *Gui) handleRefresh() error {
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
-func (gui *Gui) handleMouseDownMain() error {
- switch gui.currentSideContext() {
- case gui.State.Contexts.CommitFiles:
- return gui.enterCommitFile(types.OnFocusOpts{ClickedViewName: "main", ClickedViewLineIdx: gui.Views.Main.SelectedLineIdx()})
- }
-
- return nil
-}
-
func (gui *Gui) backgroundFetch() (err error) {
err = gui.git.Sync.Fetch(git_commands.FetchOptions{Background: true})
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 982ecae1e..93476636c 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -497,6 +497,7 @@ func (gui *Gui) resetControllers() {
rebaseHelper := helpers.NewMergeAndRebaseHelper(controllerCommon, gui.State.Contexts, gui.git, gui.takeOverMergeConflictScrolling, refsHelper)
gui.helpers = &helpers.Helpers{
Refs: refsHelper,
+ PatchBuilding: helpers.NewPatchBuildingHelper(controllerCommon, gui.git),
Bisect: helpers.NewBisectHelper(controllerCommon, gui.git),
Suggestions: helpers.NewSuggestionsHelper(controllerCommon, model, gui.refreshSuggestions),
Files: helpers.NewFilesHelper(controllerCommon, gui.git, osCommand),
@@ -534,8 +535,8 @@ func (gui *Gui) resetControllers() {
bisectController := controllers.NewBisectController(common)
- reflogController := controllers.NewReflogController(common, gui.SwitchToCommitFilesContext)
- subCommitsController := controllers.NewSubCommitsController(common, gui.SwitchToCommitFilesContext)
+ reflogController := controllers.NewReflogController(common)
+ subCommitsController := controllers.NewSubCommitsController(common)
gui.Controllers = Controllers{
Submodules: submodulesController,
@@ -548,12 +549,8 @@ func (gui *Gui) resetControllers() {
func() string { return gui.State.failedCommitMessage },
gui.switchToMerge,
),
- Tags: controllers.NewTagsController(common),
- LocalCommits: controllers.NewLocalCommitsController(
- common,
- syncController.HandlePull,
- gui.SwitchToCommitFilesContext,
- ),
+ Tags: controllers.NewTagsController(common),
+ LocalCommits: controllers.NewLocalCommitsController(common, syncController.HandlePull),
Remotes: controllers.NewRemotesController(
common,
func(branches []*models.RemoteBranch) { gui.State.Model.RemoteBranches = branches },
@@ -567,6 +564,7 @@ func (gui *Gui) resetControllers() {
gitFlowController := controllers.NewGitFlowController(common)
filesRemoveController := controllers.NewFilesRemoveController(common)
stashController := controllers.NewStashController(common)
+ commitFilesController := controllers.NewCommitFilesController(common)
switchToSubCommitsControllerFactory := controllers.NewSubCommitsSwitchControllerFactory(
common,
@@ -602,6 +600,7 @@ func (gui *Gui) resetControllers() {
controllers.AttachControllers(gui.State.Contexts.LocalCommits, gui.Controllers.LocalCommits, bisectController)
controllers.AttachControllers(gui.State.Contexts.ReflogCommits, reflogController)
controllers.AttachControllers(gui.State.Contexts.SubCommits, subCommitsController)
+ controllers.AttachControllers(gui.State.Contexts.CommitFiles, commitFilesController)
controllers.AttachControllers(gui.State.Contexts.Remotes, gui.Controllers.Remotes)
controllers.AttachControllers(gui.State.Contexts.Stash, stashController)
controllers.AttachControllers(gui.State.Contexts.Menu, gui.Controllers.Menu)
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index dfff8c9e1..fa0e893e0 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -473,48 +473,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
Description: self.c.Tr.LcCopyCommitFileNameToClipboard,
},
{
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.CommitFiles.CheckoutCommitFile),
- Handler: self.handleCheckoutCommitFile,
- Description: self.c.Tr.LcCheckoutCommitFile,
- },
- {
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.Universal.Remove),
- Handler: self.handleDiscardOldFileChange,
- Description: self.c.Tr.LcDiscardOldFileChange,
- },
- {
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.Universal.OpenFile),
- Handler: self.handleOpenOldCommitFile,
- Description: self.c.Tr.LcOpenFile,
- },
- {
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.Universal.Edit),
- Handler: self.handleEditCommitFile,
- Description: self.c.Tr.LcEditFile,
- },
- {
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.Universal.Select),
- Handler: self.handleToggleFileForPatch,
- Description: self.c.Tr.LcToggleAddToPatch,
- },
- {
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.Universal.GoInto),
- Handler: self.handleEnterCommitFile,
- Description: self.c.Tr.LcEnterFile,
- },
- {
- ViewName: "commitFiles",
- Key: opts.GetKey(opts.Config.Files.ToggleTreeView),
- Handler: self.handleToggleCommitFileTreeView,
- Description: self.c.Tr.LcToggleTreeView,
- },
- {
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.FilteringMenu),
Handler: self.handleCreateFilteringMenuPanel,
@@ -571,13 +529,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
Alternative: "fn+down",
},
{
- ViewName: "main",
- Contexts: []string{string(context.MAIN_NORMAL_CONTEXT_KEY)},
- Key: gocui.MouseLeft,
- Modifier: gocui.ModNone,
- Handler: self.handleMouseDownMain,
- },
- {
ViewName: "secondary",
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseLeft,
diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go
index 7f423f115..56de72426 100644
--- a/pkg/gui/line_by_line_panel.go
+++ b/pkg/gui/line_by_line_panel.go
@@ -120,15 +120,6 @@ func (gui *Gui) handleMouseDrag() error {
})
}
-func (gui *Gui) getSelectedCommitFileName() string {
- node := gui.State.Contexts.CommitFiles.GetSelectedFileNode()
- if node == nil {
- return ""
- }
-
- return node.Path
-}
-
func (gui *Gui) refreshMainViewForLineByLine(state *LblPanelState) error {
var includedLineIndices []int
// I'd prefer not to have knowledge of contexts using this file but I'm not sure
diff --git a/pkg/gui/modes/diffing/diffing.go b/pkg/gui/modes/diffing/diffing.go
index a5e103d62..b27662b72 100644
--- a/pkg/gui/modes/diffing/diffing.go
+++ b/pkg/gui/modes/diffing/diffing.go