mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
// This controller is for all contexts that contain commit files.
|
|
|
|
var _ types.IController = &SwitchToDiffFilesController{}
|
|
|
|
type CanSwitchToDiffFiles interface {
|
|
types.Context
|
|
CanRebase() bool
|
|
GetSelectedRefName() string
|
|
GetSelectedDescription() string
|
|
}
|
|
|
|
type SwitchToDiffFilesController struct {
|
|
baseController
|
|
*controllerCommon
|
|
context CanSwitchToDiffFiles
|
|
viewFiles func(SwitchToCommitFilesContextOpts) error
|
|
}
|
|
|
|
func NewSwitchToDiffFilesController(
|
|
controllerCommon *controllerCommon,
|
|
viewFiles func(SwitchToCommitFilesContextOpts) error,
|
|
context CanSwitchToDiffFiles,
|
|
) *SwitchToDiffFilesController {
|
|
return &SwitchToDiffFilesController{
|
|
baseController: baseController{},
|
|
controllerCommon: controllerCommon,
|
|
context: context,
|
|
viewFiles: viewFiles,
|
|
}
|
|
}
|
|
|
|
func (self *SwitchToDiffFilesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
|
bindings := []*types.Binding{
|
|
{
|
|
Key: opts.GetKey(opts.Config.Universal.GoInto),
|
|
Handler: self.checkSelected(self.enter),
|
|
Description: self.c.Tr.LcViewItemFiles,
|
|
},
|
|
}
|
|
|
|
return bindings
|
|
}
|
|
|
|
func (self *SwitchToDiffFilesController) GetOnClick() func() error {
|
|
return self.checkSelected(self.enter)
|
|
}
|
|
|
|
func (self *SwitchToDiffFilesController) checkSelected(callback func(string) error) func() error {
|
|
return func() error {
|
|
refName := self.context.GetSelectedRefName()
|
|
if refName == "" {
|
|
return nil
|
|
}
|
|
|
|
return callback(refName)
|
|
}
|
|
}
|
|
|
|
func (self *SwitchToDiffFilesController) enter(refName string) error {
|
|
return self.viewFiles(SwitchToCommitFilesContextOpts{
|
|
RefName: refName,
|
|
RefDescription: self.context.GetSelectedDescription(),
|
|
CanRebase: self.context.CanRebase(),
|
|
Context: self.context,
|
|
})
|
|
}
|
|
|
|
func (self *SwitchToDiffFilesController) Context() types.Context {
|
|
return self.context
|
|
}
|