diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 27c2d693c..956b67e96 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -69,7 +69,7 @@ func (gui *Gui) refreshBranches() { } gui.State.Branches = builder.Build() - if err := gui.postRefreshUpdate(gui.Contexts.Branches.Context); err != nil { + if err := gui.postRefreshUpdate(gui.Contexts.Branches); err != nil { gui.Log.Error(err) } @@ -507,8 +507,8 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error { context.GetPanelState().SetSelectedLineIdx(0) } - if context.GetKey() != gui.Contexts.Branches.Context.GetKey() { - if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil { + if context.GetKey() != gui.Contexts.Branches.GetKey() { + if err := gui.pushContext(gui.Contexts.Branches); err != nil { return err } } diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index c72ee3b13..626fe173c 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -107,7 +107,7 @@ func (gui *Gui) refreshCommitFilesView() error { } gui.State.CommitFileManager.SetFiles(files, to) - return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context) + return gui.postRefreshUpdate(gui.Contexts.CommitFiles) } func (gui *Gui) handleOpenOldCommitFile() error { @@ -167,7 +167,7 @@ func (gui *Gui) handleToggleFileForPatch() error { gui.GitCommand.PatchManager.Reset() } - return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context) + return gui.postRefreshUpdate(gui.Contexts.CommitFiles) } if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileManager.GetParent() { @@ -215,7 +215,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { } } - if err := gui.pushContext(gui.Contexts.PatchBuilding.Context); err != nil { + if err := gui.pushContext(gui.Contexts.PatchBuilding); err != nil { return err } return gui.handleRefreshPatchBuildingPanel(selectedLineIdx) @@ -231,7 +231,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { return enterTheFile(selectedLineIdx) }, handleClose: func() error { - return gui.pushContext(gui.Contexts.CommitFiles.Context) + return gui.pushContext(gui.Contexts.CommitFiles) }, }) } @@ -247,7 +247,7 @@ func (gui *Gui) handleToggleCommitFileDirCollapsed() error { gui.State.CommitFileManager.ToggleCollapsed(node.GetPath()) - if err := gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context); err != nil { + if err := gui.postRefreshUpdate(gui.Contexts.CommitFiles); err != nil { gui.Log.Error(err) } @@ -262,14 +262,14 @@ func (gui *Gui) switchToCommitFilesContext(refName string, canRebase bool, conte gui.State.Panels.CommitFiles.SelectedLineIdx = 0 gui.State.Panels.CommitFiles.refName = refName gui.State.Panels.CommitFiles.canRebase = canRebase - gui.Contexts.CommitFiles.Context.SetParentContext(context) - gui.Contexts.CommitFiles.Context.SetWindowName(windowName) + gui.Contexts.CommitFiles.SetParentContext(context) + gui.Contexts.CommitFiles.SetWindowName(windowName) if err := gui.refreshCommitFilesView(); err != nil { return err } - return gui.pushContext(gui.Contexts.CommitFiles.Context) + return gui.pushContext(gui.Contexts.CommitFiles) } // NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics @@ -283,12 +283,12 @@ func (gui *Gui) handleToggleCommitFileTreeView() error { gui.State.CommitFileManager.ExpandToPath(path) index, found := gui.State.CommitFileManager.GetIndexForPath(path) if found { - gui.commitFilesListContext().GetPanelState().SetSelectedLineIdx(index) + gui.Contexts.CommitFiles.GetPanelState().SetSelectedLineIdx(index) } } if gui.getCommitFilesView().Context == COMMIT_FILES_CONTEXT_KEY { - if err := gui.Contexts.CommitFiles.Context.HandleRender(); err != nil { + if err := gui.Contexts.CommitFiles.HandleRender(); err != nil { return err } } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 811c8613d..8edcc642d 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -12,7 +12,7 @@ import ( func (gui *Gui) getSelectedLocalCommit() *models.Commit { selectedLine := gui.State.Panels.Commits.SelectedLineIdx - if selectedLine == -1 { + if selectedLine == -1 || selectedLine > len(gui.State.Commits)-1 { return nil } @@ -38,7 +38,7 @@ func (gui *Gui) handleCommitSelect() error { task = gui.createRenderStringTask(gui.Tr.NoCommitsThisBranch) } else { cmd := gui.OSCommand.ExecutableFromString( - gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path), + gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()), ) task = gui.createRunPtyTask(cmd) } @@ -86,7 +86,7 @@ func (gui *Gui) refreshCommits() error { go utils.Safe(func() { _ = gui.refreshCommitsWithLimit() - context, ok := gui.Contexts.CommitFiles.Context.GetParentContext() + context, ok := gui.Contexts.CommitFiles.GetParentContext() if ok && context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { // This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA 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 @@ -117,7 +117,7 @@ func (gui *Gui) refreshCommitsWithLimit() error { commits, err := builder.GetCommits( commands.GetCommitsOptions{ Limit: gui.State.Panels.Commits.LimitCommits, - FilterPath: gui.State.Modes.Filtering.Path, + FilterPath: gui.State.Modes.Filtering.GetPath(), IncludeRebaseCommits: true, RefName: "HEAD", }, @@ -127,7 +127,7 @@ func (gui *Gui) refreshCommitsWithLimit() error { } gui.State.Commits = commits - return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context) + return gui.postRefreshUpdate(gui.Contexts.BranchCommits) } func (gui *Gui) refreshRebaseCommits() error { @@ -142,7 +142,7 @@ func (gui *Gui) refreshRebaseCommits() error { } gui.State.Commits = updatedCommits - return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context) + return gui.postRefreshUpdate(gui.Contexts.BranchCommits) } // specific functions @@ -444,7 +444,7 @@ func (gui *Gui) handleViewCommitFiles() error { return nil } - return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits.Context, "commits") + return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits, "commits") } func (gui *Gui) handleCreateFixupCommit() error { diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 74c4cc9d6..c52a32ce3 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -204,7 +204,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, f } gui.g.Update(func(g *gocui.Gui) error { - return gui.pushContext(gui.Contexts.Confirmation.Context) + return gui.pushContext(gui.Contexts.Confirmation) }) return confirmationView, nil } @@ -284,7 +284,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { { viewName: "confirmation", key: gui.getKey(keybindingConfig.Universal.TogglePanel), - handler: func() error { return gui.replaceContext(gui.Contexts.Suggestions.Context) }, + handler: func() error { return gui.replaceContext(gui.Contexts.Suggestions) }, }, { viewName: "suggestions", @@ -304,7 +304,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { { viewName: "suggestions", key: gui.getKey(keybindingConfig.Universal.TogglePanel), - handler: func() error { return gui.replaceContext(gui.Contexts.Confirmation.Context) }, + handler: func() error { return gui.replaceContext(gui.Contexts.Confirmation) }, }, } diff --git a/pkg/gui/context.go b/pkg/gui/context.go index d76747d74..8b2015711 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -65,62 +65,54 @@ var allContextKeys = []string{ SUGGESTIONS_CONTEXT_KEY, } -type SimpleContextNode struct { - Context Context -} - -type RemotesContextNode struct { - Context Context - Branches SimpleContextNode -} - type ContextTree struct { - Status SimpleContextNode - Files SimpleContextNode - Submodules SimpleContextNode - Menu SimpleContextNode - Branches SimpleContextNode - Remotes RemotesContextNode - Tags SimpleContextNode - BranchCommits SimpleContextNode - CommitFiles SimpleContextNode - ReflogCommits SimpleContextNode - SubCommits SimpleContextNode - Stash SimpleContextNode - Normal SimpleContextNode - Staging SimpleContextNode - PatchBuilding SimpleContextNode - Merging SimpleContextNode - Credentials SimpleContextNode - Confirmation SimpleContextNode - CommitMessage SimpleContextNode - Search SimpleContextNode - Suggestions SimpleContextNode + Status Context + Files *ListContext + Submodules *ListContext + Menu *ListContext + Branches *ListContext + Remotes *ListContext + RemoteBranches *ListContext + Tags *ListContext + BranchCommits *ListContext + CommitFiles *ListContext + ReflogCommits *ListContext + SubCommits *ListContext + Stash *ListContext + Suggestions *ListContext + Normal Context + Staging Context + PatchBuilding Context + Merging Context + Credentials Context + Confirmation Context + CommitMessage Context + Search Context } func (gui *Gui) allContexts() []Context { return []Context{ - gui.Contexts.Status.Context, - gui.Contexts.Files.Context, - gui.Contexts.Submodules.Context, - gui.Contexts.Branches.Context, - gui.Contexts.Remotes.Context, - gui.Contexts.Remotes.Branches.Context, - gui.Contexts.Tags.Context, - gui.Contexts.BranchCommits.Context, - gui.Contexts.CommitFiles.Context, - gui.Contexts.ReflogCommits.Context, - gui.Contexts.Stash.Context, - gui.Contexts.Menu.Context, - gui.Contexts.Confirmation.Context, - gui.Contexts.Credentials.Context, - gui.Contexts.CommitMessage.Context, - gui.Contexts.Normal.Context, - gui.Contexts.Staging.Context, - gui.Contexts.Merging.Context, - gui.Contexts.PatchBuilding.Context, - gui.Contexts.SubCommits.Context, - gui.Contexts.Suggestions.Context, + gui.Contexts.Status, + gui.Contexts.Files, + gui.Contexts.Submodules, + gui.Contexts.Branches, + gui.Contexts.Remotes, + gui.Contexts.RemoteBranches, + gui.Contexts.Tags, + gui.Contexts.BranchCommits, + gui.Contexts.CommitFiles, + gui.Contexts.ReflogCommits, + gui.Contexts.Stash, + gui.Contexts.Menu, + gui.Contexts.Confirmation, + gui.Contexts.Credentials, + gui.Contexts.CommitMessage, + gui.Contexts.Normal, + gui.Contexts.Staging, + gui.Contexts.Merging, + gui.Contexts.PatchBuilding, + gui.Contexts.SubCommits, + gui.Contexts.Suggestions, } } @@ -206,145 +198,101 @@ func (c BasicContext) GetKey() string { func (gui *Gui) contextTree() ContextTree { return ContextTree{ - Status: SimpleContextNode{ - Context: BasicContext{ - OnFocus: gui.handleStatusSelect, - Kind: SIDE_CONTEXT, - ViewName: "status", - Key: STATUS_CONTEXT_KEY, + Status: BasicContext{ + OnFocus: gui.handleStatusSelect, + Kind: SIDE_CONTEXT, + ViewName: "status", + Key: STATUS_CONTEXT_KEY, + }, + Files: gui.filesListContext(), + Submodules: gui.submodulesListContext(), + Menu: gui.menuListContext(), + Remotes: gui.remotesListContext(), + RemoteBranches: gui.remoteBranchesListContext(), + BranchCommits: gui.branchCommitsListContext(), + CommitFiles: gui.commitFilesListContext(), + ReflogCommits: gui.reflogCommitsListContext(), + SubCommits: gui.subCommitsListContext(), + Branches: gui.branchesListContext(), + Tags: gui.tagsListContext(), + Stash: gui.stashListContext(), + Normal: BasicContext{ + OnFocus: func() error { + return nil // TODO: should we do something here? We should allow for scrolling the panel }, + Kind: MAIN_CONTEXT, + ViewName: "main", + Key: MAIN_NORMAL_CONTEXT_KEY, }, - Files: SimpleContextNode{ - Context: gui.filesListContext(), - }, - Submodules: SimpleContextNode{ - Context: gui.submodulesListContext(), - }, - Menu: SimpleContextNode{ - Context: gui.menuListContext(), - }, - Remotes: RemotesContextNode{ - Context: gui.remotesListContext(), - Branches: SimpleContextNode{ - Context: gui.remoteBranchesListContext(), + Staging: BasicContext{ + OnFocus: func() error { + return nil + // TODO: centralise the code here + // return gui.refreshStagingPanel(false, -1) }, + Kind: MAIN_CONTEXT, + ViewName: "main", + Key: MAIN_STAGING_CONTEXT_KEY, }, - BranchCommits: SimpleContextNode{ - Context: gui.branchCommitsListContext(), - }, - CommitFiles: SimpleContextNode{ - Context: gui.commitFilesListContext(), - }, - ReflogCommits: SimpleContextNode{ - Context: gui.reflogCommitsListContext(), - }, - SubCommits: SimpleContextNode{ - Context: gui.subCommitsListContext(), - }, - Branches: SimpleContextNode{ - Context: gui.branchesListContext(), - }, - Tags: SimpleContextNode{ - Context: gui.tagsListContext(), - }, - Stash: SimpleContextNode{ - Context: gui.stashListContext(), - }, - Normal: SimpleContextNode{ - Context: BasicContext{ - OnFocus: func() error { - return nil // TODO: should we do something here? We should allow for scrolling the panel - }, - Kind: MAIN_CONTEXT, - ViewName: "main", - Key: MAIN_NORMAL_CONTEXT_KEY, + PatchBuilding: BasicContext{ + OnFocus: func() error { + return nil + // TODO: centralise the code here + // return gui.refreshPatchBuildingPanel(-1) }, + Kind: MAIN_CONTEXT, + ViewName: "main", + Key: MAIN_PATCH_BUILDING_CONTEXT_KEY, }, - Staging: SimpleContextNode{ - Context: BasicContext{ - OnFocus: func() error { - return nil - // TODO: centralise the code here - // return gui.refreshStagingPanel(false, -1) - }, - Kind: MAIN_CONTEXT, - ViewName: "main", - Key: MAIN_STAGING_CONTEXT_KEY, - }, + Merging: BasicContext{ + OnFocus: gui.refreshMergePanelWithLock, + Kind: MAIN_CONTEXT, + ViewName: "main", + Key: MAIN_MERGING_CONTEXT_KEY, + OnGetOptionsMap: gui.getMergingOptions, }, - PatchBuilding: SimpleContextNode{ - Context: BasicContext{ - OnFocus: func() error { - return nil - // TODO: centralise the code here - // return gui.refreshPatchBuildingPanel(-1) - }, - Kind: MAIN_CONTEXT, - ViewName: "main", - Key: MAIN_PATCH_BUILDING_CONTEXT_KEY, - }, + Credentials: BasicContext{ + OnFocus: gui.handleCredentialsViewFocused, + Kind: PERSISTENT_POPUP, + ViewName: "credentials", + Key: CREDENTIALS_CONTEXT_KEY, }, - Merging: SimpleContextNode{ - Context: BasicContext{ - OnFocus: gui.refreshMergePanelWithLock, - Kind: MAIN_CONTEXT, - ViewName: "main", - Key: MAIN_MERGING_CONTEXT_KEY, - OnGetOptionsMap: gui.getMergingOptions, - }, + Confirmation: BasicContext{ + OnFocus: func() error { return nil }, + Kind: TEMPORARY_POPUP, + ViewName: "confirmation", + Key: CONFIRMATION_CONTEXT_KEY, }, - Credentials: SimpleContextNode{ - Context: BasicContext{ - OnFocus: gui.handleCredentialsViewFocused, - Kind: PERSISTENT_POPUP, - ViewName: "credentials", - Key: CREDENTIALS_CONTEXT_KEY, - }, + Suggestions: gui.suggestionsListContext(), + CommitMessage: BasicContext{ + OnFocus: gui.handleCommitMessageFocused, + Kind: PERSISTENT_POPUP, + ViewName: "commitMessage", + Key: COMMIT_MESSAGE_CONTEXT_KEY, }, - Confirmation: SimpleContextNode{ - Context: BasicContext{ - OnFocus: func() error { return nil }, - Kind: TEMPORARY_POPUP, - ViewName: "confirmation", - Key: CONFIRMATION_CONTEXT_KEY, - }, - }, - Suggestions: SimpleContextNode{ - Context: gui.suggestionsListContext(), - }, - CommitMessage: SimpleContextNode{ - Context: BasicContext{ - OnFocus: gui.handleCommitMessageFocused, - Kind: PERSISTENT_POPUP, - ViewName: "commitMessage", - Key: COMMIT_MESSAGE_CONTEXT_KEY, - }, - }, - Search: SimpleContextNode{ - Context: BasicContext{ - OnFocus: func() error { return nil }, - Kind: PERSISTENT_POPUP, - ViewName: "search", - Key: SEARCH_CONTEXT_KEY, - }, + Search: BasicContext{ + OnFocus: func() error { return nil }, + Kind: PERSISTENT_POPUP, + ViewName: "search", + Key: SEARCH_CONTEXT_KEY, }, } } func (gui *Gui) initialViewContextMap() map[string]Context { return map[string]Context{ - "status": gui.Contexts.Status.Context, - "files": gui.Contexts.Files.Context, - "branches": gui.Contexts.Branches.Context, - "commits": gui.Contexts.BranchCommits.Context, - "commitFiles": gui.Contexts.CommitFiles.Context, - "stash": gui.Contexts.Stash.Context, - "menu": gui.Contexts.Menu.Context, - "confirmation": gui.Contexts.Confirmation.Context, - "credentials": gui.Contexts.Credentials.Context, - "commitMessage": gui.Contexts.CommitMessage.Context, - "main": gui.Contexts.Normal.Context, - "secondary": gui.Contexts.Normal.Context, + "status": gui.Contexts.Status, + "files": gui.Contexts.Files, + "branches": gui.Contexts.Branches, + "commits": gui.Contexts.BranchCommits, + "commitFiles": gui.Contexts.CommitFiles, + "stash": gui.Contexts.Stash, + "menu": gui.Contexts.Menu, + "confirmation": gui.Contexts.Confirmation, + "credentials": gui.Contexts.Credentials, + "commitMessage": gui.Contexts.CommitMessage, + "main": gui.Contexts.Normal, + "secondary": gui.Contexts.Normal, } } @@ -353,41 +301,41 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext { "branches": { { tab: "Local Branches", - contexts: []Context{gui.Contexts.Branches.Context}, + contexts: []Context{gui.Contexts.Branches}, }, { tab: "Remotes", contexts: []Context{ - gui.Contexts.Remotes.Context, - gui.Contexts.Remotes.Branches.Context, + gui.Contexts.Remotes, + gui.Contexts.RemoteBranches, }, }, { tab: "Tags", - contexts: []Context{gui.Contexts.Tags.Context}, + contexts: []Context{gui.Contexts.Tags}, }, }, "commits": { { tab: "Commits", - contexts: []Context{gui.Contexts.BranchCommits.Context}, + contexts: []Context{gui.Contexts.BranchCommits}, }, { tab: "Reflog", contexts: []Context{ - gui.Contexts.ReflogCommits.Context, + gui.Contexts.ReflogCommits, }, }, }, "files": { { tab: "Files", - contexts: []Context{gui.Contexts.Files.Context}, + contexts: []Context{gui.Contexts.Files}, }, { tab: "Submodules", contexts: []Context{ - gui.Contexts.Submodules.Context, + gui.Contexts.Submodules, }, }, }, @@ -623,7 +571,7 @@ func (gui *Gui) currentSideContext() *ListContext { } func (gui *Gui) defaultSideContext() Context { - return gui.Contexts.Files.Context + return gui.Contexts.Files } func (gui *Gui) setInitialViewContexts() { @@ -684,7 +632,7 @@ func (gui *Gui) onViewFocusLost(v *gocui.View, newView *gocui.View) error { if v.Name() == "commitFiles" && newView.Name() != "main" && newView.Name() != "secondary" { gui.resetWindowForView("commitFiles") - if err := gui.deactivateContext(gui.Contexts.CommitFiles.Context); err != nil { + if err := gui.deactivateContext(gui.Contexts.CommitFiles); err != nil { return err } } diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go index d79d4cf67..2f2585bcf 100644 --- a/pkg/gui/credentials_panel.go +++ b/pkg/gui/credentials_panel.go @@ -26,7 +26,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string { credentialsView.Mask = '*' } - if err := gui.pushContext(gui.Contexts.Credentials.Context); err != nil { + if err := gui.pushContext(gui.Contexts.Credentials); err != nil { return err } diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go index 5bce9fe44..bd29664fe 100644 --- a/pkg/gui/diffing.go +++ b/pkg/gui/diffing.go @@ -94,7 +94,7 @@ func (gui *Gui) diffStr() string { if file != "" { output += " -- " + file } else if gui.State.Modes.Filtering.Active() { - output += " -- " + gui.State.Modes.Filtering.Path + output += " -- " + gui.State.Modes.Filtering.GetPath() } return output diff --git a/pkg/gui/errors.go b/pkg/gui/errors.go index e0f37d3ea..651b964c2 100644 --- a/pkg/gui/errors.go +++ b/pkg/gui/errors.go @@ -26,7 +26,6 @@ func (gui *Gui) GenerateSentinelErrors() { gui.Errors = SentinelErrors{ ErrNoFiles: errors.New(gui.Tr.NoChangedFiles), ErrSwitchRepo: errors.New("switching repo"), - ErrRestart: errors.New("restarting"), } } @@ -34,6 +33,5 @@ func (gui *Gui) sentinelErrorsArr() []error { return []error{ gui.Errors.ErrNoFiles, gui.Errors.ErrSwitchRepo, - gui.Errors.ErrRestart, } } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 59ec172b3..d95875d5e 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -124,13 +124,13 @@ func (gui *Gui) refreshFilesAndSubmodules() error { } gui.g.Update(func(g *gocui.Gui) error { - if err := gui.postRefreshUpdate(gui.Contexts.Submodules.Context); err != nil { + if err := gui.postRefreshUpdate(gui.Contexts.Submodules); err != nil { gui.Log.Error(err) } if gui.getFilesView().Context == FILES_CONTEXT_KEY { // doing this a little custom (as opposed to using gui.postRefreshUpdate) because we handle selecting the file explicitly below - if err := gui.Contexts.Files.Context.HandleRender(); err != nil { + if err := gui.Contexts.Files.HandleRender(); err != nil { return err } } @@ -210,7 +210,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error if file.HasMergeConflicts { return gui.createErrorPanel(gui.Tr.FileStagingRequirements) } - _ = gui.pushContext(gui.Contexts.Staging.Context) + _ = gui.pushContext(gui.Contexts.Staging) return gui.handleRefreshStagingPanel(forceSecondaryFocused, selectedLineIdx) // TODO: check if this is broken, try moving into context code } @@ -412,7 +412,7 @@ func (gui *Gui) handleCommitPress() error { } gui.g.Update(func(g *gocui.Gui) error { - if err := gui.pushContext(gui.Contexts.CommitMessage.Context); err != nil { + if err := gui.pushContext(gui.Contexts.CommitMessage); err != nil { return err } @@ -777,7 +777,7 @@ func (gui *Gui) handleSwitchToMerge() error { return gui.createErrorPanel(gui.Tr.FileNoMergeCons) } - return gui.pushContext(gui.Contexts.Merging.Context) + return gui.pushContext(gui.Contexts.Merging) } func (gui *Gui) openFile(filename string) error { @@ -842,7 +842,7 @@ func (gui *Gui) handleToggleDirCollapsed() error { gui.State.FileManager.ToggleCollapsed(node.GetPath()) - if err := gui.postRefreshUpdate(gui.Contexts.Files.Context); err != nil { + if err := gui.postRefreshUpdate(gui.Contexts.Files); err != nil { gui.Log.Error(err) } @@ -865,7 +865,7 @@ func (gui *Gui) handleToggleFileTreeView() error { } if gui.getFilesView().Context == FILES_CONTEXT_KEY { - if err := gui.Contexts.Files.Context.HandleRender(); err != nil { + if err := gui.Contexts.Files.HandleRender(); err != nil { return err } } diff --git a/pkg/gui/filtering.go b/pkg/gui/filtering.go index bf44ec0bc..b3fa0e089 100644 --- a/pkg/gui/filtering.go +++ b/pkg/gui/filtering.go @@ -14,6 +14,29 @@ func (gui *Gui) validateNotInFilterMode() (bool, error) { } func (gui *Gui) exitFilterMode() error { - gui.State.Modes.Filtering.Path = "" - return gui.Errors.ErrRestart + return gui.clearFiltering() +} + +func (gui *Gui) clearFiltering() error { + gui.State.Modes.Filtering.Reset() + if gui.State.ScreenMode == SCREEN_HALF { + gui.State.ScreenMode = SCREEN_NORMAL + } + + return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{COMMITS}}) +} + +func (gui *Gui) setFiltering(path string) error { + gui.State.Modes.Filtering.SetPath(path) + if gui.State.ScreenMode == SCREEN_NORMAL { + gui.State.ScreenMode = SCREEN_HALF + } + + if err := gui.pushContext(gui.Contexts.BranchCommits); err != nil { + return err + } + + return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{COMMITS}, then: func() { + gui.Contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) + }}) } diff --git a/pkg/gui/filtering_menu_panel.go b/pkg/gui/filtering_menu_panel.go index 75c1e1c86..935b58af1 100644 --- a/pkg/gui/filtering_menu_panel.go +++ b/pkg/gui/filtering_menu_panel.go @@ -30,8 +30,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error { menuItems = append(menuItems, &menuItem{ displayString: fmt.Sprintf("%s '%s'", gui.Tr.LcFilterBy, fileName), onPress: func() error { - gui.State.Modes.Filtering.Path = fileName - return gui.Errors.ErrRestart + return gui.setFiltering(fileName) }, }) } @@ -42,8 +41,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error { return gui.prompt(promptOpts{ title: gui.Tr.LcEnterFileName, handleConfirm: func(response string) error { - gui.State.Modes.Filtering.Path = strings.TrimSpace(response) - return gui.Errors.ErrRestart + return gui.setFiltering(strings.TrimSpace(response)) }, }) }, @@ -52,10 +50,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error { if gui.State.Modes.Filtering.Active() { menuItems = append(menuItems, &menuItem{ displayString: gui.Tr.LcExitFilterMode, - onPress: func() error { - gui.State.Modes.Filtering.Path = "" - return gui.Errors.ErrRestart - }, + onPress: gui.clearFiltering, }) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 2e58f430d..a9343d115 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -20,6 +20,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/filetree" + "github.com/jesseduffield/lazygit/pkg/gui/modes/filtering" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/tasks" @@ -232,14 +233,6 @@ func (m *Diffing) Active() bool { return m.Ref != "" } -type Filtering struct { - Path string // the filename that gets passed to git log -} - -func (m *Filtering) Active() bool { - return m.Path != "" -} - type CherryPicking struct { CherryPickedCommits []*models.Commit @@ -252,7 +245,7 @@ func (m *CherryPicking) Active() bool { } type Modes struct { - Filtering Filtering + Filtering filtering.Filtering CherryPicking CherryPicking Diffing Diffing } @@ -320,9 +313,7 @@ type guiState struct { func (gui *Gui) resetState() { // we carry over the filter path and diff state - prevFiltering := Filtering{ - Path: "", - } + prevFiltering := filtering.NewFiltering() prevDiff := Diffing{} prevCherryPicking := CherryPicking{ CherryPickedCommits: make([]*models.Commit, 0), @@ -380,6 +371,12 @@ func (gui *Gui) resetState() { ViewContextMap: gui.initialViewContextMap(), RepoPathStack: prevRepoPathStack, } + + if gui.State.Modes.Filtering.Active() { + gui.State.ScreenMode = SCREEN_HALF + } else { + gui.State.ScreenMode = SCREEN_NORMAL + } } // for now the split view will always be on @@ -399,7 +396,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom } gui.resetState() - gui.State.Modes.Filtering.Path = filterPath + gui.State.Modes.Filtering.SetPath(filterPath) gui.Contexts = gui.contextTree() gui.ViewTabContextMap = gui.viewTabContextMap() @@ -427,12 +424,6 @@ func (gui *Gui) Run() error { go utils.Safe(gui.recordEvents) } - if gui.State.Modes.Filtering.Active() { - gui.State.ScreenMode = SCREEN_HALF - } else { - gui.State.ScreenMode = SCREEN_NORMAL - } - g.OnSearchEscape = gui.onSearchEscape if err := gui.Config.ReloadUserConfig(); err != nil { return nil @@ -509,7 +500,7 @@ func (gui *Gui) RunWithRestarts() error { } return nil - case gui.Errors.ErrSwitchRepo, gui.Errors.ErrRestart: + case gui.Errors.ErrSwitchRepo: continue default: return err diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 2594cb9ad..32ad1de85 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -152,7 +152,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { branchesView.ContainsList = true } - commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.Context.GetWindowName(), true) + commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.GetWindowName(), true) if err != nil { if err.Error() != UNKNOWN_VIEW_ERROR_MSG { return err @@ -272,9 +272,9 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if gui.g.CurrentView() == nil { - initialContext := gui.Contexts.Files.Context + initialContext := gui.Contexts.Files if gui.State.Modes.Filtering.Active() { - initialContext = gui.Contexts.BranchCommits.Context + initialContext = gui.Contexts.BranchCommits } if err := gui.pushContext(initialContext); err != nil { @@ -282,41 +282,24 @@ func (gui *Gui) layout(g *gocui.Gui) error { } } - type listContextState struct { - view *gocui.View - listContext *ListContext - } - - // TODO: don't we already have the view included in the context object itself? Or might that change in a way we don't want reflected here? - listContextStates := []listContextState{ - {view: filesView, listContext: gui.filesListContext()}, - {view: filesView, listContext: gui.submodulesListContext()}, - {view: branchesView, listContext: gui.branchesListContext()}, - {view: branchesView, listContext: gui.remotesListContext()}, - {view: branchesView, listContext: gui.remoteBranchesListContext()}, - {view: branchesView, listContext: gui.tagsListContext()}, - {view: commitsView, listContext: gui.branchCommitsListContext()}, - {view: commitsView, listContext: gui.reflogCommitsListContext()}, - {view: stashView, listContext: gui.stashListContext()}, - {view: commitFilesView, listContext: gui.commitFilesListContext()}, - } - - // menu view might not exist so we check to be safe - if menuView, err := gui.g.View("menu"); err == nil { - listContextStates = append(listContextStates, listContextState{view: menuView, listContext: gui.menuListContext()}) - } - for _, listContextState := range listContextStates { - // ignore contexts whose view is owned by another context right now - if listContextState.view.Context != listContextState.listContext.GetKey() { + for _, listContext := range gui.getListContexts() { + view, err := gui.g.View(listContext.ViewName) + if err != nil { continue } - // check if the selected line is now out of view and if so refocus it - listContextState.view.FocusPoint(0, listContextState.listContext.GetPanelState().GetSelectedLineIdx()) - listContextState.view.SelBgColor = theme.GocuiSelectedLineBgColor + // ignore contexts whose view is owned by another context right now + if view.Context != listContext.GetKey() { + continue + } + + // check if the selected line is now out of view and if so refocus it + view.FocusPoint(0, listContext.GetPanelState().GetSelectedLineIdx()) + + view.SelBgColor = theme.GocuiSelectedLineBgColor // I doubt this is expensive though it's admittedly redundant after the first render - listContextState.view.SetOnSelectItem(gui.onSelectItemWrapper(listContextState.listContext.onSearchSelect)) + view.SetOnSelectItem(gui.onSelectItemWrapper(listContext.onSearchSelect)) } gui.getMainView().SetOnSelectItem(gui.onSelectItemWrapper(gui.handlelineByLineNavigateTo)) diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index fd06d0f14..3d5536ec1 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -238,7 +238,7 @@ func (gui *Gui) refreshMainViewForLineByLine(state *lBlPanelState) error { var includedLineIndices []int // I'd prefer not to have knowledge of contexts using this file but I'm not sure // how to get around this - if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() { + if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.GetKey() { filename := gui.getSelectedCommitFileName() var err error includedLineIndices, err = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename) @@ -341,9 +341,9 @@ func (gui *Gui) handleOpenFileAtLine() error { // again, would be good to use inheritance here (or maybe even composition) var filename string switch gui.State.MainContext { - case gui.Contexts.PatchBuilding.Context.GetKey(): + case gui.Contexts.PatchBuilding.GetKey(): filename = gui.getSelectedCommitFileName() - case gui.Contexts.Staging.Context.GetKey(): + case gui.Contexts.Staging.GetKey(): file := gui.getSelectedFile() if file == nil { return nil diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 7f78f5a97..34e1a7171 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -530,20 +530,20 @@ func (gui *Gui) suggestionsListContext() *ListContext { func (gui *Gui) getListContexts() []*ListContext { return []*ListContext{ - gui.Contexts.Menu.Context.(*ListContext), - gui.Contexts.Files.Context.(*ListContext), - gui.Contexts.Branches.Context.(*ListContext), - gui.Contexts.Remotes.Context.(*ListContext), - gui.Contexts.Remotes.Branches.Context.(*ListContext), - gui.Contexts.Tags.Context.(*ListContext), - gui.Contexts.BranchCommits.Context.(*ListContext), - gui.Contexts.BranchCommits.Context.(*ListContext), - gui.Contexts.ReflogCommits.Context.(*ListContext), - gui.Contexts.SubCommits.Context.(*ListContext), - gui.Contexts.Stash.Context.(*ListContext), - gui.Contexts.CommitFiles.Context.(*ListContext), - gui.Contexts.Submodules.Context.(*ListContext), - gui.Contexts.Suggestions.Context.(*ListContext), + gui.Contexts.Menu, + gui.Contexts.Files, + gui.Contexts.Branches, + gui.Contexts.Remotes, + gui.Contexts.RemoteBranches, + gui.Contexts.Tags, + gui.Contexts.BranchCommits, + gui.Contexts.BranchCommits, + gui.Contexts.ReflogCommits, + gui.Contexts.SubCommits, + gui.Contexts.Stash, + gui.Contexts.CommitFiles, + gui.Contexts.Submodules, + gui.Contexts.Suggestions, } } @@ -553,6 +553,8 @@ func (gui *Gui) getListContextKeyBindings() []*Binding { keybindingConfig := gui.Config.GetUserConfig().Keybinding for _, listContext := range gui.getListContexts() { + listContext := listContext + bindings = append(bindings, []*Binding{ {ViewName: listContext.ViewName, Tag: "navigation", Contexts: []string{listContext.ContextKey}, Key: gui.getKey(keybindingConfig.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine}, {ViewName: listContext.ViewName, Tag: "navigation", Contexts: []string{listContext.ContextKey}, Key: gui.getKey(keybindingConfig.Universal.PrevItem), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine}, diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 143fd7bf1..c5dd0aed7 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -88,7 +88,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr gui.State.Panels.Menu.SelectedLineIdx = 0 gui.g.Update(func(g *gocui.Gui) error { - return gui.pushContext(gui.Contexts.Menu.Context) + return gui.pushContext(gui.Contexts.Menu) }) return nil } diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index 37ad6725a..ba204e41d 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -270,7 +270,7 @@ func (gui *Gui) handleEscapeMerge() error { // it's possible this method won't be called from the merging view so we need to // ensure we only 'return' focus if we already have it if gui.g.CurrentView() == gui.getMainView() { - return gui.pushContext(gui.Contexts.Files.Context) + return gui.pushContext(gui.Contexts.Files) } return nil } @@ -303,14 +303,14 @@ func (gui *Gui) promptToContinueRebase() error { prompt: gui.Tr.ConflictsResolved, handlersManageFocus: true, handleConfirm: func() error { - if err := gui.pushContext(gui.Contexts.Files.Context); err != nil { + if err := gui.pushContext(gui.Contexts.Files); err != nil { return err } return gui.genericMergeCommand("continue") }, handleClose: func() error { - return gui.pushContext(gui.Contexts.Files.Context) + return gui.pushContext(gui.Contexts.Files) }, }) } diff --git a/pkg/gui/modes.go b/pkg/gui/modes.go index 03ac76dd3..5f783c4eb 100644 --- a/pkg/gui/modes.go +++ b/pkg/gui/modes.go @@ -29,7 +29,7 @@ func (gui *Gui) modeStatuses() []modeStatus { isActive: gui.State.Modes.Filtering.Active, description: func() string { return utils.ColoredString( - fmt.Sprintf("%s '%s' %s", gui.Tr.LcFilteringBy, gui.State.Modes.Filtering.Path, utils.ColoredString(gui.Tr.ResetInParentheses, color.Underline)), + fmt.Sprintf("%s '%s' %s", gui.Tr.LcFilteringBy, gui.State.Modes.Filtering.GetPath(), utils.ColoredString(gui.Tr.ResetInParentheses, color.Underline)), color.FgRed, color.Bold, ) diff --git a/pkg/gui/modes/filtering/filtering.go b/pkg/gui/modes/filtering/filtering.go new file mode 100644 index 000000000..da6c97a90 --- /dev/null +++ b/pkg/gui/modes/filtering/filtering.go @@ -0,0 +1,25 @@ +package filtering + +type Filtering struct { + path string // the filename that gets passed to git log +} + +func NewFiltering() Filtering { + return Filtering{path: ""} +} + +func (m *Filtering) Active() bool { + return m.path != "" +} + +func (m *Filtering) Reset() { + m.path = "" +} + +func (m *Filtering) SetPath(path string) { + m.path = path +} + +func (m *Filtering) GetPath() string { + return m.path +} diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index e1fb823fb..094799022 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -109,8 +109,8 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error { gui.GitCommand.PatchManager.Reset() } - if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() { - return gui.pushContext(gui.Contexts.CommitFiles.Context) + if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.GetKey() { + return gui.pushContext(gui.Contexts.CommitFiles) } else { // need to re-focus in case the secondary view should now be hidden return gui.currentContext().HandleFocus() diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index a340efc2a..b6a373ed9 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -42,7 +42,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error { }, }...) - if gui.currentContext().GetKey() == gui.Contexts.BranchCommits.Context.GetKey() { + if gui.currentContext().GetKey() == gui.Contexts.BranchCommits.GetKey() { selectedCommit := gui.getSelectedLocalCommit() if selectedCommit != nil && gui.GitCommand.PatchManager.To != selectedCommit.Sha { // adding this option to index 1 @@ -179,7 +179,7 @@ func (gui *Gui) handleApplyPatch(reverse bool) error { func (gui *Gui) handleResetPatch() error { gui.GitCommand.PatchManager.Reset() if gui.currentContextKeyIgnoringPopups() == MAIN_PATCH_BUILDING_CONTEXT_KEY { - if err := gui.pushContext(gui.Contexts.CommitFiles.Context); err != nil { + if err := gui.pushContext(gui.Contexts.CommitFiles); err != nil { return err } } diff --git a/pkg/gui/rebase_options_panel.go b/pkg/gui/rebase_options_panel.go index 01f91d3cb..77b36be8a 100644 --- a/pkg/gui/rebase_options_panel.go +++ b/pkg/gui/rebase_options_panel.go @@ -80,7 +80,7 @@ func (gui *Gui) handleGenericMergeCommandResult(result error) error { prompt: gui.Tr.FoundConflicts, handlersManageFocus: true, handleConfirm: func() error { - return gui.pushContext(gui.Contexts.Files.Context) + return gui.pushContext(gui.Contexts.Files) }, handleClose: func() error { if err := gui.returnFromContext(); err != nil { diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 018098d23..691e63d68 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -73,7 +73,7 @@ func (gui *Gui) dispatchSwitchToRepo(path string) error { return err } gui.GitCommand = newGitCommand - gui.State.Modes.Filtering.Path = "" + gui.State.Modes.Filtering.Reset() return gui.Errors.ErrSwitchRepo } diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index 89293f6b4..3fd3277dc 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -23,7 +23,7 @@ func (gui *Gui) handleReflogCommitSelect() error { task = gui.createRenderStringTask("No reflog history") } else { cmd := gui.OSCommand.ExecutableFromString( - gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path), + gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()), ) task = gui.createRunPtyTask(cmd) @@ -72,14 +72,14 @@ func (gui *Gui) refreshReflogCommits() error { } if gui.State.Modes.Filtering.Active() { - if err := refresh(&state.FilteredReflogCommits, state.Modes.Filtering.Path); err != nil { + if err := refresh(&state.FilteredReflogCommits, state.Modes.Filtering.GetPath()); err != nil { return err } } else { state.FilteredReflogCommits = state.ReflogCommits } - return gui.postRefreshUpdate(gui.Contexts.ReflogCommits.Context) + return gui.postRefreshUpdate(gui.Contexts.ReflogCommits) } func (gui *Gui) handleCheckoutReflogCommit() error { @@ -116,5 +116,5 @@ func (gui *Gui) handleViewReflogCommitFiles() error { return nil } - return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.ReflogCommits.Context, "commits") + return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.ReflogCommits, "commits") } diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 2c0aa074a..88b093e09 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -39,7 +39,7 @@ func (gui *Gui) handleRemoteBranchSelect() error { } func (gui *Gui) handleRemoteBranchesEscape() error { - return gui.pushContext(gui.Contexts.Remotes.Context) + return gui.pushContext(gui.Contexts.Remotes) } func (gui *Gui) handleMergeRemoteBranch() error { diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 3c18aa212..2ef1d415b 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -80,7 +80,7 @@ func (gui *Gui) handleRemoteEnter() error { } gui.State.Panels.RemoteBranches.SelectedLineIdx = newSelectedLine - return gui.pushContext(gui.Contexts.Remotes.Branches.Context) + return gui.pushContext(gui.Contexts.RemoteBranches) } func (gui *Gui) handleAddRemote() error { diff --git a/pkg/gui/reset_menu_panel.go b/pkg/gui/reset_menu_panel.go index 58dabf0cd..5ddabcd17 100644 --- a/pkg/gui/reset_menu_panel.go +++ b/pkg/gui/reset_menu_panel.go @@ -17,7 +17,7 @@ func (gui *Gui) resetToRef(ref string, strength string, options oscommands.RunCo // loading a heap of commits is slow so we limit them whenever doing a reset gui.State.Panels.Commits.LimitCommits = true - if err := gui.pushContext(gui.Contexts.BranchCommits.Context); err != nil { + if err := gui.pushContext(gui.Contexts.BranchCommits); err != nil { return err } diff --git a/pkg/gui/searching.go b/pkg/gui/searching.go index fdb61a70f..a21e83d3b 100644 --- a/pkg/gui/searching.go +++ b/pkg/gui/searching.go @@ -18,7 +18,7 @@ func (gui *Gui) handleOpenSearch(viewName string) error { gui.renderString("search", "") - if err := gui.pushContext(gui.Contexts.Search.Context); err != nil { + if err := gui.pushContext(gui.Contexts.Search); err != nil { return err } diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index d021525dc..617a4c203 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -84,7 +84,7 @@ func (gui *Gui) handleTogglePanel() error { func (gui *Gui) handleStagingEscape() error { gui.escapeLineByLinePanel() - return gui.pushContext(gui.Contexts.Files.Context) + return gui.pushContext(gui.Contexts.Files) } func (gui *Gui) handleToggleStagedSelection() error { @@ -107,7 +107,7 @@ func (gui *Gui) handleResetSelection() error { handlersManageFocus: true, handleConfirm: func() error { return gui.withLBLActiveCheck(func(state *lBlPanelState) error { - if err := gui.pushContext(gui.Contexts.Staging.Context); err != nil { + if err := gui.pushContext(gui.Contexts.Staging); err != nil { return err } @@ -115,7 +115,7 @@ func (gui *Gui) handleResetSelection() error { }) }, handleClose: func() error { - return gui.pushContext(gui.Contexts.Staging.Context) + return gui.pushContext(gui.Contexts.Staging) }, }) } else { diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index deaf5790e..b76beec60 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -37,9 +37,9 @@ func (gui *Gui) handleStashEntrySelect() error { } func (gui *Gui) refreshStashEntries() error { - gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.Modes.Filtering.Path) + gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.Modes.Filtering.GetPath()) - return gui.Contexts.Stash.Context.HandleRender() + return gui.Contexts.Stash.HandleRender() } // specific functions @@ -134,5 +134,5 @@ func (gui *Gui) handleViewStashFiles() error { return nil } - return gui.switchToCommitFilesContext(stashEntry.RefName(), false, gui.Contexts.Stash.Context, "stash") + return gui.switchToCommitFilesContext(stashEntry.RefName(), false, gui.Contexts.Stash, "stash") } diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index f1a52f38a..7ebe53ef3 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -73,7 +73,7 @@ func (gui *Gui) handleStatusClick() error { return nil } - if err := gui.pushContext(gui.Contexts.Status.Context); err != nil { + if err := gui.pushContext(gui.Contexts.Status); err != nil { return err } diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go index b133a250b..8e063ed94 100644 --- a/pkg/gui/sub_commits_panel.go +++ b/pkg/gui/sub_commits_panel.go @@ -24,7 +24,7 @@ func (gui *Gui) handleSubCommitSelect() error { task = gui.createRenderStringTask("No commits") } else { cmd := gui.OSCommand.ExecutableFromString( - gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path), + gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()), ) task = gui.createRunPtyTask(cmd) @@ -72,7 +72,7 @@ func (gui *Gui) handleViewSubCommitFiles() error { return nil } - return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.SubCommits.Context, "branches") + return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.SubCommits, "branches") } func (gui *Gui) switchToSubCommitsContext(refName string) error { @@ -82,7 +82,7 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error { commits, err := builder.GetCommits( commands.GetCommitsOptions{ Limit: gui.State.Panels.Commits.LimitCommits, - FilterPath: gui.State.Modes.Filtering.Path, + FilterPath: gui.State.Modes.Filtering.GetPath(), IncludeRebaseCommits: false, RefName: refName, }, @@ -94,9 +94,9 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error { gui.State.SubCommits = commits gui.State.Panels.SubCommits.refName = refName gui.State.Panels.SubCommits.SelectedLineIdx = 0 - gui.Contexts.SubCommits.Context.SetParentContext(gui.currentSideContext()) + gui.Contexts.SubCommits.SetParentContext(gui.currentSideContext()) - return gui.pushContext(gui.Contexts.SubCommits.Context) + return gui.pushContext(gui.Contexts.SubCommits) } func (gui *Gui) handleSwitchToSubCommits() error { diff --git a/pkg/gui/suggestions_panel.go b/pkg/gui/suggestions_panel.go index 8ca0fcb56..891225170 100644 --- a/pkg/gui/suggestions_panel.go +++ b/pkg/gui/suggestions_panel.go @@ -32,5 +32,5 @@ func (gui *Gui) setSuggestions(suggestions []*types.Suggestion) { gui.State.Suggestions = suggestions gui.State.Panels.Suggestions.SelectedLineIdx = 0 _ = gui.resetOrigin(view) - _ = gui.Contexts.Suggestions.Context.HandleRender() + _ = gui.Contexts.Suggestions.HandleRender() } diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go index 0ea86ad2b..fe74a1b1f 100644 --- a/pkg/gui/tags_panel.go +++ b/pkg/gui/tags_panel.go @@ -44,7 +44,7 @@ func (gui *Gui) refreshTags() error { gui.State.Tags = tags - return gui.postRefreshUpdate(gui.Contexts.Tags.Context) + return gui.postRefreshUpdate(gui.Contexts.Tags) } func (gui *Gui) handleCheckoutTag() error { @@ -55,7 +55,7 @@ func (gui *Gui) handleCheckoutTag() error { if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{}); err != nil { return err } - return gui.pushContext(gui.Contexts.Branches.Context) + return gui.pushContext(gui.Contexts.Branches) } func (gui *Gui) handleDeleteTag() error { @@ -123,7 +123,7 @@ func (gui *Gui) handleCreateTag() error { for i, tag := range gui.State.Tags { if tag.Name == tagName { gui.State.Panels.Tags.SelectedLineIdx = i - if err := gui.Contexts.Tags.Context.HandleRender(); err != nil { + if err := gui.Contexts.Tags.HandleRender(); err != nil { gui.Log.Error(err) } diff --git a/pkg/gui/window.go b/pkg/gui/window.go index c3fffc637..6717807c3 100644 --- a/pkg/gui/window.go +++ b/pkg/gui/window.go @@ -17,7 +17,7 @@ func (gui *Gui) getViewNameForWindow(window string) string { func (gui *Gui) getWindowForViewName(viewName string) string { if viewName == "commitFiles" { - return gui.Contexts.CommitFiles.Context.GetWindowName() + return gui.Contexts.CommitFiles.GetWindowName() } return viewName