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

Replace PushContext() with Context().Push()

This commit is contained in:
Stefan Haller
2024-08-08 10:16:56 +02:00
parent d89dc967b8
commit bd36b8a95e
31 changed files with 36 additions and 41 deletions

View File

@ -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() { if self.c.Git().Patch.PatchBuilder.Active() && self.c.Git().Patch.PatchBuilder.To != self.context().GetRef().RefName() {

View File

@ -220,7 +220,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil { if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil {
return err 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 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 { func (self *FilesController) toggleStagedAll() error {

View File

@ -116,7 +116,7 @@ func (self *FilteringMenuAction) setFiltering() error {
repoState.SetScreenMode(types.SCREEN_HALF) 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 return err
} }

View File

@ -154,7 +154,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
self.UpdateCommitPanelView(opts.InitialMessage) 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() { func (self *CommitsHelper) OnCommitSuccess() {

View File

@ -241,7 +241,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
self.c.State().GetRepoState().SetCurrentPopupOpts(&opts) 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 { func underlineLinks(text string) string {

View File

@ -137,7 +137,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
} }
self.c.Contexts().LocalCommits.SetSelection(index) 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 { if warnAboutAddedLines {

View File

@ -202,7 +202,7 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
{ {
Label: self.c.Tr.ViewConflictsMenuItem, Label: self.c.Tr.ViewConflictsMenuItem,
OnPress: func() error { 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 { if err = self.ResetMarkedBaseCommit(); err != nil {
return err return err
} }
return self.c.PushContext(self.c.Contexts().LocalCommits) return self.c.Context().Push(self.c.Contexts().LocalCommits)
}, },
}, },
{ {

View File

@ -62,7 +62,7 @@ func (self *MergeConflictsHelper) EscapeMerge() error {
// files context over it. // files context over it.
// So long as both places call OnUIThread, we're fine. // So long as both places call OnUIThread, we're fine.
if self.c.IsCurrentContext(self.c.Contexts().MergeConflicts) { if self.c.IsCurrentContext(self.c.Contexts().MergeConflicts) {
return self.c.PushContext(self.c.Contexts().Files) return self.c.Context().Push(self.c.Contexts().Files)
} }
return nil 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 { func (self *MergeConflictsHelper) context() *context.MergeConflictsContext {

View File

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

View File

@ -41,7 +41,7 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
self.OnPromptContentChanged("") self.OnPromptContentChanged("")
promptView.RenderTextArea() 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 return err
} }
@ -60,7 +60,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err
promptView.ClearTextArea() promptView.ClearTextArea()
promptView.RenderTextArea() 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 return err
} }

View File

@ -83,11 +83,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
} }
if mainState == nil && !secondaryFocused { if mainState == nil && !secondaryFocused {
return self.c.PushContext(secondaryContext, focusOpts) return self.c.Context().Push(secondaryContext, focusOpts)
} }
if secondaryState == nil && secondaryFocused { if secondaryState == nil && secondaryFocused {
return self.c.PushContext(mainContext, focusOpts) return self.c.Context().Push(mainContext, focusOpts)
} }
if secondaryFocused { if secondaryFocused {
@ -110,7 +110,7 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro
} }
func (self *StagingHelper) handleStagingEscape() error { 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 { func (self *StagingHelper) secondaryStagingFocused() bool {

View File

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

View File

@ -55,6 +55,6 @@ func (self *JumpToSideWindowController) goToSideWindow(window string) func() err
context := self.c.Helpers().Window.GetContextForWindow(window) 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 { func (self *ListController) pushContextIfNotFocused() error {
if !self.isFocused() { if !self.isFocused() {
if err := self.c.PushContext(self.context); err != nil { if err := self.c.Context().Push(self.context); err != nil {
return err return err
} }
} }

View File

@ -150,7 +150,7 @@ func (self *PatchExplorerController) GetMouseKeybindings(opts types.KeybindingsO
return self.withRenderAndFocus(self.HandleMouseDown)() 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(), ClickedWindowName: self.context.GetWindowName(),
ClickedViewLineIdx: opts.Y, ClickedViewLineIdx: opts.Y,
}) })

View File

@ -74,7 +74,7 @@ func (self *QuitActions) Escape() error {
parentContext, hasParent := currentContext.GetParentContext() parentContext, hasParent := currentContext.GetParentContext()
if hasParent && currentContext != nil && parentContext != nil { if hasParent && currentContext != nil && parentContext != nil {
// TODO: think about whether this should be marked as a return rather than adding to the stack // 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() { 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 err
} }
return self.c.PushContext(remoteBranchesContext) return self.c.Context().Push(remoteBranchesContext)
} }
func (self *RemotesController) add() error { func (self *RemotesController) add() error {

View File

@ -69,7 +69,7 @@ func (self *SideWindowController) previousSideWindow() error {
context := self.c.Helpers().Window.GetContextForWindow(newWindow) context := self.c.Helpers().Window.GetContextForWindow(newWindow)
return self.c.PushContext(context) return self.c.Context().Push(context)
} }
func (self *SideWindowController) nextSideWindow() error { func (self *SideWindowController) nextSideWindow() error {
@ -92,5 +92,5 @@ func (self *SideWindowController) nextSideWindow() error {
context := self.c.Helpers().Window.GetContextForWindow(newWindow) 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 { func (self *SnakeController) Escape() error {
return self.c.PushContext(self.c.Contexts().Submodules) return self.c.Context().Push(self.c.Contexts().Submodules)
} }

View File

@ -177,7 +177,7 @@ func (self *StagingController) Escape() error {
func (self *StagingController) TogglePanel() error { func (self *StagingController) TogglePanel() error {
if self.otherContext.GetState() != nil { if self.otherContext.GetState() != nil {
return self.c.PushContext(self.otherContext) return self.c.Context().Push(self.otherContext)
} }
return nil return nil

View File

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

View File

@ -285,7 +285,7 @@ func (self *SubmodulesController) remove(submodule *models.SubmoduleConfig) erro
} }
func (self *SubmodulesController) easterEgg() error { 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 { func (self *SubmodulesController) context() *context.SubmodulesContext {

View File

@ -89,7 +89,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte
return err return err
} }
return self.c.PushContext(diffFilesContext) return self.c.Context().Push(diffFilesContext)
} }
func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason { 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 { if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil {
return err 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 { func (self *TagsController) localDelete(tag *models.Tag) error {

View File

@ -40,7 +40,7 @@ func (gui *Gui) handleFocusCommandLog() error {
gui.c.State().SetShowExtrasWindow(true) gui.c.State().SetShowExtrasWindow(true)
// TODO: is this necessary? Can't I just call 'return from context'? // TODO: is this necessary? Can't I just call 'return from context'?
gui.State.Contexts.CommandLog.SetParentContext(gui.c.CurrentSideContext()) gui.State.Contexts.CommandLog.SetParentContext(gui.c.CurrentSideContext())
return gui.c.PushContext(gui.State.Contexts.CommandLog) return gui.c.Context().Push(gui.State.Contexts.CommandLog)
} }
func (gui *Gui) scrollUpExtra() error { func (gui *Gui) scrollUpExtra() error {

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 return err
} }

View File

@ -45,10 +45,6 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
return self.gui.runSubprocessWithSuspense(cmdObj) 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 { func (self *guiCommon) PopContext() error {
return self.gui.State.ContextMgr.Pop() return self.gui.State.ContextMgr.Pop()
} }

View File

@ -60,5 +60,5 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
_ = gui.c.PostRefreshUpdate(gui.State.Contexts.Menu) _ = gui.c.PostRefreshUpdate(gui.State.Contexts.Menu)
// TODO: ensure that if we're opened a menu from within a menu that it renders correctly // 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

@ -57,7 +57,6 @@ type IGuiCommon interface {
RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error)
RunSubprocessAndRefresh(oscommands.ICmdObj) error RunSubprocessAndRefresh(oscommands.ICmdObj) error
PushContext(context Context, opts ...OnFocusOpts) error
PopContext() error PopContext() error
ReplaceContext(context Context) error ReplaceContext(context Context) error
// Removes all given contexts from the stack. If a given context is not in the stack, it is ignored. // Removes all given contexts from the stack. If a given context is not in the stack, it is ignored.

View File

@ -78,7 +78,7 @@ func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error {
return nil return nil
} }
return gui.c.PushContext(context) return gui.c.Context().Push(context)
} }
func (gui *Gui) handleNextTab() error { func (gui *Gui) handleNextTab() error {