From d82f175e79f18756769d91de94458b095130297c Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 5 Feb 2022 17:04:10 +1100 Subject: refactor contexts --- pkg/gui/gui.go | 94 ++++++++-------------------------------------------------- 1 file changed, 13 insertions(+), 81 deletions(-) (limited to 'pkg/gui/gui.go') diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f8479c111..3cc6129e3 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -179,11 +179,11 @@ type GuiRepoState struct { // Suggestions will sometimes appear when typing into a prompt Suggestions []*types.Suggestion - MenuItems []*types.MenuItem Updating bool Panels *panelStates SplitMainPanel bool + LimitCommits bool IsRefreshingFiles bool Searching searchingState @@ -253,68 +253,11 @@ type MergingPanelState struct { UserVerticalScrolling bool } -// TODO: consider splitting this out into the window and the branches view -type branchPanelState struct { - listPanelState -} - -type remotePanelState struct { - listPanelState -} - -type remoteBranchesState struct { - listPanelState -} - -type commitPanelState struct { - listPanelState - - LimitCommits bool -} - -type reflogCommitPanelState struct { - listPanelState -} - -type subCommitPanelState struct { - listPanelState - - // e.g. name of branch whose commits we're looking at - refName string -} - -type stashPanelState struct { - listPanelState -} - -type menuPanelState struct { - listPanelState - OnPress func() error -} - -type submodulePanelState struct { - listPanelState -} - -type suggestionsPanelState struct { - listPanelState -} - // as we move things to the new context approach we're going to eventually // remove this struct altogether and store this state on the contexts. type panelStates struct { - Branches *branchPanelState - Remotes *remotePanelState - RemoteBranches *remoteBranchesState - Commits *commitPanelState - ReflogCommits *reflogCommitPanelState - SubCommits *subCommitPanelState - Stash *stashPanelState - Menu *menuPanelState - LineByLine *LblPanelState - Merging *MergingPanelState - Submodules *submodulePanelState - Suggestions *suggestionsPanelState + LineByLine *LblPanelState + Merging *MergingPanelState } type Views struct { @@ -449,23 +392,13 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) { }, Panels: &panelStates{ - // TODO: work out why some of these are -1 and some are 0. Last time I checked there was a good reason but I'm less certain now - Submodules: &submodulePanelState{listPanelState{SelectedLineIdx: -1}}, - Branches: &branchPanelState{listPanelState{SelectedLineIdx: 0}}, - Remotes: &remotePanelState{listPanelState{SelectedLineIdx: 0}}, - RemoteBranches: &remoteBranchesState{listPanelState{SelectedLineIdx: -1}}, - Commits: &commitPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, LimitCommits: true}, - ReflogCommits: &reflogCommitPanelState{listPanelState{SelectedLineIdx: 0}}, - SubCommits: &subCommitPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, refName: ""}, - Stash: &stashPanelState{listPanelState{SelectedLineIdx: -1}}, - Menu: &menuPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}, OnPress: nil}, - Suggestions: &suggestionsPanelState{listPanelState: listPanelState{SelectedLineIdx: 0}}, Merging: &MergingPanelState{ State: mergeconflicts.NewState(), UserVerticalScrolling: false, }, }, - Ptmx: nil, + LimitCommits: true, + Ptmx: nil, Modes: Modes{ Filtering: filtering.New(filterPath), CherryPicking: cherrypicking.New(), @@ -584,7 +517,7 @@ func (gui *Gui) resetControllers() { controllerCommon, gui.git, gui.State.Contexts, - func() { gui.State.Panels.Commits.LimitCommits = true }, + func() { gui.State.LimitCommits = true }, ), Bisect: controllers.NewBisectHelper(controllerCommon, gui.git), Suggestions: controllers.NewSuggestionsHelper(controllerCommon, model, gui.refreshSuggestions), @@ -615,7 +548,6 @@ func (gui *Gui) resetControllers() { gui.State.Contexts.Submodules, gui.git, gui.enterSubmodule, - gui.getSelectedSubmodule, ) bisectController := controllers.NewBisectController( @@ -623,7 +555,6 @@ func (gui *Gui) resetControllers() { gui.State.Contexts.BranchCommits, gui.git, gui.helpers.Bisect, - gui.getSelectedLocalCommit, func() []*models.Commit { return gui.State.Model.Commits }, ) @@ -672,15 +603,13 @@ func (gui *Gui) resetControllers() { gui.helpers.Refs, gui.helpers.CherryPick, gui.helpers.Rebase, - gui.getSelectedLocalCommit, model, - func() int { return gui.State.Panels.Commits.SelectedLineIdx }, gui.helpers.Rebase.CheckMergeOrRebase, syncController.HandlePull, gui.getHostingServiceMgr, gui.SwitchToCommitFilesContext, - func() bool { return gui.State.Panels.Commits.LimitCommits }, - func(value bool) { gui.State.Panels.Commits.LimitCommits = value }, + func() bool { return gui.State.LimitCommits }, + func(value bool) { gui.State.LimitCommits = value }, func() bool { return gui.ShowWholeGitGraph }, func(value bool) { gui.ShowWholeGitGraph = value }, ), @@ -689,13 +618,11 @@ func (gui *Gui) resetControllers() { gui.State.Contexts.Remotes, gui.git, gui.State.Contexts, - gui.getSelectedRemote, func(branches []*models.RemoteBranch) { gui.State.Model.RemoteBranches = branches }, ), Menu: controllers.NewMenuController( controllerCommon, gui.State.Contexts.Menu, - gui.getSelectedMenuItem, ), Undo: controllers.NewUndoController( controllerCommon, @@ -714,6 +641,11 @@ func (gui *Gui) resetControllers() { controllers.AttachControllers(gui.State.Contexts.Remotes, gui.Controllers.Remotes) controllers.AttachControllers(gui.State.Contexts.Menu, gui.Controllers.Menu) controllers.AttachControllers(gui.State.Contexts.Global, gui.Controllers.Sync, gui.Controllers.Undo, gui.Controllers.Global) + + listControllerFactory := controllers.NewListControllerFactory(gui.c) + for _, context := range gui.getListContexts() { + controllers.AttachControllers(context, listControllerFactory.Create(context)) + } } var RuneReplacements = map[rune]string{ -- cgit v1.2.3