mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
Remove return value of IContextMgr.Push/Pop et. al.
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
@ -37,9 +36,9 @@ func NewContextMgr(
|
||||
|
||||
// use when you don't want to return to the original context upon
|
||||
// hitting escape: you want to go that context's parent instead.
|
||||
func (self *ContextMgr) Replace(c types.Context) error {
|
||||
func (self *ContextMgr) Replace(c types.Context) {
|
||||
if !c.IsFocusable() {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
self.Lock()
|
||||
@ -53,12 +52,12 @@ func (self *ContextMgr) Replace(c types.Context) error {
|
||||
|
||||
self.Unlock()
|
||||
|
||||
return self.Activate(c, types.OnFocusOpts{})
|
||||
self.Activate(c, types.OnFocusOpts{})
|
||||
}
|
||||
|
||||
func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error {
|
||||
func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) {
|
||||
if len(opts) > 1 {
|
||||
return errors.New("cannot pass multiple opts to Push")
|
||||
panic("cannot pass multiple opts to Push")
|
||||
}
|
||||
|
||||
singleOpts := types.OnFocusOpts{}
|
||||
@ -68,22 +67,18 @@ func (self *ContextMgr) Push(c types.Context, opts ...types.OnFocusOpts) error {
|
||||
}
|
||||
|
||||
if !c.IsFocusable() {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
contextsToDeactivate, contextToActivate := self.pushToContextStack(c)
|
||||
|
||||
for _, contextToDeactivate := range contextsToDeactivate {
|
||||
if err := self.deactivate(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil {
|
||||
return err
|
||||
}
|
||||
self.deactivate(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()})
|
||||
}
|
||||
|
||||
if contextToActivate == nil {
|
||||
return nil
|
||||
if contextToActivate != nil {
|
||||
self.Activate(contextToActivate, singleOpts)
|
||||
}
|
||||
|
||||
return self.Activate(contextToActivate, singleOpts)
|
||||
}
|
||||
|
||||
// Adjusts the context stack based on the context that's being pushed and
|
||||
@ -144,13 +139,13 @@ func (self *ContextMgr) pushToContextStack(c types.Context) ([]types.Context, ty
|
||||
return contextsToDeactivate, c
|
||||
}
|
||||
|
||||
func (self *ContextMgr) Pop() error {
|
||||
func (self *ContextMgr) Pop() {
|
||||
self.Lock()
|
||||
|
||||
if len(self.ContextStack) == 1 {
|
||||
// cannot escape from bottommost context
|
||||
self.Unlock()
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
var currentContext types.Context
|
||||
@ -160,14 +155,12 @@ func (self *ContextMgr) Pop() error {
|
||||
|
||||
self.Unlock()
|
||||
|
||||
if err := self.deactivate(currentContext, types.OnFocusLostOpts{NewContextKey: newContext.GetKey()}); err != nil {
|
||||
return err
|
||||
}
|
||||
self.deactivate(currentContext, types.OnFocusLostOpts{NewContextKey: newContext.GetKey()})
|
||||
|
||||
return self.Activate(newContext, types.OnFocusOpts{})
|
||||
self.Activate(newContext, types.OnFocusOpts{})
|
||||
}
|
||||
|
||||
func (self *ContextMgr) deactivate(c types.Context, opts types.OnFocusLostOpts) error {
|
||||
func (self *ContextMgr) deactivate(c types.Context, opts types.OnFocusLostOpts) {
|
||||
view, _ := self.gui.c.GocuiGui().View(c.GetViewName())
|
||||
|
||||
if opts.NewContextKey != context.SEARCH_CONTEXT_KEY {
|
||||
@ -184,15 +177,13 @@ func (self *ContextMgr) deactivate(c types.Context, opts types.OnFocusLostOpts)
|
||||
}
|
||||
|
||||
c.HandleFocusLost(opts)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) error {
|
||||
func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) {
|
||||
viewName := c.GetViewName()
|
||||
v, err := self.gui.c.GocuiGui().View(viewName)
|
||||
if err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
self.gui.helpers.Window.SetWindowContext(c)
|
||||
@ -203,7 +194,7 @@ func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) error
|
||||
oldView.HighlightInactive = true
|
||||
}
|
||||
if _, err := self.gui.c.GocuiGui().SetCurrentView(viewName); err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
self.gui.helpers.Search.RenderSearchStatus(c)
|
||||
@ -218,8 +209,6 @@ func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) error
|
||||
self.gui.c.GocuiGui().Cursor = v.Editable
|
||||
|
||||
c.HandleFocus(opts)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *ContextMgr) Current() types.Context {
|
||||
|
@ -197,9 +197,7 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := self.c.Context().Pop(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Pop()
|
||||
|
||||
if selectedItem == nil {
|
||||
return nil
|
||||
|
@ -60,11 +60,13 @@ func (self *CommitDescriptionController) GetMouseKeybindings(opts types.Keybindi
|
||||
}
|
||||
|
||||
func (self *CommitDescriptionController) switchToCommitMessage() error {
|
||||
return self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
||||
self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CommitDescriptionController) close() error {
|
||||
return self.c.Helpers().Commits.CloseCommitMessagePanel()
|
||||
self.c.Helpers().Commits.CloseCommitMessagePanel()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CommitDescriptionController) confirm() error {
|
||||
@ -79,7 +81,7 @@ func (self *CommitDescriptionController) openCommitMenu() error {
|
||||
func (self *CommitDescriptionController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
||||
// Activate the description panel when the commit message panel is currently active
|
||||
if self.c.Context().Current().GetKey() == context.COMMIT_MESSAGE_CONTEXT_KEY {
|
||||
return self.c.Context().Replace(self.c.Contexts().CommitDescription)
|
||||
self.c.Context().Replace(self.c.Contexts().CommitDescription)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -95,9 +95,7 @@ func (self *CommitMessageController) handleNextCommit() error {
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) switchToCommitDescription() error {
|
||||
if err := self.c.Context().Replace(self.c.Contexts().CommitDescription); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Replace(self.c.Contexts().CommitDescription)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -140,7 +138,8 @@ func (self *CommitMessageController) confirm() error {
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) close() error {
|
||||
return self.c.Helpers().Commits.CloseCommitMessagePanel()
|
||||
self.c.Helpers().Commits.CloseCommitMessagePanel()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) openCommitMenu() error {
|
||||
@ -151,7 +150,7 @@ func (self *CommitMessageController) openCommitMenu() error {
|
||||
func (self *CommitMessageController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
||||
// Activate the commit message panel when the commit description panel is currently active
|
||||
if self.c.Context().Current().GetKey() == context.COMMIT_DESCRIPTION_CONTEXT_KEY {
|
||||
return self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
||||
self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -359,7 +359,8 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
|
||||
}
|
||||
}
|
||||
|
||||
return self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts)
|
||||
self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts)
|
||||
return nil
|
||||
}
|
||||
|
||||
from, to, reverse := self.currentFromToReverseForPatchBuilding()
|
||||
|
@ -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.Context().Replace(self.c.Contexts().Suggestions)
|
||||
self.c.Context().Replace(self.c.Contexts().Suggestions)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
@ -121,11 +121,10 @@ func (self *CustomPatchOptionsMenuAction) validateNormalWorkingTreeState() (bool
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (self *CustomPatchOptionsMenuAction) returnFocusFromPatchExplorerIfNecessary() error {
|
||||
func (self *CustomPatchOptionsMenuAction) returnFocusFromPatchExplorerIfNecessary() {
|
||||
if self.c.Context().Current().GetKey() == self.c.Contexts().CustomPatchBuilder.GetKey() {
|
||||
return self.c.Helpers().PatchBuilding.Escape()
|
||||
self.c.Helpers().PatchBuilding.Escape()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CustomPatchOptionsMenuAction) handleDeletePatchFromCommit() error {
|
||||
@ -133,9 +132,7 @@ func (self *CustomPatchOptionsMenuAction) handleDeletePatchFromCommit() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.returnFocusFromPatchExplorerIfNecessary()
|
||||
|
||||
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
|
||||
commitIndex := self.getPatchCommitIndex()
|
||||
@ -150,9 +147,7 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchToSelectedCommit() erro
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.returnFocusFromPatchExplorerIfNecessary()
|
||||
|
||||
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
|
||||
commitIndex := self.getPatchCommitIndex()
|
||||
@ -167,9 +162,7 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchIntoWorkingTree() error
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.returnFocusFromPatchExplorerIfNecessary()
|
||||
|
||||
pull := func(stash bool) error {
|
||||
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
|
||||
@ -198,9 +191,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.returnFocusFromPatchExplorerIfNecessary()
|
||||
|
||||
commitIndex := self.getPatchCommitIndex()
|
||||
return self.c.Helpers().Commits.OpenCommitMessagePanel(
|
||||
@ -214,13 +205,14 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
|
||||
PreserveMessage: false,
|
||||
OnConfirm: func(summary string, description string) error {
|
||||
return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error {
|
||||
_ = self.c.Helpers().Commits.CloseCommitMessagePanel()
|
||||
self.c.Helpers().Commits.CloseCommitMessagePanel()
|
||||
self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
|
||||
err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex, summary, description)
|
||||
if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil {
|
||||
return err
|
||||
}
|
||||
return self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
return nil
|
||||
})
|
||||
},
|
||||
},
|
||||
@ -228,9 +220,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
|
||||
}
|
||||
|
||||
func (self *CustomPatchOptionsMenuAction) handleApplyPatch(reverse bool) error {
|
||||
if err := self.returnFocusFromPatchExplorerIfNecessary(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.returnFocusFromPatchExplorerIfNecessary()
|
||||
|
||||
action := self.c.Tr.Actions.ApplyPatch
|
||||
if reverse {
|
||||
|
@ -505,7 +505,8 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error {
|
||||
return errors.New(self.c.Tr.FileStagingRequirements)
|
||||
}
|
||||
|
||||
return self.c.Context().Push(self.c.Contexts().Staging, opts)
|
||||
self.c.Context().Push(self.c.Contexts().Staging, opts)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *FilesController) toggleStagedAll() error {
|
||||
|
@ -116,9 +116,7 @@ func (self *FilteringMenuAction) setFiltering() error {
|
||||
repoState.SetScreenMode(types.SCREEN_HALF)
|
||||
}
|
||||
|
||||
if err := self.c.Context().Push(self.c.Contexts().LocalCommits); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
|
||||
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() error {
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
|
@ -101,10 +101,7 @@ func (self *CommitsHelper) SwitchToEditor() error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = self.CloseCommitMessagePanel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
self.CloseCommitMessagePanel()
|
||||
|
||||
return self.c.Contexts().CommitMessage.SwitchToEditor(filepath)
|
||||
}
|
||||
@ -136,9 +133,7 @@ type OpenCommitMessagePanelOpts struct {
|
||||
|
||||
func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOpts) error {
|
||||
onConfirm := func(summary string, description string) error {
|
||||
if err := self.CloseCommitMessagePanel(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.CloseCommitMessagePanel()
|
||||
|
||||
return opts.OnConfirm(summary, description)
|
||||
}
|
||||
@ -154,7 +149,8 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
|
||||
|
||||
self.UpdateCommitPanelView(opts.InitialMessage)
|
||||
|
||||
return self.c.Context().Push(self.c.Contexts().CommitMessage)
|
||||
self.c.Context().Push(self.c.Contexts().CommitMessage)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) OnCommitSuccess() {
|
||||
@ -179,7 +175,7 @@ func (self *CommitsHelper) HandleCommitConfirm() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) CloseCommitMessagePanel() error {
|
||||
func (self *CommitsHelper) CloseCommitMessagePanel() {
|
||||
if self.c.Contexts().CommitMessage.GetPreserveMessage() {
|
||||
message := self.JoinCommitMessageAndUnwrappedDescription()
|
||||
|
||||
@ -193,7 +189,7 @@ func (self *CommitsHelper) CloseCommitMessagePanel() error {
|
||||
self.c.Views().CommitMessage.Visible = false
|
||||
self.c.Views().CommitDescription.Visible = false
|
||||
|
||||
return self.c.Context().Pop()
|
||||
self.c.Context().Pop()
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.Suggestion) error {
|
||||
|
@ -28,9 +28,7 @@ func (self *ConfirmationHelper) wrappedConfirmationFunction(cancel goContext.Can
|
||||
return func() error {
|
||||
cancel()
|
||||
|
||||
if err := self.c.Context().Pop(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Pop()
|
||||
|
||||
if function != nil {
|
||||
if err := function(); err != nil {
|
||||
@ -232,7 +230,8 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
|
||||
|
||||
self.c.State().GetRepoState().SetCurrentPopupOpts(&opts)
|
||||
|
||||
return self.c.Context().Push(self.c.Contexts().Confirmation)
|
||||
self.c.Context().Push(self.c.Contexts().Confirmation)
|
||||
return nil
|
||||
}
|
||||
|
||||
func underlineLinks(text string) string {
|
||||
|
@ -137,7 +137,8 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
|
||||
}
|
||||
|
||||
self.c.Contexts().LocalCommits.SetSelection(index)
|
||||
return self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
return nil
|
||||
}
|
||||
|
||||
if warnAboutAddedLines {
|
||||
|
@ -202,7 +202,8 @@ func (self *MergeAndRebaseHelper) PromptForConflictHandling() error {
|
||||
{
|
||||
Label: self.c.Tr.ViewConflictsMenuItem,
|
||||
OnPress: func() error {
|
||||
return self.c.Context().Push(self.c.Contexts().Files)
|
||||
self.c.Context().Push(self.c.Contexts().Files)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -346,7 +347,8 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error {
|
||||
if err = self.ResetMarkedBaseCommit(); err != nil {
|
||||
return err
|
||||
}
|
||||
return self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
self.c.Context().Push(self.c.Contexts().LocalCommits)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ func (self *MergeConflictsHelper) EscapeMerge() error {
|
||||
// files context over it.
|
||||
// So long as both places call OnUIThread, we're fine.
|
||||
if self.c.Context().IsCurrent(self.c.Contexts().MergeConflicts) {
|
||||
return self.c.Context().Push(self.c.Contexts().Files)
|
||||
self.c.Context().Push(self.c.Contexts().Files)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@ -93,7 +93,8 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error {
|
||||
}
|
||||
}
|
||||
|
||||
return self.c.Context().Push(self.c.Contexts().MergeConflicts)
|
||||
self.c.Context().Push(self.c.Contexts().MergeConflicts)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *MergeConflictsHelper) context() *context.MergeConflictsContext {
|
||||
|
@ -33,8 +33,8 @@ 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.Context().Pop()
|
||||
func (self *PatchBuildingHelper) Escape() {
|
||||
self.c.Context().Pop()
|
||||
}
|
||||
|
||||
// kills the custom patch and returns us back to the commit files panel if needed
|
||||
@ -42,9 +42,7 @@ func (self *PatchBuildingHelper) Reset() error {
|
||||
self.c.Git().Patch.PatchBuilder.Reset()
|
||||
|
||||
if self.c.Context().CurrentStatic().GetKind() != types.SIDE_CONTEXT {
|
||||
if err := self.Escape(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.Escape()
|
||||
}
|
||||
|
||||
if err := self.c.Refresh(types.RefreshOptions{
|
||||
@ -64,7 +62,8 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt
|
||||
}
|
||||
|
||||
if !self.c.Git().Patch.PatchBuilder.Active() {
|
||||
return self.Escape()
|
||||
self.Escape()
|
||||
return nil
|
||||
}
|
||||
|
||||
// get diff from commit file that's currently selected
|
||||
@ -94,7 +93,8 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt
|
||||
state := patch_exploring.NewState(diff, selectedLineIdx, oldState, self.c.Log)
|
||||
context.SetState(state)
|
||||
if state == nil {
|
||||
return self.Escape()
|
||||
self.Escape()
|
||||
return nil
|
||||
}
|
||||
|
||||
mainContent := context.GetContentToRender(true)
|
||||
|
@ -115,9 +115,7 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN
|
||||
// Switch to the branches context _before_ starting to check out the
|
||||
// branch, so that we see the inline status
|
||||
if self.c.Context().Current() != self.c.Contexts().Branches {
|
||||
if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.c.Contexts().Branches)
|
||||
}
|
||||
return self.CheckoutRef(branchName, types.CheckoutRefOptions{})
|
||||
}
|
||||
@ -285,9 +283,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
|
||||
|
||||
refresh := func() error {
|
||||
if self.c.Context().Current() != self.c.Contexts().Branches {
|
||||
if err := self.c.Context().Push(self.c.Contexts().Branches); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.c.Contexts().Branches)
|
||||
}
|
||||
|
||||
self.c.Contexts().LocalCommits.SetSelection(0)
|
||||
|
@ -41,9 +41,7 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
|
||||
self.OnPromptContentChanged("")
|
||||
promptView.RenderTextArea()
|
||||
|
||||
if err := self.c.Context().Push(self.c.Contexts().Search); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.c.Contexts().Search)
|
||||
|
||||
return self.c.ResetKeybindings()
|
||||
}
|
||||
@ -60,9 +58,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err
|
||||
promptView.ClearTextArea()
|
||||
promptView.RenderTextArea()
|
||||
|
||||
if err := self.c.Context().Push(self.c.Contexts().Search); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.c.Contexts().Search)
|
||||
|
||||
return self.c.ResetKeybindings()
|
||||
}
|
||||
@ -115,11 +111,11 @@ func (self *SearchHelper) Confirm() error {
|
||||
var err error
|
||||
switch state.SearchType() {
|
||||
case types.SearchTypeFilter:
|
||||
err = self.ConfirmFilter()
|
||||
self.ConfirmFilter()
|
||||
case types.SearchTypeSearch:
|
||||
err = self.ConfirmSearch()
|
||||
case types.SearchTypeNone:
|
||||
err = self.c.Context().Pop()
|
||||
self.c.Context().Pop()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -129,14 +125,14 @@ func (self *SearchHelper) Confirm() error {
|
||||
return self.c.ResetKeybindings()
|
||||
}
|
||||
|
||||
func (self *SearchHelper) ConfirmFilter() error {
|
||||
func (self *SearchHelper) ConfirmFilter() {
|
||||
// We also do this on each keypress but we do it here again just in case
|
||||
state := self.searchState()
|
||||
|
||||
context, ok := state.Context.(types.IFilterableContext)
|
||||
if !ok {
|
||||
self.c.Log.Warnf("Context %s is not filterable", state.Context.GetKey())
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
self.OnPromptContentChanged(self.promptContent())
|
||||
@ -145,7 +141,7 @@ func (self *SearchHelper) ConfirmFilter() error {
|
||||
context.GetSearchHistory().Push(filterString)
|
||||
}
|
||||
|
||||
return self.c.Context().Pop()
|
||||
self.c.Context().Pop()
|
||||
}
|
||||
|
||||
func (self *SearchHelper) ConfirmSearch() error {
|
||||
@ -163,9 +159,7 @@ func (self *SearchHelper) ConfirmSearch() error {
|
||||
context.GetSearchHistory().Push(searchString)
|
||||
}
|
||||
|
||||
if err := self.c.Context().Pop(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Pop()
|
||||
|
||||
return context.GetView().Search(searchString, modelSearchResults(context))
|
||||
}
|
||||
@ -188,9 +182,7 @@ func modelSearchResults(context types.ISearchableContext) []gocui.SearchPosition
|
||||
func (self *SearchHelper) CancelPrompt() error {
|
||||
self.Cancel()
|
||||
|
||||
if err := self.c.Context().Pop(); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Pop()
|
||||
|
||||
return self.c.ResetKeybindings()
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) {
|
||||
}
|
||||
|
||||
if file == nil || (!file.HasUnstagedChanges && !file.HasStagedChanges) {
|
||||
_ = self.handleStagingEscape()
|
||||
self.handleStagingEscape()
|
||||
return
|
||||
}
|
||||
|
||||
@ -80,17 +80,17 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) {
|
||||
secondaryContext.GetMutex().Unlock()
|
||||
|
||||
if mainState == nil && secondaryState == nil {
|
||||
_ = self.handleStagingEscape()
|
||||
self.handleStagingEscape()
|
||||
return
|
||||
}
|
||||
|
||||
if mainState == nil && !secondaryFocused {
|
||||
_ = self.c.Context().Push(secondaryContext, focusOpts)
|
||||
self.c.Context().Push(secondaryContext, focusOpts)
|
||||
return
|
||||
}
|
||||
|
||||
if secondaryState == nil && secondaryFocused {
|
||||
_ = self.c.Context().Push(mainContext, focusOpts)
|
||||
self.c.Context().Push(mainContext, focusOpts)
|
||||
return
|
||||
}
|
||||
|
||||
@ -113,8 +113,8 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) {
|
||||
})
|
||||
}
|
||||
|
||||
func (self *StagingHelper) handleStagingEscape() error {
|
||||
return self.c.Context().Push(self.c.Contexts().Files)
|
||||
func (self *StagingHelper) handleStagingEscape() {
|
||||
self.c.Context().Push(self.c.Contexts().Files)
|
||||
}
|
||||
|
||||
func (self *StagingHelper) secondaryStagingFocused() bool {
|
||||
|
@ -72,5 +72,6 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.c.Context().Push(self.c.Contexts().SubCommits)
|
||||
self.c.Context().Push(self.c.Contexts().SubCommits)
|
||||
return nil
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ func (self *JumpToSideWindowController) goToSideWindow(window string) func() err
|
||||
|
||||
context := self.c.Helpers().Window.GetContextForWindow(window)
|
||||
|
||||
return self.c.Context().Push(context)
|
||||
self.c.Context().Push(context)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -179,9 +179,7 @@ func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error {
|
||||
|
||||
func (self *ListController) pushContextIfNotFocused() error {
|
||||
if !self.isFocused() {
|
||||
if err := self.c.Context().Push(self.context); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.context)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -78,7 +78,8 @@ func (self *MenuController) close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return self.c.Context().Pop()
|
||||
self.c.Context().Pop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *MenuController) context() *context.MenuContext {
|
||||
|
@ -188,7 +188,8 @@ func (self *MergeConflictsController) context() *context.MergeConflictsContext {
|
||||
}
|
||||
|
||||
func (self *MergeConflictsController) Escape() error {
|
||||
return self.c.Context().Pop()
|
||||
self.c.Context().Pop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *MergeConflictsController) HandleEditFile() error {
|
||||
|
@ -165,5 +165,6 @@ func (self *PatchBuildingController) Escape() error {
|
||||
return self.c.PostRefreshUpdate(context)
|
||||
}
|
||||
|
||||
return self.c.Helpers().PatchBuilding.Escape()
|
||||
self.c.Helpers().PatchBuilding.Escape()
|
||||
return nil
|
||||
}
|
||||
|
@ -150,10 +150,12 @@ func (self *PatchExplorerController) GetMouseKeybindings(opts types.KeybindingsO
|
||||
return self.withRenderAndFocus(self.HandleMouseDown)()
|
||||
}
|
||||
|
||||
return self.c.Context().Push(self.context, types.OnFocusOpts{
|
||||
self.c.Context().Push(self.context, types.OnFocusOpts{
|
||||
ClickedWindowName: self.context.GetWindowName(),
|
||||
ClickedViewLineIdx: opts.Y,
|
||||
})
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -74,7 +74,8 @@ func (self *QuitActions) Escape() error {
|
||||
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.Context().Push(parentContext)
|
||||
self.c.Context().Push(parentContext)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, mode := range self.c.Helpers().Mode.Statuses() {
|
||||
|
@ -131,7 +131,8 @@ func (self *RemotesController) enter(remote *models.Remote) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.c.Context().Push(remoteBranchesContext)
|
||||
self.c.Context().Push(remoteBranchesContext)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *RemotesController) add() error {
|
||||
|
@ -69,7 +69,8 @@ func (self *SideWindowController) previousSideWindow() error {
|
||||
|
||||
context := self.c.Helpers().Window.GetContextForWindow(newWindow)
|
||||
|
||||
return self.c.Context().Push(context)
|
||||
self.c.Context().Push(context)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SideWindowController) nextSideWindow() error {
|
||||
@ -92,5 +93,6 @@ func (self *SideWindowController) nextSideWindow() error {
|
||||
|
||||
context := self.c.Helpers().Window.GetContextForWindow(newWindow)
|
||||
|
||||
return self.c.Context().Push(context)
|
||||
self.c.Context().Push(context)
|
||||
return nil
|
||||
}
|
||||
|
@ -73,5 +73,6 @@ func (self *SnakeController) SetDirection(direction snake.Direction) func() erro
|
||||
}
|
||||
|
||||
func (self *SnakeController) Escape() error {
|
||||
return self.c.Context().Push(self.c.Contexts().Submodules)
|
||||
self.c.Context().Push(self.c.Contexts().Submodules)
|
||||
return nil
|
||||
}
|
||||
|
@ -171,12 +171,13 @@ func (self *StagingController) Escape() error {
|
||||
return self.c.PostRefreshUpdate(self.context)
|
||||
}
|
||||
|
||||
return self.c.Context().Pop()
|
||||
self.c.Context().Pop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *StagingController) TogglePanel() error {
|
||||
if self.otherContext.GetState() != nil {
|
||||
return self.c.Context().Push(self.otherContext)
|
||||
self.c.Context().Push(self.otherContext)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -104,9 +104,7 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := self.c.Context().Push(self.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Context().Push(self.Context())
|
||||
|
||||
upstreamStatus := utils.Decolorise(presentation.BranchStatus(currentBranch, types.ItemOperationNone, self.c.Tr, time.Now(), self.c.UserConfig()))
|
||||
repoName := self.c.Git().RepoPaths.RepoName()
|
||||
|
@ -285,7 +285,8 @@ func (self *SubmodulesController) remove(submodule *models.SubmoduleConfig) erro
|
||||
}
|
||||
|
||||
func (self *SubmodulesController) easterEgg() error {
|
||||
return self.c.Context().Push(self.c.Contexts().Snake)
|
||||
self.c.Context().Push(self.c.Contexts().Snake)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SubmodulesController) context() *context.SubmodulesContext {
|
||||
|
@ -72,7 +72,8 @@ 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.Context().Replace(self.c.Contexts().Confirmation)
|
||||
self.c.Context().Replace(self.c.Contexts().Confirmation)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
||||
|
@ -91,7 +91,8 @@ func (self *SwitchToDiffFilesController) enter() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.c.Context().Push(commitFilesContext)
|
||||
self.c.Context().Push(commitFilesContext)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SwitchToDiffFilesController) canEnter() *types.DisabledReason {
|
||||
|
@ -115,7 +115,8 @@ 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.Context().Push(self.c.Contexts().Branches)
|
||||
self.c.Context().Push(self.c.Contexts().Branches)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *TagsController) localDelete(tag *models.Tag) error {
|
||||
|
@ -17,9 +17,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
|
||||
OnPress: func() error {
|
||||
currentContext := gui.c.Context().CurrentStatic()
|
||||
if gui.c.State().GetShowExtrasWindow() && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
|
||||
if err := gui.c.Context().Pop(); err != nil {
|
||||
return err
|
||||
}
|
||||
gui.c.Context().Pop()
|
||||
}
|
||||
show := !gui.c.State().GetShowExtrasWindow()
|
||||
gui.c.State().SetShowExtrasWindow(show)
|
||||
@ -40,7 +38,8 @@ 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.Context().CurrentSide())
|
||||
return gui.c.Context().Push(gui.State.Contexts.CommandLog)
|
||||
gui.c.Context().Push(gui.State.Contexts.CommandLog)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) scrollUpExtra() error {
|
||||
|
@ -393,9 +393,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||
}
|
||||
}
|
||||
|
||||
if err := gui.c.Context().Push(contextToPush); err != nil {
|
||||
return err
|
||||
}
|
||||
gui.c.Context().Push(contextToPush)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -677,7 +675,7 @@ func NewGui(
|
||||
return gui.helpers.Confirmation.CreatePopupPanel(ctx, opts)
|
||||
},
|
||||
func() error { return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) },
|
||||
func() error { return gui.State.ContextMgr.Pop() },
|
||||
func() { gui.State.ContextMgr.Pop() },
|
||||
func() types.Context { return gui.State.ContextMgr.Current() },
|
||||
gui.createMenu,
|
||||
func(message string, f func(gocui.Task) error) { gui.helpers.AppStatus.WithWaitingStatus(message, f) },
|
||||
|
@ -223,9 +223,7 @@ func (gui *Gui) onInitialViewsCreationForRepo() error {
|
||||
}
|
||||
|
||||
initialContext := gui.c.Context().Current()
|
||||
if err := gui.c.Context().Activate(initialContext, types.OnFocusOpts{}); err != nil {
|
||||
return err
|
||||
}
|
||||
gui.c.Context().Activate(initialContext, types.OnFocusOpts{})
|
||||
|
||||
return gui.loadNewRepo()
|
||||
}
|
||||
|
@ -60,5 +60,6 @@ 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.Context().Push(gui.State.Contexts.Menu)
|
||||
gui.c.Context().Push(gui.State.Contexts.Menu)
|
||||
return nil
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ type PopupHandler struct {
|
||||
*common.Common
|
||||
createPopupPanelFn func(context.Context, types.CreatePopupPanelOpts) error
|
||||
onErrorFn func() error
|
||||
popContextFn func() error
|
||||
popContextFn func()
|
||||
currentContextFn func() types.Context
|
||||
createMenuFn func(types.CreateMenuOptions) error
|
||||
withWaitingStatusFn func(message string, f func(gocui.Task) error)
|
||||
@ -30,7 +30,7 @@ func NewPopupHandler(
|
||||
common *common.Common,
|
||||
createPopupPanelFn func(context.Context, types.CreatePopupPanelOpts) error,
|
||||
onErrorFn func() error,
|
||||
popContextFn func() error,
|
||||
popContextFn func(),
|
||||
currentContextFn func() types.Context,
|
||||
createMenuFn func(types.CreateMenuOptions) error,
|
||||
withWaitingStatusFn func(message string, f func(gocui.Task) error),
|
||||
|
@ -278,10 +278,10 @@ type ListItem interface {
|
||||
}
|
||||
|
||||
type IContextMgr interface {
|
||||
Push(context Context, opts ...OnFocusOpts) error
|
||||
Pop() error
|
||||
Replace(context Context) error
|
||||
Activate(context Context, opts OnFocusOpts) error
|
||||
Push(context Context, opts ...OnFocusOpts)
|
||||
Pop()
|
||||
Replace(context Context)
|
||||
Activate(context Context, opts OnFocusOpts)
|
||||
Current() Context
|
||||
CurrentStatic() Context
|
||||
CurrentSide() Context
|
||||
|
@ -72,7 +72,8 @@ func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return gui.c.Context().Push(context)
|
||||
gui.c.Context().Push(context)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) handleNextTab() error {
|
||||
|
Reference in New Issue
Block a user