1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

refactor contexts code

This commit is contained in:
Jesse Duffield
2022-01-29 19:09:20 +11:00
parent 1a74ed3214
commit 138be04e65
60 changed files with 1154 additions and 602 deletions

View File

@ -124,7 +124,7 @@ type Gui struct {
suggestionsAsyncHandler *tasks.AsyncHandler
PopupHandler popup.IPopupHandler
PopupHandler types.IPopupHandler
IsNewRepo bool
@ -143,7 +143,7 @@ type Gui struct {
PrevLayout PrevLayout
c *controllers.ControllerCommon
c *types.ControllerCommon
refHelper *RefHelper
suggestionsHelper *SuggestionsHelper
fileHelper *FileHelper
@ -189,7 +189,7 @@ type GuiRepoState struct {
// Suggestions will sometimes appear when typing into a prompt
Suggestions []*types.Suggestion
MenuItems []*popup.MenuItem
MenuItems []*types.MenuItem
BisectInfo *git_commands.BisectInfo
Updating bool
Panels *panelStates
@ -284,10 +284,6 @@ type remoteBranchesState struct {
listPanelState
}
type tagsPanelState struct {
listPanelState
}
type commitPanelState struct {
listPanelState
@ -336,7 +332,6 @@ type panelStates struct {
Branches *branchPanelState
Remotes *remotePanelState
RemoteBranches *remoteBranchesState
Tags *tagsPanelState
Commits *commitPanelState
ReflogCommits *reflogCommitPanelState
SubCommits *subCommitPanelState
@ -453,7 +448,6 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
Branches: &branchPanelState{listPanelState{SelectedLineIdx: 0}},
Remotes: &remotePanelState{listPanelState{SelectedLineIdx: 0}},
RemoteBranches: &remoteBranchesState{listPanelState{SelectedLineIdx: -1}},
Tags: &tagsPanelState{listPanelState{SelectedLineIdx: -1}},
Commits: &commitPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, LimitCommits: true},
ReflogCommits: &reflogCommitPanelState{listPanelState{SelectedLineIdx: 0}},
SubCommits: &subCommitPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, refName: ""},
@ -557,7 +551,7 @@ func NewGui(
)
guiCommon := &guiCommon{gui: gui, IPopupHandler: gui.PopupHandler}
controllerCommon := &controllers.ControllerCommon{IGuiCommon: guiCommon, Common: cmn}
controllerCommon := &types.ControllerCommon{IGuiCommon: guiCommon, Common: cmn}
// storing this stuff on the gui for now to ease refactoring
// TODO: reset these controllers upon changing repos due to state changing
@ -589,12 +583,11 @@ func (gui *Gui) setControllers() {
tagsController := controllers.NewTagsController(
controllerCommon,
func() types.IListContext { return gui.State.Contexts.Tags },
func() *context.TagsContext { return gui.State.Contexts.Tags },
gui.git,
getContexts,
refHelper,
gui.suggestionsHelper,
gui.getSelectedTag,
gui.switchToSubCommitsContext,
)
@ -921,7 +914,7 @@ func (gui *Gui) showIntroPopupMessage(done chan struct{}) error {
return gui.c.SaveAppState()
}
return gui.c.Ask(popup.AskOpts{
return gui.c.Ask(types.AskOpts{
Title: "",
Prompt: gui.c.Tr.IntroPopupMessage,
HandleConfirm: onConfirm,
@ -956,7 +949,7 @@ func (gui *Gui) startBackgroundFetch() {
}
err := gui.backgroundFetch()
if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
_ = gui.c.Ask(popup.AskOpts{
_ = gui.c.Ask(types.AskOpts{
Title: gui.c.Tr.NoAutomaticGitFetchTitle,
Prompt: gui.c.Tr.NoAutomaticGitFetchBody,
})