1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-17 22:32:58 +02:00

Some cleanups for APIs related to contexts (#3808)

- **PR Description**

Some cleanups for APIs related to contexts. Most of these were triggered
by a TODO comment in the code.
This commit is contained in:
Stefan Haller 2024-08-17 11:24:15 +02:00 committed by GitHub
commit 1cb29cea15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
57 changed files with 115 additions and 202 deletions

View File

@ -53,7 +53,7 @@ func (self *ContextMgr) Replace(c types.Context) error {
defer self.Unlock()
return self.ActivateContext(c, types.OnFocusOpts{})
return self.Activate(c, types.OnFocusOpts{})
}
func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error {
@ -74,7 +74,7 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error {
contextsToDeactivate, contextToActivate := self.pushToContextStack(c)
for _, contextToDeactivate := range contextsToDeactivate {
if err := self.deactivateContext(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil {
if err := self.deactivate(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil {
return err
}
}
@ -83,7 +83,7 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error {
return nil
}
return self.ActivateContext(contextToActivate, singleOpts)
return self.Activate(contextToActivate, singleOpts)
}
// Adjusts the context stack based on the context that's being pushed and
@ -160,44 +160,14 @@ func (self *ContextMgr) Pop() error {
self.Unlock()
if err := self.deactivateContext(currentContext, types.OnFocusLostOpts{NewContextKey: newContext.GetKey()}); err != nil {
if err := self.deactivate(currentContext, types.OnFocusLostOpts{NewContextKey: newContext.GetKey()}); err != nil {
return err
}
return self.ActivateContext(newContext, types.OnFocusOpts{})
return self.Activate(newContext, types.OnFocusOpts{})
}
func (self *ContextMgr) RemoveContexts(contextsToRemove []types.Context) error {
self.Lock()
if len(self.ContextStack) == 1 {
self.Unlock()
return nil
}
rest := lo.Filter(self.ContextStack, func(context types.Context, _ int) bool {
for _, contextToRemove := range contextsToRemove {
if context.GetKey() == contextToRemove.GetKey() {
return false
}
}
return true
})
self.ContextStack = rest
contextToActivate := rest[len(rest)-1]
self.Unlock()
for _, context := range contextsToRemove {
if err := self.deactivateContext(context, types.OnFocusLostOpts{NewContextKey: contextToActivate.GetKey()}); err != nil {
return err
}
}
// activate the item at the top of the stack
return self.ActivateContext(contextToActivate, types.OnFocusOpts{})
}
func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLostOpts) error {
func (self *ContextMgr) deactivate(c types.Context, opts types.OnFocusLostOpts) error {
view, _ := self.gui.c.GocuiGui().View(c.GetViewName())
if opts.NewContextKey != context.SEARCH_CONTEXT_KEY {
@ -220,7 +190,7 @@ func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLos
return nil
}
func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts) error {
func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) error {
viewName := c.GetViewName()
v, err := self.gui.c.GocuiGui().View(viewName)
if err != nil {
@ -392,7 +362,7 @@ func (self *ContextMgr) ContextForKey(key types.ContextKey) types.Context {
return nil
}
func (self *ContextMgr) PopupContexts() []types.Context {
func (self *ContextMgr) CurrentPopup() []types.Context {
self.RLock()
defer self.RUnlock()

View File

@ -34,7 +34,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
getDisplayStrings := func(startIdx int, endIdx int) [][]string {
selectedCommitHash := ""
if c.CurrentContext().GetKey() == LOCAL_COMMITS_CONTEXT_KEY {
if c.Context().Current().GetKey() == LOCAL_COMMITS_CONTEXT_KEY {
selectedCommit := viewModel.GetSelected()
if selectedCommit != nil {
selectedCommitHash = selectedCommit.Hash

View File

@ -197,7 +197,7 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
return nil
}
if err := self.c.PopContext(); err != nil {
if err := self.c.Context().Pop(); err != nil {
return err
}

View File

@ -4,17 +4,14 @@ import "github.com/jesseduffield/lazygit/pkg/gui/types"
type ParentContextMgr struct {
ParentContext types.Context
// we can't know on the calling end whether a Context is actually a nil value without reflection, so we're storing this flag here to tell us. There has got to be a better way around this
hasParent bool
}
var _ types.ParentContexter = (*ParentContextMgr)(nil)
func (self *ParentContextMgr) SetParentContext(context types.Context) {
self.ParentContext = context
self.hasParent = true
}
func (self *ParentContextMgr) GetParentContext() (types.Context, bool) {
return self.ParentContext, self.hasParent
func (self *ParentContextMgr) GetParentContext() types.Context {
return self.ParentContext
}

View File

@ -53,7 +53,7 @@ func NewPatchExplorerContext(
func(selectedLineIdx int) error {
ctx.GetMutex().Lock()
defer ctx.GetMutex().Unlock()
return ctx.NavigateTo(ctx.c.IsCurrentContext(ctx), selectedLineIdx)
return ctx.NavigateTo(ctx.c.Context().IsCurrent(ctx), selectedLineIdx)
}),
)

View File

@ -47,7 +47,7 @@ func NewSubCommitsContext(
}
selectedCommitHash := ""
if c.CurrentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY {
if c.Context().Current().GetKey() == SUB_COMMITS_CONTEXT_KEY {
selectedCommit := viewModel.GetSelected()
if selectedCommit != nil {
selectedCommitHash = selectedCommit.Hash

View File

@ -53,7 +53,7 @@ func (self *CommitDescriptionController) context() *context.CommitMessageContext
}
func (self *CommitDescriptionController) switchToCommitMessage() error {
return self.c.ReplaceContext(self.c.Contexts().CommitMessage)
return self.c.Context().Replace(self.c.Contexts().CommitMessage)
}
func (self *CommitDescriptionController) close() error {

View File

@ -85,7 +85,7 @@ func (self *CommitMessageController) handleNextCommit() error {
}
func (self *CommitMessageController) switchToCommitDescription() error {
if err := self.c.ReplaceContext(self.c.Contexts().CommitDescription); err != nil {
if err := self.c.Context().Replace(self.c.Contexts().CommitDescription); err != nil {
return err
}
return nil

View File

@ -178,8 +178,8 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error
}
func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {
parentContext, ok := self.c.CurrentContext().GetParentContext()
if !ok || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY {
parentContext := self.c.Context().Current().GetParentContext()
if parentContext == nil || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY {
return errors.New(self.c.Tr.CanOnlyDiscardFromLocalCommits)
}
@ -354,7 +354,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
}
}
return self.c.PushContext(self.c.Contexts().CustomPatchBuilder, opts)
return self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts)
}
if self.c.Git().Patch.PatchBuilder.Active() && self.c.Git().Patch.PatchBuilder.To != self.context().GetRef().RefName() {

View File

@ -49,7 +49,7 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
self.c.UserConfig.Keybinding.Universal.Remove, self.c.UserConfig.Keybinding.Universal.Edit)
}
self.c.Views().Suggestions.Subtitle = subtitle
return self.c.ReplaceContext(self.c.Contexts().Suggestions)
return self.c.Context().Replace(self.c.Contexts().Suggestions)
}
return nil
},

View File

@ -94,7 +94,7 @@ func (self *ContextLinesController) applyChange() error {
self.c.Toast(fmt.Sprintf(self.c.Tr.DiffContextSizeChanged, self.c.AppState.DiffContextSize))
self.c.SaveAppStateAndLogError()
currentContext := self.c.CurrentStaticContext()
currentContext := self.c.Context().CurrentStatic()
switch currentContext.GetKey() {
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
case context.PATCH_BUILDING_MAIN_CONTEXT_KEY:
@ -117,6 +117,6 @@ func (self *ContextLinesController) checkCanChangeContext() error {
func (self *ContextLinesController) isShowingDiff() bool {
return lo.Contains(
CONTEXT_KEYS_SHOWING_DIFFS,
self.c.CurrentStaticContext().GetKey(),
self.c.Context().CurrentStatic().GetKey(),
)
}

View File

@ -66,7 +66,7 @@ func (self *CustomPatchOptionsMenuAction) Call() error {
},
}...)
if self.c.CurrentContext().GetKey() == self.c.Contexts().LocalCommits.GetKey() {
if self.c.Context().Current().GetKey() == self.c.Contexts().LocalCommits.GetKey() {
selectedCommit := self.c.Contexts().LocalCommits.GetSelected()
if selectedCommit != nil && self.c.Git().Patch.PatchBuilder.To != selectedCommit.Hash {
@ -122,7 +122,7 @@ func (self *CustomPatchOptionsMenuAction) validateNormalWorkingTreeState() (bool
}
func (self *CustomPatchOptionsMenuAction) returnFocusFromPatchExplorerIfNecessary() error {
if self.c.CurrentContext().GetKey() == self.c.Contexts().CustomPatchBuilder.GetKey() {
if self.c.Context().Current().GetKey() == self.c.Contexts().CustomPatchBuilder.GetKey() {
return self.c.Helpers().PatchBuilding.Escape()
}
return nil
@ -220,7 +220,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil {
return err
}
return self.c.PushContext(self.c.Contexts().LocalCommits)
return self.c.Context().Push(self.c.Contexts().LocalCommits)
})
},
},

View File

@ -500,7 +500,7 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error {
return errors.New(self.c.Tr.FileStagingRequirements)
}
return self.c.PushContext(self.c.Contexts().Staging, opts)
return self.c.Context().Push(self.c.Contexts().Staging, opts)
}
func (self *FilesController) toggleStagedAll() error {

View File

@ -14,7 +14,7 @@ type FilteringMenuAction struct {
func (self *FilteringMenuAction) Call() error {
fileName := ""
author := ""
switch self.c.CurrentSideContext() {
switch self.c.Context().CurrentSide() {
case self.c.Contexts().Files:
node := self.c.Contexts().Files.GetSelected()
if node != nil {
@ -116,7 +116,7 @@ func (self *FilteringMenuAction) setFiltering() error {
repoState.SetScreenMode(types.SCREEN_HALF)
}
if err := self.c.PushContext(self.c.Contexts().LocalCommits); err != nil {
if err := self.c.Context().Push(self.c.Contexts().LocalCommits); err != nil {
return err
}

View File

@ -154,7 +154,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
self.UpdateCommitPanelView(opts.InitialMessage)
return self.c.PushContext(self.c.Contexts().CommitMessage)
return self.c.Context().Push(self.c.Contexts().CommitMessage)
}
func (self *CommitsHelper) OnCommitSuccess() {
@ -193,7 +193,7 @@ func (self *CommitsHelper) CloseCommitMessagePanel() error {
self.c.Views().CommitMessage.Visible = false
self.c.Views().CommitDescription.Visible = false
return self.c.PopContext()
return self.c.Context().Pop()
}
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {

View File

@ -28,7 +28,7 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can
return func() error {
cancel()
if err := self.c.PopContext(); err != nil {
if err := self.c.Context().Pop(); err != nil {
return err
}
@ -241,7 +241,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
self.c.State().GetRepoState().SetCurrentPopupOpts(&opts)
return self.c.PushContext(self.c.Contexts().Confirmation)
return self.c.Context().Push(self.c.Contexts().Confirmation)
}
func underlineLinks(text string) string {
@ -325,7 +325,7 @@ func (self *ConfirmationHelper) getSelectedSuggestionValue() string {
func (self *ConfirmationHelper) ResizeCurrentPopupPanels() {
var parentPopupContext types.Context
for _, c := range self.c.CurrentPopupContexts() {
for _, c := range self.c.Context().CurrentPopup() {
switch c {
case self.c.Contexts().Menu:
self.resizeMenu(parentPopupContext)
@ -431,7 +431,7 @@ func (self *ConfirmationHelper) IsPopupPanel(context types.Context) bool {
}
func (self *ConfirmationHelper) IsPopupPanelFocused() bool {
return self.IsPopupPanel(self.c.CurrentContext())
return self.IsPopupPanel(self.c.Context().Current())
}
func (self *ConfirmationHelper) TooltipForMenuItem(menuItem *types.MenuItem) string {

View File

@ -70,7 +70,7 @@ func (self *DiffHelper) RenderDiff() error {
// which becomes an option when you bring up the diff menu, but when you're just
// flicking through branches it will be using the local branch name.
func (self *DiffHelper) CurrentDiffTerminals() []string {
c := self.c.CurrentSideContext()
c := self.c.Context().CurrentSide()
if c.GetKey() == "" {
return nil
@ -93,7 +93,7 @@ func (self *DiffHelper) currentDiffTerminal() string {
}
func (self *DiffHelper) currentlySelectedFilename() string {
currentContext := self.c.CurrentContext()
currentContext := self.c.Context().Current()
switch currentContext := currentContext.(type) {
case types.IListContext:

View File

@ -137,7 +137,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
}
self.c.Contexts().LocalCommits.SetSelection(index)
return self.c.PushContext(self.c.Contexts().LocalCommits)
return self.c.Context().Push(self.c.Contexts().LocalCommits)
}
if warnAboutAddedLines {

View File

@ -202,7 +202,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
{
Label: self.c.Tr.ViewConflictsMenuItem,
OnPress: func() error {
return self.c.PushContext(self.c.Contexts().Files)
return self.c.Context().Push(self.c.Contexts().Files)
},
},
{
@ -316,7 +316,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
if err = self.ResetMarkedBaseCommit(); err != nil {
return err
}
return self.c.PushContext(self.c.Contexts().LocalCommits)
return self.c.Context().Push(self.c.Contexts().LocalCommits)
},
},
{

View File

@ -61,8 +61,8 @@ func (self *MergeConflictsHelper) EscapeMerge() error {
// to continue the merge/rebase. In that case, we don't want to then push the
// files context over it.
// So long as both places call OnUIThread, we're fine.
if self.c.IsCurrentContext(self.c.Contexts().MergeConflicts) {
return self.c.PushContext(self.c.Contexts().Files)
if self.c.Context().IsCurrent(self.c.Contexts().MergeConflicts) {
return self.c.Context().Push(self.c.Contexts().Files)
}
return nil
})
@ -93,7 +93,7 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error {
}
}
return self.c.PushContext(self.c.Contexts().MergeConflicts)
return self.c.Context().Push(self.c.Contexts().MergeConflicts)
}
func (self *MergeConflictsHelper) context() *context.MergeConflictsContext {
@ -123,7 +123,7 @@ func (self *MergeConflictsHelper) RefreshMergeState() error {
self.c.Contexts().MergeConflicts.GetMutex().Lock()
defer self.c.Contexts().MergeConflicts.GetMutex().Unlock()
if self.c.CurrentContext().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY {
if self.c.Context().Current().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY {
return nil
}

View File

@ -34,14 +34,14 @@ func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error)
// takes us from the patch building panel back to the commit files panel
func (self *PatchBuildingHelper) Escape() error {
return self.c.PopContext()
return self.c.Context().Pop()
}
// kills the custom patch and returns us back to the commit files panel if needed
func (self *PatchBuildingHelper) Reset() error {
self.c.Git().Patch.PatchBuilder.Reset()
if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT {
if self.c.Context().CurrentStatic().GetKind() != types.SIDE_CONTEXT {
if err := self.Escape(); err != nil {
return err
}
@ -54,7 +54,7 @@ func (self *PatchBuildingHelper) Reset() error {
}
// refreshing the current context so that the secondary panel is hidden if necessary.
return self.c.PostRefreshUpdate(self.c.CurrentContext())
return self.c.PostRefreshUpdate(self.c.Context().Current())
}
func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpts) error {

View File

@ -276,8 +276,8 @@ func (self *RefreshHelper) refreshReflogAndBranches(refreshWorktrees bool, keepB
func (self *RefreshHelper) refreshCommitsAndCommitFiles() {
_ = self.refreshCommitsWithLimit()
ctx, ok := self.c.Contexts().CommitFiles.GetParentContext()
if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
ctx := self.c.Contexts().CommitFiles.GetParentContext()
if ctx != nil && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit hash at the same position.
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
// showing the contents of a different commit than the one we initially entered.

View File

@ -109,8 +109,8 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN
checkout := func(branchName string) error {
// Switch to the branches context _before_ starting to check out the
// branch, so that we see the inline status
if self.c.CurrentContext() != self.c.Contexts().Branches {
if err := self.c.PushContext(self.c.Contexts().Branches); err != nil {
if self.c.Context().Current() != self.c.Contexts().Branches {
if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil {
return err
}
}
@ -292,8 +292,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
return err
}
if self.c.CurrentContext() != self.c.Contexts().Branches {
if err := self.c.PushContext(self.c.Contexts().Branches); err != nil {
if self.c.Context().Current() != self.c.Contexts().Branches {
if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil {
return err
}
}

View File

@ -41,7 +41,7 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
self.OnPromptContentChanged("")
promptView.RenderTextArea()
if err := self.c.PushContext(self.c.Contexts().Search); err != nil {
if err := self.c.Context().Push(self.c.Contexts().Search); err != nil {
return err
}
@ -60,7 +60,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err
promptView.ClearTextArea()
promptView.RenderTextArea()
if err := self.c.PushContext(self.c.Contexts().Search); err != nil {
if err := self.c.Context().Push(self.c.Contexts().Search); err != nil {
return err
}
@ -118,7 +118,7 @@ func (self *SearchHelper) Confirm() error {
case types.SearchTypeSearch:
return self.ConfirmSearch()
case types.SearchTypeNone:
return self.c.PopContext()
return self.c.Context().Pop()
}
return nil
@ -140,7 +140,7 @@ func (self *SearchHelper) ConfirmFilter() error {
context.GetSearchHistory().Push(filterString)
}
return self.c.PopContext()
return self.c.Context().Pop()
}
func (self *SearchHelper) ConfirmSearch() error {
@ -158,7 +158,7 @@ func (self *SearchHelper) ConfirmSearch() error {
context.GetSearchHistory().Push(searchString)
}
if err := self.c.PopContext(); err != nil {
if err := self.c.Context().Pop(); err != nil {
return err
}
@ -183,7 +183,7 @@ func modelSearchResults(context types.ISearchableContext) []gocui.SearchPosition
func (self *SearchHelper) CancelPrompt() error {
self.Cancel()
return self.c.PopContext()
return self.c.Context().Pop()
}
func (self *SearchHelper) ScrollHistory(scrollIncrement int) {
@ -262,7 +262,7 @@ func (self *SearchHelper) ReApplySearch(ctx types.Context) {
if ctx == state.Context {
// Re-render the "x of y" search status, unless the search prompt is
// open for typing.
if self.c.CurrentContext().GetKey() != context.SEARCH_CONTEXT_KEY {
if self.c.Context().Current().GetKey() != context.SEARCH_CONTEXT_KEY {
self.RenderSearchStatus(searchableContext)
}
}

View File

@ -83,11 +83,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
}
if mainState == nil && !secondaryFocused {
return self.c.PushContext(secondaryContext, focusOpts)
return self.c.Context().Push(secondaryContext, focusOpts)
}
if secondaryState == nil && secondaryFocused {
return self.c.PushContext(mainContext, focusOpts)
return self.c.Context().Push(mainContext, focusOpts)
}
if secondaryFocused {
@ -110,13 +110,13 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
}
func (self *StagingHelper) handleStagingEscape() error {
return self.c.PushContext(self.c.Contexts().Files)
return self.c.Context().Push(self.c.Contexts().Files)
}
func (self *StagingHelper) secondaryStagingFocused() bool {
return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().StagingSecondary.GetKey()
return self.c.Context().CurrentStatic().GetKey() == self.c.Contexts().StagingSecondary.GetKey()
}
func (self *StagingHelper) mainStagingFocused() bool {
return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().Staging.GetKey()
return self.c.Context().CurrentStatic().GetKey() == self.c.Contexts().Staging.GetKey()
}

View File

@ -72,5 +72,5 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
return err
}
return self.c.PushContext(self.c.Contexts().SubCommits)
return self.c.Context().Push(self.c.Contexts().SubCommits)
}

View File

@ -89,8 +89,8 @@ func (self *WindowArrangementHelper) GetWindowDimensions(informationStr string,
Height: height,
UserConfig: self.c.UserConfig,
CurrentWindow: self.windowHelper.CurrentWindow(),
CurrentSideWindow: self.c.CurrentSideContext().GetWindowName(),
CurrentStaticWindow: self.c.CurrentStaticContext().GetWindowName(),
CurrentSideWindow: self.c.Context().CurrentSide().GetWindowName(),
CurrentStaticWindow: self.c.Context().CurrentStatic().GetWindowName(),
SplitMainPanel: repoState.GetSplitMainPanel(),
ScreenMode: repoState.GetScreenMode(),
AppStatus: appStatus,

View File

@ -61,7 +61,7 @@ func (self *WindowHelper) windowViewNameMap() *utils.ThreadSafeMap[string, strin
}
func (self *WindowHelper) CurrentWindow() string {
return self.c.CurrentContext().GetWindowName()
return self.c.Context().Current().GetWindowName()
}
// assumes the context's windowName has been set to the new window if necessary

View File

@ -55,6 +55,6 @@ func (self *JumpToSideWindowController) goToSideWindow(window string) func() err
context := self.c.Helpers().Window.GetContextForWindow(window)
return self.c.PushContext(context)
return self.c.Context().Push(context)
}
}

View File

@ -176,7 +176,7 @@ func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error {
func (self *ListController) pushContextIfNotFocused() error {
if !self.isFocused() {
if err := self.c.PushContext(self.context); err != nil {
if err := self.c.Context().Push(self.context); err != nil {
return err
}
}
@ -185,7 +185,7 @@ func (self *ListController) pushContextIfNotFocused() error {
}
func (self *ListController) isFocused() bool {
return self.c.CurrentContext().GetKey() == self.context.GetKey()
return self.c.Context().Current().GetKey() == self.context.GetKey()
}
func (self *ListController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {

View File

@ -79,7 +79,7 @@ func (self *MenuController) close() error {
return nil
}
return self.c.PopContext()
return self.c.Context().Pop()
}
func (self *MenuController) context() *context.MenuContext {

View File

@ -194,7 +194,7 @@ func (self *MergeConflictsController) context() *context.MergeConflictsContext {
}
func (self *MergeConflictsController) Escape() error {
return self.c.PopContext()
return self.c.Context().Pop()
}
func (self *MergeConflictsController) HandleEditFile() error {

View File

@ -12,7 +12,7 @@ type OptionsMenuAction struct {
}
func (self *OptionsMenuAction) Call() error {
ctx := self.c.CurrentContext()
ctx := self.c.Context().Current()
// Don't show menu while displaying popup.
if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP {
return nil

View File

@ -150,7 +150,7 @@ func (self *PatchExplorerController) GetMouseKeybindings(opts types.KeybindingsO
return self.withRenderAndFocus(self.HandleMouseDown)()
}
return self.c.PushContext(self.context, types.OnFocusOpts{
return self.c.Context().Push(self.context, types.OnFocusOpts{
ClickedWindowName: self.context.GetWindowName(),
ClickedViewLineIdx: opts.Y,
})
@ -293,7 +293,7 @@ func (self *PatchExplorerController) CopySelectedToClipboard() error {
}
func (self *PatchExplorerController) isFocused() bool {
return self.c.CurrentContext().GetKey() == self.context.GetKey()
return self.c.Context().Current().GetKey() == self.context.GetKey()
}
func (self *PatchExplorerController) withRenderAndFocus(f func() error) func() error {

View File

@ -49,7 +49,7 @@ func (self *QuitActions) confirmQuitDuringUpdate() error {
}
func (self *QuitActions) Escape() error {
currentContext := self.c.CurrentContext()
currentContext := self.c.Context().Current()
if listContext, ok := currentContext.(types.IListContext); ok {
if listContext.GetList().IsSelectingRange() {
@ -71,10 +71,10 @@ func (self *QuitActions) Escape() error {
}
}
parentContext, hasParent := currentContext.GetParentContext()
if hasParent && currentContext != nil && parentContext != nil {
parentContext := currentContext.GetParentContext()
if parentContext != nil {
// TODO: think about whether this should be marked as a return rather than adding to the stack
return self.c.PushContext(parentContext)
return self.c.Context().Push(parentContext)
}
for _, mode := range self.c.Helpers().Mode.Statuses() {

View File

@ -131,7 +131,7 @@ func (self *RemotesController) enter(remote *models.Remote) error {
return err
}
return self.c.PushContext(remoteBranchesContext)
return self.c.Context().Push(remoteBranchesContext)
}
func (self *RemotesController) add() error {

View File

@ -82,7 +82,7 @@ func (self *RenameSimilarityThresholdController) applyChange() error {
self.c.Toast(fmt.Sprintf(self.c.Tr.RenameSimilarityThresholdChanged, self.c.AppState.RenameSimilarityThreshold))
self.c.SaveAppStateAndLogError()
currentContext := self.c.CurrentStaticContext()
currentContext := self.c.Context().CurrentStatic()
switch currentContext.GetKey() {
// we make an exception for our files context, because it actually need to refresh its state afterwards.
case context.FILES_CONTEXT_KEY:
@ -95,6 +95,6 @@ func (self *RenameSimilarityThresholdController) applyChange() error {
func (self *RenameSimilarityThresholdController) isShowingRenames() bool {
return lo.Contains(
CONTEXT_KEYS_SHOWING_RENAMES,
self.c.CurrentStaticContext().GetKey(),
self.c.Context().CurrentStatic().GetKey(),
)
}

View File

@ -69,7 +69,7 @@ func (self *SideWindowController) previousSideWindow() error {
context := self.c.Helpers().Window.GetContextForWindow(newWindow)
return self.c.PushContext(context)
return self.c.Context().Push(context)
}
func (self *SideWindowController) nextSideWindow() error {
@ -92,5 +92,5 @@ func (self *SideWindowController) nextSideWindow() error {
context := self.c.Helpers().Window.GetContextForWindow(newWindow)
return self.c.PushContext(context)
return self.c.Context().Push(context)
}

View File

@ -75,5 +75,5 @@ func (self *SnakeController) SetDirection(direction snake.Direction) func() erro
}
func (self *SnakeController) Escape() error {
return self.c.PushContext(self.c.Contexts().Submodules)
return self.c.Context().Push(self.c.Contexts().Submodules)
}

View File

@ -172,12 +172,12 @@ func (self *StagingController) Escape() error {
return self.c.PostRefreshUpdate(self.context)
}
return self.c.PopContext()
return self.c.Context().Pop()
}
func (self *StagingController) TogglePanel() error {
if self.otherContext.GetState() != nil {
return self.c.PushContext(self.otherContext)
return self.c.Context().Push(self.otherContext)
}
return nil

View File

@ -113,7 +113,7 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error {
return nil
}
if err := self.c.PushContext(self.Context()); err != nil {
if err := self.c.Context().Push(self.Context()); err != nil {
return err
}

View File

@ -285,7 +285,7 @@ func (self *SubmodulesController) remove(submodule *models.SubmoduleConfig) erro
}
func (self *SubmodulesController) easterEgg() error {
return self.c.PushContext(self.c.Contexts().Snake)
return self.c.Context().Push(self.c.Contexts().Snake)
}
func (self *SubmodulesController) context() *context.SubmodulesContext {

View File

@ -72,7 +72,7 @@ func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) []
func (self *SuggestionsController) switchToConfirmation() error {
self.c.Views().Suggestions.Subtitle = ""
self.c.Views().Suggestions.Highlight = false
return self.c.ReplaceContext(self.c.Contexts().Confirmation)
return self.c.Context().Replace(self.c.Contexts().Confirmation)
}
func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) error {

View File

@ -89,7 +89,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte
return err
}
return self.c.PushContext(diffFilesContext)
return self.c.Context().Push(diffFilesContext)
}
func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason {

View File

@ -115,7 +115,7 @@ func (self *TagsController) checkout(tag *models.Tag) error {
if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil {
return err
}
return self.c.PushContext(self.c.Contexts().Branches)
return self.c.Context().Push(self.c.Contexts().Branches)
}
func (self *TagsController) localDelete(tag *models.Tag) error {

View File

@ -19,7 +19,7 @@ func (self *ToggleWhitespaceAction) Call() error {
context.PATCH_BUILDING_MAIN_CONTEXT_KEY,
}
if lo.Contains(contextsThatDontSupportIgnoringWhitespace, self.c.CurrentContext().GetKey()) {
if lo.Contains(contextsThatDontSupportIgnoringWhitespace, self.c.Context().Current().GetKey()) {
// Ignoring whitespace is not supported in these views. Let the user
// know that it's not going to work in case they try to turn it on.
return errors.New(self.c.Tr.IgnoreWhitespaceNotSupportedHere)
@ -28,5 +28,5 @@ func (self *ToggleWhitespaceAction) Call() error {
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
self.c.SaveAppStateAndLogError()
return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{})
return self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{})
}

View File

@ -15,9 +15,9 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
{
Label: gui.c.Tr.ToggleShowCommandLog,
OnPress: func() error {
currentContext := gui.c.CurrentStaticContext()
currentContext := gui.c.Context().CurrentStatic()
if gui.c.State().GetShowExtrasWindow() && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
if err := gui.c.PopContext(); err != nil {
if err := gui.c.Context().Pop(); err != nil {
return err
}
}
@ -39,8 +39,8 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
func (gui *Gui) handleFocusCommandLog() error {
gui.c.State().SetShowExtrasWindow(true)
// TODO: is this necessary? Can't I just call 'return from context'?
gui.State.Contexts.CommandLog.SetParentContext(gui.c.CurrentSideContext())
return gui.c.PushContext(gui.State.Contexts.CommandLog)
gui.State.Contexts.CommandLog.SetParentContext(gui.c.Context().CurrentSide())
return gui.c.Context().Push(gui.State.Contexts.CommandLog)
}
func (gui *Gui) scrollUpExtra() error {

View File

@ -27,7 +27,7 @@ func (gui *Gui) scrollDownView(view *gocui.View) {
func (gui *Gui) scrollUpMain() error {
var view *gocui.View
if gui.c.CurrentContext().GetWindowName() == "secondary" {
if gui.c.Context().Current().GetWindowName() == "secondary" {
view = gui.secondaryView()
} else {
view = gui.mainView()
@ -48,7 +48,7 @@ func (gui *Gui) scrollUpMain() error {
func (gui *Gui) scrollDownMain() error {
var view *gocui.View
if gui.c.CurrentContext().GetWindowName() == "secondary" {
if gui.c.Context().Current().GetWindowName() == "secondary" {
view = gui.secondaryView()
} else {
view = gui.mainView()
@ -128,7 +128,7 @@ func (gui *Gui) handleCopySelectedSideContextItemCommitHashToClipboard() error {
func (gui *Gui) handleCopySelectedSideContextItemToClipboardWithTruncation(maxWidth int) error {
// important to note that this assumes we've selected an item in a side context
currentSideContext := gui.c.CurrentSideContext()
currentSideContext := gui.c.Context().CurrentSide()
if currentSideContext == nil {
return nil
}
@ -162,7 +162,7 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboardWithTruncation(maxWi
func (gui *Gui) getCopySelectedSideContextItemToClipboardDisabledReason() *types.DisabledReason {
// important to note that this assumes we've selected an item in a side context
currentSideContext := gui.c.CurrentSideContext()
currentSideContext := gui.c.Context().CurrentSide()
if currentSideContext == nil {
// This should never happen but if it does we'll just ignore the keypress
return nil

View File

@ -335,7 +335,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
}
}
if err := gui.c.PushContext(contextToPush); err != nil {
if err := gui.c.Context().Push(contextToPush); err != nil {
return err
}
@ -360,7 +360,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
gui.State.CurrentPopupOpts = nil
gui.Mutexes.PopupMutex.Unlock()
return gui.c.CurrentContext()
return gui.c.Context().Current()
}
contextTree := gui.contextTree()

View File

@ -45,42 +45,6 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
return self.gui.runSubprocessWithSuspense(cmdObj)
}
func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error {
return self.gui.State.ContextMgr.Push(context, opts...)
}
func (self *guiCommon) PopContext() error {
return self.gui.State.ContextMgr.Pop()
}
func (self *guiCommon) ReplaceContext(context types.Context) error {
return self.gui.State.ContextMgr.Replace(context)
}
func (self *guiCommon) RemoveContexts(contexts []types.Context) error {
return self.gui.State.ContextMgr.RemoveContexts(contexts)
}
func (self *guiCommon) CurrentContext() types.Context {
return self.gui.State.ContextMgr.Current()
}
func (self *guiCommon) CurrentStaticContext() types.Context {
return self.gui.State.ContextMgr.CurrentStatic()
}
func (self *guiCommon) CurrentSideContext() types.Context {
return self.gui.State.ContextMgr.CurrentSide()
}
func (self *guiCommon) CurrentPopupContexts() []types.Context {
return self.gui.State.ContextMgr.PopupContexts()
}
func (self *guiCommon) IsCurrentContext(c types.Context) bool {
return self.gui.State.ContextMgr.IsCurrent(c)
}
func (self *guiCommon) Context() types.IContextMgr {
return self.gui.State.ContextMgr
}
@ -89,10 +53,6 @@ func (self *guiCommon) ContextForKey(key types.ContextKey) types.Context {
return self.gui.State.ContextMgr.ContextForKey(key)
}
func (self *guiCommon) ActivateContext(context types.Context) error {
return self.gui.State.ContextMgr.ActivateContext(context, types.OnFocusOpts{})
}
func (self *guiCommon) GetAppState() *config.AppState {
return self.gui.Config.GetAppState()
}

View File

@ -75,7 +75,7 @@ func (self *GuiDriver) Keys() config.KeybindingConfig {
}
func (self *GuiDriver) CurrentContext() types.Context {
return self.gui.c.CurrentContext()
return self.gui.c.Context().Current()
}
func (self *GuiDriver) ContextForView(viewName string) types.Context {

View File

@ -211,8 +211,8 @@ func (gui *Gui) onInitialViewsCreationForRepo() error {
}
}
initialContext := gui.c.CurrentContext()
if err := gui.c.ActivateContext(initialContext); err != nil {
initialContext := gui.c.Context().Current()
if err := gui.c.Context().Activate(initialContext, types.OnFocusOpts{}); err != nil {
return err
}

View File

@ -60,5 +60,5 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
_ = gui.c.PostRefreshUpdate(gui.State.Contexts.Menu)
// TODO: ensure that if we're opened a menu from within a menu that it renders correctly
return gui.c.PushContext(gui.State.Contexts.Menu)
return gui.c.Context().Push(gui.State.Contexts.Menu)
}

View File

@ -33,7 +33,7 @@ func (gui *Gui) renderContextOptionsMap() {
// to want to press that key. For example, when in cherry-picking mode, we
// want to prominently show the keybinding for pasting commits.
func (self *OptionsMapMgr) renderContextOptionsMap() {
currentContext := self.c.CurrentContext()
currentContext := self.c.Context().Current()
currentContextBindings := currentContext.GetKeybindings(self.c.KeybindingsOpts())
globalBindings := self.c.Contexts().Global.GetKeybindings(self.c.KeybindingsOpts())

View File

@ -57,24 +57,9 @@ type IGuiCommon interface {
RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error)
RunSubprocessAndRefresh(oscommands.ICmdObj) error
PushContext(context Context, opts ...OnFocusOpts) error
PopContext() error
ReplaceContext(context Context) error
// Removes all given contexts from the stack. If a given context is not in the stack, it is ignored.
// This is for when you have a group of contexts that are bundled together e.g. with the commit message panel.
// If you want to remove a single context, you should probably use PopContext instead.
RemoveContexts([]Context) error
CurrentContext() Context
CurrentStaticContext() Context
CurrentSideContext() Context
CurrentPopupContexts() []Context
IsCurrentContext(Context) bool
// TODO: replace the above context-based methods with just using Context() e.g. replace PushContext() with Context().Push()
Context() IContextMgr
ContextForKey(key ContextKey) Context
ActivateContext(context Context) error
GetConfig() config.AppConfigurer
GetAppState() *config.AppState
SaveAppState() error

View File

@ -35,8 +35,7 @@ const (
type ParentContexter interface {
SetParentContext(Context)
// we return a bool here to tell us whether or not the returned value just wraps a nil
GetParentContext() (Context, bool)
GetParentContext() Context
}
type NeedsRerenderOnWidthChangeLevel int
@ -279,9 +278,11 @@ type IContextMgr interface {
Push(context Context, opts ...OnFocusOpts) error
Pop() error
Replace(context Context) error
Activate(context Context, opts OnFocusOpts) error
Current() Context
CurrentStatic() Context
CurrentSide() Context
CurrentPopup() []Context
IsCurrent(c Context) bool
ForEach(func(Context))
AllList() []IListContext

View File

@ -78,7 +78,7 @@ func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error {
return nil
}
return gui.c.PushContext(context)
return gui.c.Context().Push(context)
}
func (gui *Gui) handleNextTab() error {
@ -119,7 +119,7 @@ func (gui *Gui) handlePrevTab() error {
func getTabbedView(gui *Gui) *gocui.View {
// It safe assumption that only static contexts have tabs
context := gui.c.CurrentStaticContext()
context := gui.c.Context().CurrentStatic()
view, _ := gui.g.View(context.GetViewName())
return view
}