diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-30 23:24:24 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:52 +1000 |
commit | 8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch) | |
tree | 0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui/controllers/switch_to_diff_files_controller.go | |
parent | 826128a8e03fb50f7287029ebac93c85712faecb (diff) |
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the
gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui/controllers/switch_to_diff_files_controller.go')
-rw-r--r-- | pkg/gui/controllers/switch_to_diff_files_controller.go | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 275a5ebb2..fa6ccdc0d 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -17,20 +18,20 @@ type CanSwitchToDiffFiles interface { type SwitchToDiffFilesController struct { baseController *controllerCommon - context CanSwitchToDiffFiles - viewFiles func(SwitchToCommitFilesContextOpts) error + context CanSwitchToDiffFiles + diffFilesContext *context.CommitFilesContext } func NewSwitchToDiffFilesController( controllerCommon *controllerCommon, - viewFiles func(SwitchToCommitFilesContextOpts) error, context CanSwitchToDiffFiles, + diffFilesContext *context.CommitFilesContext, ) *SwitchToDiffFilesController { return &SwitchToDiffFilesController{ baseController: baseController{}, controllerCommon: controllerCommon, context: context, - viewFiles: viewFiles, + diffFilesContext: diffFilesContext, } } @@ -72,3 +73,22 @@ func (self *SwitchToDiffFilesController) enter(ref types.Ref) error { func (self *SwitchToDiffFilesController) Context() types.Context { return self.context } + +func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error { + diffFilesContext := self.diffFilesContext + + diffFilesContext.SetSelectedLineIdx(0) + diffFilesContext.SetRef(opts.Ref) + diffFilesContext.SetTitleRef(opts.Ref.Description()) + diffFilesContext.SetCanRebase(opts.CanRebase) + diffFilesContext.SetParentContext(opts.Context) + diffFilesContext.SetWindowName(opts.Context.GetWindowName()) + + if err := self.c.Refresh(types.RefreshOptions{ + Scope: []types.RefreshableView{types.COMMIT_FILES}, + }); err != nil { + return err + } + + return self.c.PushContext(diffFilesContext) +} |