1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-01 13:17:53 +02:00

move context keys into context package

This commit is contained in:
Jesse Duffield 2022-01-29 19:15:46 +11:00
parent 138be04e65
commit e363606fb6
19 changed files with 257 additions and 243 deletions

View File

@ -2,6 +2,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/boxlayout"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -139,7 +140,7 @@ func (gui *Gui) getExtrasWindowSize(screenHeight int) int {
}
var baseSize int
if gui.currentStaticContext().GetKey() == COMMAND_LOG_CONTEXT_KEY {
if gui.currentStaticContext().GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
baseSize = 1000 // my way of saying 'fill the available space'
} else if screenHeight < 40 {
baseSize = 1

View File

@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@ -409,9 +410,9 @@ func (gui *Gui) handleRenameBranch() error {
}
func (gui *Gui) handleNewBranchOffCurrentItem() error {
context := gui.currentSideListContext()
ctx := gui.currentSideListContext()
item, ok := context.GetSelectedItem()
item, ok := ctx.GetSelectedItem()
if !ok {
return nil
}
@ -424,7 +425,7 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
)
prefilledName := ""
if context.GetKey() == REMOTE_BRANCHES_CONTEXT_KEY {
if ctx.GetKey() == context.REMOTE_BRANCHES_CONTEXT_KEY {
// will set to the remote's branch name without the remote name
prefilledName = strings.SplitAfterN(item.ID(), "/", 2)[1]
}
@ -440,11 +441,11 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
// if we're currently in the branch commits context then the selected commit
// is about to go to the top of the list
if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
context.GetPanelState().SetSelectedLineIdx(0)
if ctx.GetKey() == context.BRANCH_COMMITS_CONTEXT_KEY {
ctx.GetPanelState().SetSelectedLineIdx(0)
}
if context.GetKey() != gui.State.Contexts.Branches.GetKey() {
if ctx.GetKey() != gui.State.Contexts.Branches.GetKey() {
if err := gui.c.PushContext(gui.State.Contexts.Branches); err != nil {
return err
}

View File

@ -2,6 +2,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -62,21 +63,21 @@ func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
}
func (gui *Gui) commitsListForContext() []*models.Commit {
context := gui.currentSideListContext()
if context == nil {
ctx := gui.currentSideListContext()
if ctx == nil {
return nil
}
// using a switch statement, but we should use polymorphism
switch context.GetKey() {
case BRANCH_COMMITS_CONTEXT_KEY:
switch ctx.GetKey() {
case context.BRANCH_COMMITS_CONTEXT_KEY:
return gui.State.Commits
case REFLOG_COMMITS_CONTEXT_KEY:
case context.REFLOG_COMMITS_CONTEXT_KEY:
return gui.State.FilteredReflogCommits
case SUB_COMMITS_CONTEXT_KEY:
case context.SUB_COMMITS_CONTEXT_KEY:
return gui.State.SubCommits
default:
gui.c.Log.Errorf("no commit list for context %s", context.GetKey())
gui.c.Log.Errorf("no commit list for context %s", ctx.GetKey())
return nil
}
}

View File

@ -3,6 +3,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@ -100,7 +101,7 @@ func (gui *Gui) handleDiscardOldFileChange() error {
func (gui *Gui) refreshCommitFilesView() error {
currentSideContext := gui.currentSideContext()
if currentSideContext.GetKey() == COMMIT_FILES_CONTEXT_KEY || currentSideContext.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
if currentSideContext.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || currentSideContext.GetKey() == context.BRANCH_COMMITS_CONTEXT_KEY {
if err := gui.handleRefreshPatchBuildingPanel(-1); err != nil {
return err
}

View File

@ -5,6 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -91,8 +92,8 @@ func (gui *Gui) refreshCommits() {
go utils.Safe(func() {
_ = gui.refreshCommitsWithLimit()
context, ok := gui.State.Contexts.CommitFiles.GetParentContext()
if ok && context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
ctx, ok := gui.State.Contexts.CommitFiles.GetParentContext()
if ok && ctx.GetKey() == context.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
// showing the contents of a different commit than the one we initially entered.

View File

@ -5,7 +5,7 @@ import (
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/popup"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
@ -138,7 +138,7 @@ func (gui *Gui) prepareConfirmationPanel(
return nil
}
func (gui *Gui) createPopupPanel(opts popup.CreatePopupPanelOpts) error {
func (gui *Gui) createPopupPanel(opts types.CreatePopupPanelOpts) error {
// remove any previous keybindings
gui.clearConfirmationViewKeyBindings()
@ -174,7 +174,7 @@ func (gui *Gui) createPopupPanel(opts popup.CreatePopupPanelOpts) error {
return gui.c.PushContext(gui.State.Contexts.Confirmation)
}
func (gui *Gui) setKeyBindings(opts popup.CreatePopupPanelOpts) error {
func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
actions := utils.ResolvePlaceholderString(
gui.c.Tr.CloseConfirm,
map[string]string{
@ -201,25 +201,25 @@ func (gui *Gui) setKeyBindings(opts popup.CreatePopupPanelOpts) error {
bindings := []*types.Binding{
{
ViewName: "confirmation",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Confirm),
Handler: onConfirm,
},
{
ViewName: "confirmation",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
Handler: onConfirm,
},
{
ViewName: "confirmation",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Return),
Handler: gui.wrappedConfirmationFunction(opts.HandlersManageFocus, opts.HandleClose),
},
{
ViewName: "confirmation",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
Handler: func() error {
if len(gui.State.Suggestions) > 0 {
@ -230,25 +230,25 @@ func (gui *Gui) setKeyBindings(opts popup.CreatePopupPanelOpts) error {
},
{
ViewName: "suggestions",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Confirm),
Handler: onSuggestionConfirm,
},
{
ViewName: "suggestions",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
Handler: onSuggestionConfirm,
},
{
ViewName: "suggestions",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Return),
Handler: gui.wrappedConfirmationFunction(opts.HandlersManageFocus, opts.HandleClose),
},
{
ViewName: "suggestions",
Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
Handler: func() error { return gui.replaceContext(gui.State.Contexts.Confirmation) },
},

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -130,7 +131,7 @@ func (gui *Gui) deactivateContext(c types.Context) error {
}
// if we are the kind of context that is sent to back upon deactivation, we should do that
if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || c.GetKey() == COMMIT_FILES_CONTEXT_KEY) {
if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || c.GetKey() == context.COMMIT_FILES_CONTEXT_KEY) {
view.Visible = false
}
@ -181,7 +182,7 @@ func (gui *Gui) activateContext(c types.Context, opts ...types.OnFocusOpts) erro
if viewName == "main" {
gui.changeMainViewsContext(c.GetKey())
} else {
gui.changeMainViewsContext(MAIN_NORMAL_CONTEXT_KEY)
gui.changeMainViewsContext(context.MAIN_NORMAL_CONTEXT_KEY)
}
gui.setViewTabForContext(c)
@ -382,7 +383,7 @@ func (gui *Gui) changeMainViewsContext(contextKey types.ContextKey) {
}
switch contextKey {
case MAIN_NORMAL_CONTEXT_KEY, MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY, MAIN_MERGING_CONTEXT_KEY:
case context.MAIN_NORMAL_CONTEXT_KEY, context.MAIN_PATCH_BUILDING_CONTEXT_KEY, context.MAIN_STAGING_CONTEXT_KEY, context.MAIN_MERGING_CONTEXT_KEY:
gui.Views.Main.Context = string(contextKey)
gui.Views.Secondary.Context = string(contextKey)
default:

View File

@ -2,6 +2,58 @@ package context
import "github.com/jesseduffield/lazygit/pkg/gui/types"
const (
STATUS_CONTEXT_KEY types.ContextKey = "status"
FILES_CONTEXT_KEY types.ContextKey = "files"
LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
REMOTES_CONTEXT_KEY types.ContextKey = "remotes"
REMOTE_BRANCHES_CONTEXT_KEY types.ContextKey = "remoteBranches"
TAGS_CONTEXT_KEY types.ContextKey = "tags"
BRANCH_COMMITS_CONTEXT_KEY types.ContextKey = "commits"
REFLOG_COMMITS_CONTEXT_KEY types.ContextKey = "reflogCommits"
SUB_COMMITS_CONTEXT_KEY types.ContextKey = "subCommits"
COMMIT_FILES_CONTEXT_KEY types.ContextKey = "commitFiles"
STASH_CONTEXT_KEY types.ContextKey = "stash"
MAIN_NORMAL_CONTEXT_KEY types.ContextKey = "normal"
MAIN_MERGING_CONTEXT_KEY types.ContextKey = "merging"
MAIN_PATCH_BUILDING_CONTEXT_KEY types.ContextKey = "patchBuilding"
MAIN_STAGING_CONTEXT_KEY types.ContextKey = "staging"
MENU_CONTEXT_KEY types.ContextKey = "menu"
CREDENTIALS_CONTEXT_KEY types.ContextKey = "credentials"
CONFIRMATION_CONTEXT_KEY types.ContextKey = "confirmation"
SEARCH_CONTEXT_KEY types.ContextKey = "search"
COMMIT_MESSAGE_CONTEXT_KEY types.ContextKey = "commitMessage"
SUBMODULES_CONTEXT_KEY types.ContextKey = "submodules"
SUGGESTIONS_CONTEXT_KEY types.ContextKey = "suggestions"
COMMAND_LOG_CONTEXT_KEY types.ContextKey = "cmdLog"
)
var AllContextKeys = []types.ContextKey{
STATUS_CONTEXT_KEY,
FILES_CONTEXT_KEY,
LOCAL_BRANCHES_CONTEXT_KEY,
REMOTES_CONTEXT_KEY,
REMOTE_BRANCHES_CONTEXT_KEY,
TAGS_CONTEXT_KEY,
BRANCH_COMMITS_CONTEXT_KEY,
REFLOG_COMMITS_CONTEXT_KEY,
SUB_COMMITS_CONTEXT_KEY,
COMMIT_FILES_CONTEXT_KEY,
STASH_CONTEXT_KEY,
MAIN_NORMAL_CONTEXT_KEY,
MAIN_MERGING_CONTEXT_KEY,
MAIN_PATCH_BUILDING_CONTEXT_KEY,
MAIN_STAGING_CONTEXT_KEY,
MENU_CONTEXT_KEY,
CREDENTIALS_CONTEXT_KEY,
CONFIRMATION_CONTEXT_KEY,
SEARCH_CONTEXT_KEY,
COMMIT_MESSAGE_CONTEXT_KEY,
SUBMODULES_CONTEXT_KEY,
SUGGESTIONS_CONTEXT_KEY,
COMMAND_LOG_CONTEXT_KEY,
}
type ContextTree struct {
Status types.Context
Files types.IListContext

View File

@ -5,58 +5,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
const (
STATUS_CONTEXT_KEY types.ContextKey = "status"
FILES_CONTEXT_KEY types.ContextKey = "files"
LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
REMOTES_CONTEXT_KEY types.ContextKey = "remotes"
REMOTE_BRANCHES_CONTEXT_KEY types.ContextKey = "remoteBranches"
TAGS_CONTEXT_KEY types.ContextKey = "tags"
BRANCH_COMMITS_CONTEXT_KEY types.ContextKey = "commits"
REFLOG_COMMITS_CONTEXT_KEY types.ContextKey = "reflogCommits"
SUB_COMMITS_CONTEXT_KEY types.ContextKey = "subCommits"
COMMIT_FILES_CONTEXT_KEY types.ContextKey = "commitFiles"
STASH_CONTEXT_KEY types.ContextKey = "stash"
MAIN_NORMAL_CONTEXT_KEY types.ContextKey = "normal"
MAIN_MERGING_CONTEXT_KEY types.ContextKey = "merging"
MAIN_PATCH_BUILDING_CONTEXT_KEY types.ContextKey = "patchBuilding"
MAIN_STAGING_CONTEXT_KEY types.ContextKey = "staging"
MENU_CONTEXT_KEY types.ContextKey = "menu"
CREDENTIALS_CONTEXT_KEY types.ContextKey = "credentials"
CONFIRMATION_CONTEXT_KEY types.ContextKey = "confirmation"
SEARCH_CONTEXT_KEY types.ContextKey = "search"
COMMIT_MESSAGE_CONTEXT_KEY types.ContextKey = "commitMessage"
SUBMODULES_CONTEXT_KEY types.ContextKey = "submodules"
SUGGESTIONS_CONTEXT_KEY types.ContextKey = "suggestions"
COMMAND_LOG_CONTEXT_KEY types.ContextKey = "cmdLog"
)
var AllContextKeys = []types.ContextKey{
STATUS_CONTEXT_KEY,
FILES_CONTEXT_KEY,
LOCAL_BRANCHES_CONTEXT_KEY,
REMOTES_CONTEXT_KEY,
REMOTE_BRANCHES_CONTEXT_KEY,
TAGS_CONTEXT_KEY,
BRANCH_COMMITS_CONTEXT_KEY,
REFLOG_COMMITS_CONTEXT_KEY,
SUB_COMMITS_CONTEXT_KEY,
COMMIT_FILES_CONTEXT_KEY,
STASH_CONTEXT_KEY,
MAIN_NORMAL_CONTEXT_KEY,
MAIN_MERGING_CONTEXT_KEY,
MAIN_PATCH_BUILDING_CONTEXT_KEY,
MAIN_STAGING_CONTEXT_KEY,
MENU_CONTEXT_KEY,
CREDENTIALS_CONTEXT_KEY,
CONFIRMATION_CONTEXT_KEY,
SEARCH_CONTEXT_KEY,
COMMIT_MESSAGE_CONTEXT_KEY,
SUBMODULES_CONTEXT_KEY,
SUGGESTIONS_CONTEXT_KEY,
COMMAND_LOG_CONTEXT_KEY,
}
func (gui *Gui) allContexts() []types.Context {
return []types.Context{
gui.State.Contexts.Status,
@ -90,7 +38,7 @@ func (gui *Gui) contextTree() context.ContextTree {
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.SIDE_CONTEXT,
ViewName: "status",
Key: STATUS_CONTEXT_KEY,
Key: context.STATUS_CONTEXT_KEY,
WindowName: "status",
}),
NewSimpleContextOpts{
@ -115,7 +63,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
Key: MAIN_NORMAL_CONTEXT_KEY,
Key: context.MAIN_NORMAL_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: func(opts ...types.OnFocusOpts) error {
@ -128,7 +76,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
Key: MAIN_STAGING_CONTEXT_KEY,
Key: context.MAIN_STAGING_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: func(opts ...types.OnFocusOpts) error {
@ -151,7 +99,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
Key: MAIN_PATCH_BUILDING_CONTEXT_KEY,
Key: context.MAIN_PATCH_BUILDING_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: func(opts ...types.OnFocusOpts) error {
@ -169,7 +117,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
Key: MAIN_MERGING_CONTEXT_KEY,
Key: context.MAIN_MERGING_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
}),
NewSimpleContextOpts{
@ -181,7 +129,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.PERSISTENT_POPUP,
ViewName: "credentials",
WindowName: "credentials",
Key: CREDENTIALS_CONTEXT_KEY,
Key: context.CREDENTIALS_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: OnFocusWrapper(gui.handleAskFocused),
@ -192,7 +140,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.TEMPORARY_POPUP,
ViewName: "confirmation",
WindowName: "confirmation",
Key: CONFIRMATION_CONTEXT_KEY,
Key: context.CONFIRMATION_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: OnFocusWrapper(gui.handleAskFocused),
@ -203,7 +151,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.PERSISTENT_POPUP,
ViewName: "commitMessage",
WindowName: "commitMessage",
Key: COMMIT_MESSAGE_CONTEXT_KEY,
Key: context.COMMIT_MESSAGE_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: OnFocusWrapper(gui.handleCommitMessageFocused),
@ -214,7 +162,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.PERSISTENT_POPUP,
ViewName: "search",
WindowName: "search",
Key: SEARCH_CONTEXT_KEY,
Key: context.SEARCH_CONTEXT_KEY,
}),
NewSimpleContextOpts{},
),
@ -223,7 +171,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.EXTRAS_CONTEXT,
ViewName: "extras",
WindowName: "extras",
Key: COMMAND_LOG_CONTEXT_KEY,
Key: context.COMMAND_LOG_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
}),
NewSimpleContextOpts{

View File

@ -12,6 +12,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@ -314,11 +315,11 @@ func (gui *Gui) GetCustomCommandKeybindings() []*types.Binding {
case "":
log.Fatalf("Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s", customCommand.Key, customCommand.Command)
default:
context, ok := gui.contextForContextKey(types.ContextKey(customCommand.Context))
ctx, ok := gui.contextForContextKey(types.ContextKey(customCommand.Context))
// stupid golang making me build an array of strings for this.
allContextKeyStrings := make([]string, len(AllContextKeys))
for i := range AllContextKeys {
allContextKeyStrings[i] = string(AllContextKeys[i])
allContextKeyStrings := make([]string, len(context.AllContextKeys))
for i := range context.AllContextKeys {
allContextKeyStrings[i] = string(context.AllContextKeys[i])
}
if !ok {
log.Fatalf("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s", customCommand.Context, customCommand.Key, customCommand.Command, strings.Join(allContextKeyStrings, ", "))
@ -326,7 +327,7 @@ func (gui *Gui) GetCustomCommandKeybindings() []*types.Binding {
// here we assume that a given context will always belong to the same view.
// Currently this is a safe bet but it's by no means guaranteed in the long term
// and we might need to make some changes in the future to support it.
viewName = context.GetViewName()
viewName = ctx.GetViewName()
contexts = []string{customCommand.Context}
}

View File

@ -3,17 +3,18 @@ package gui
import (
"errors"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
var CONTEXT_KEYS_SHOWING_DIFFS = []types.ContextKey{
FILES_CONTEXT_KEY,
COMMIT_FILES_CONTEXT_KEY,
STASH_CONTEXT_KEY,
BRANCH_COMMITS_CONTEXT_KEY,
SUB_COMMITS_CONTEXT_KEY,
MAIN_STAGING_CONTEXT_KEY,
MAIN_PATCH_BUILDING_CONTEXT_KEY,
context.FILES_CONTEXT_KEY,
context.COMMIT_FILES_CONTEXT_KEY,
context.STASH_CONTEXT_KEY,
context.BRANCH_COMMITS_CONTEXT_KEY,
context.SUB_COMMITS_CONTEXT_KEY,
context.MAIN_STAGING_CONTEXT_KEY,
context.MAIN_PATCH_BUILDING_CONTEXT_KEY,
}
func isShowingDiff(gui *Gui) bool {
@ -59,9 +60,9 @@ func (gui *Gui) handleDiffContextSizeChange() error {
currentContext := gui.currentStaticContext()
switch currentContext.GetKey() {
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
case MAIN_PATCH_BUILDING_CONTEXT_KEY:
case context.MAIN_PATCH_BUILDING_CONTEXT_KEY:
return gui.handleRefreshPatchBuildingPanel(-1)
case MAIN_STAGING_CONTEXT_KEY:
case context.MAIN_STAGING_CONTEXT_KEY:
return gui.handleRefreshStagingPanel(false, -1)
default:
return currentContext.HandleRenderToMain()

View File

@ -6,13 +6,13 @@ package gui
// +++ b/pkg/gui/diff_context_size.go
// @@ -9,12 +9,12 @@ func getRefreshFunction(gui *Gui) func()error {
// }
// } else if key == MAIN_STAGING_CONTEXT_KEY {
// } else if key == context.MAIN_STAGING_CONTEXT_KEY {
// return func() error {
// - selectedLine := gui.Views.Secondary.SelectedLineIdx()
// + selectedLine := gui.State.Panels.LineByLine.GetSelectedLineIdx()
// return gui.handleRefreshStagingPanel(false, selectedLine)
// }
// } else if key == MAIN_PATCH_BUILDING_CONTEXT_KEY {
// } else if key == context.MAIN_PATCH_BUILDING_CONTEXT_KEY {
// `
// func setupGuiForTest(gui *Gui) {

View File

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -35,12 +36,12 @@ func (gui *Gui) currentDiffTerminals() []string {
switch gui.currentContext().GetKey() {
case "":
return nil
case FILES_CONTEXT_KEY, SUBMODULES_CONTEXT_KEY:
case context.FILES_CONTEXT_KEY, context.SUBMODULES_CONTEXT_KEY:
// TODO: should we just return nil here?
return []string{""}
case COMMIT_FILES_CONTEXT_KEY:
case context.COMMIT_FILES_CONTEXT_KEY:
return []string{gui.State.Panels.CommitFiles.refName}
case LOCAL_BRANCHES_CONTEXT_KEY:
case context.LOCAL_BRANCHES_CONTEXT_KEY:
// for our local branches we want to include both the branch and its upstream
branch := gui.getSelectedBranch()
if branch != nil {
@ -74,7 +75,7 @@ func (gui *Gui) currentDiffTerminal() string {
func (gui *Gui) currentlySelectedFilename() string {
switch gui.currentContext().GetKey() {
case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
case context.FILES_CONTEXT_KEY, context.COMMIT_FILES_CONTEXT_KEY:
return gui.getSideContextSelectedItemId()
default:
return ""

View File

@ -3,6 +3,7 @@ package gui
import (
"io"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -15,7 +16,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
DisplayString: gui.c.Tr.ToggleShowCommandLog,
OnPress: func() error {
currentContext := gui.currentStaticContext()
if gui.ShowExtrasWindow && currentContext.GetKey() == COMMAND_LOG_CONTEXT_KEY {
if gui.ShowExtrasWindow && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
if err := gui.returnFromContext(); err != nil {
return err
}

View File

@ -5,6 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@ -113,14 +114,14 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
gui.c.Log.Error(err)
}
if types.ContextKey(gui.Views.Files.Context) == FILES_CONTEXT_KEY {
if types.ContextKey(gui.Views.Files.Context) == context.FILES_CONTEXT_KEY {
// doing this a little custom (as opposed to using gui.c.PostRefreshUpdate) because we handle selecting the file explicitly below
if err := gui.State.Contexts.Files.HandleRender(); err != nil {
return err
}
}
if gui.currentContext().GetKey() == FILES_CONTEXT_KEY {
if gui.currentContext().GetKey() == context.FILES_CONTEXT_KEY {
currentSelectedPath := gui.getSelectedPath()
alreadySelected := prevSelectedPath != "" && currentSelectedPath == prevSelectedPath
if !alreadySelected {

View File

@ -9,6 +9,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -355,7 +356,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "files",
Contexts: []string{string(FILES_CONTEXT_KEY)},
Contexts: []string{string(context.FILES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Remove),
Handler: gui.handleCreateDiscardMenu,
Description: gui.c.Tr.LcViewDiscardOptions,
@ -363,7 +364,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "files",
Contexts: []string{string(FILES_CONTEXT_KEY)},
Contexts: []string{string(context.FILES_CONTEXT_KEY)},
Key: gui.getKey(config.Files.ViewResetOptions),
Handler: gui.handleCreateResetMenu,
Description: gui.c.Tr.LcViewResetOptions,
@ -371,35 +372,35 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "files",
Contexts: []string{string(FILES_CONTEXT_KEY)},
Contexts: []string{string(context.FILES_CONTEXT_KEY)},
Key: gui.getKey(config.Files.Fetch),
Handler: gui.handleGitFetch,
Description: gui.c.Tr.LcFetch,
},
{
ViewName: "files",
Contexts: []string{string(FILES_CONTEXT_KEY)},
Contexts: []string{string(context.FILES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Handler: gui.handleCopySelectedSideContextItemToClipboard,
Description: gui.c.Tr.LcCopyFileNameToClipboard,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
Handler: gui.handleBranchPress,
Description: gui.c.Tr.LcCheckout,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.CreatePullRequest),
Handler: gui.handleCreatePullRequestPress,
Description: gui.c.Tr.LcCreatePullRequest,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.ViewPullRequestOptions),
Handler: gui.handleCreatePullRequestMenu,
Description: gui.c.Tr.LcCreatePullRequestOptions,
@ -407,56 +408,56 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.CopyPullRequestURL),
Handler: gui.handleCopyPullRequestURLPress,
Description: gui.c.Tr.LcCopyPullRequestURL,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.CheckoutBranchByName),
Handler: gui.handleCheckoutByName,
Description: gui.c.Tr.LcCheckoutByName,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.ForceCheckoutBranch),
Handler: gui.handleForceCheckout,
Description: gui.c.Tr.LcForceCheckout,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.New),
Handler: gui.handleNewBranchOffCurrentItem,
Description: gui.c.Tr.LcNewBranch,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Remove),
Handler: gui.handleDeleteBranch,
Description: gui.c.Tr.LcDeleteBranch,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.RebaseBranch),
Handler: guards.OutsideFilterMode(gui.handleRebaseOntoLocalBranch),
Description: gui.c.Tr.LcRebaseBranch,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.MergeIntoCurrentBranch),
Handler: guards.OutsideFilterMode(gui.handleMerge),
Description: gui.c.Tr.LcMergeIntoCurrentBranch,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.ViewGitFlowOptions),
Handler: gui.handleCreateGitFlowMenu,
Description: gui.c.Tr.LcGitFlowOptions,
@ -464,14 +465,14 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.FastForward),
Handler: gui.handleFastForward,
Description: gui.c.Tr.FastForward,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateResetToBranchMenu,
Description: gui.c.Tr.LcViewResetOptions,
@ -479,35 +480,35 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.RenameBranch),
Handler: gui.handleRenameBranch,
Description: gui.c.Tr.LcRenameBranch,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Handler: gui.handleCopySelectedSideContextItemToClipboard,
Description: gui.c.Tr.LcCopyBranchNameToClipboard,
},
{
ViewName: "branches",
Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GoInto),
Handler: gui.handleSwitchToSubCommits,
Description: gui.c.Tr.LcViewCommits,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Return),
Handler: gui.handleRemoteBranchesEscape,
Description: gui.c.Tr.ReturnToRemotesList,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateResetToRemoteBranchMenu,
Description: gui.c.Tr.LcViewResetOptions,
@ -515,42 +516,42 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GoInto),
Handler: gui.handleSwitchToSubCommits,
Description: gui.c.Tr.LcViewCommits,
},
{
ViewName: "commits",
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.CherryPickCopy),
Handler: gui.handleCopyCommit,
Description: gui.c.Tr.LcCherryPickCopy,
},
{
ViewName: "commits",
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Handler: gui.handleCopySelectedSideContextItemToClipboard,
Description: gui.c.Tr.LcCopyCommitShaToClipboard,
},
{
ViewName: "commits",
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.CherryPickCopyRange),
Handler: gui.handleCopyCommitRange,
Description: gui.c.Tr.LcCherryPickCopyRange,
},
{
ViewName: "commits",
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.PasteCommits),
Handler: guards.OutsideFilterMode(gui.HandlePasteCommits),
Description: gui.c.Tr.LcPasteCommits,
},
{
ViewName: "commits",
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.New),
Modifier: gocui.ModNone,
Handler: gui.handleNewBranchOffCurrentItem,
@ -558,28 +559,28 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "commits",
Contexts: []string{string(BRANCH_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ResetCherryPick),
Handler: gui.exitCherryPickingMode,
Description: gui.c.Tr.LcResetCherryPick,
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GoInto),
Handler: gui.handleViewReflogCommitFiles,
Description: gui.c.Tr.LcViewCommitFiles,
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
Handler: gui.CheckoutReflogCommit,
Description: gui.c.Tr.LcCheckoutCommit,
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateReflogResetMenu,
Description: gui.c.Tr.LcViewResetOptions,
@ -587,49 +588,49 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.CherryPickCopy),
Handler: guards.OutsideFilterMode(gui.handleCopyCommit),
Description: gui.c.Tr.LcCherryPickCopy,
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.CherryPickCopyRange),
Handler: guards.OutsideFilterMode(gui.handleCopyCommitRange),
Description: gui.c.Tr.LcCherryPickCopyRange,
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ResetCherryPick),
Handler: gui.exitCherryPickingMode,
Description: gui.c.Tr.LcResetCherryPick,
},
{
ViewName: "commits",
Contexts: []string{string(REFLOG_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.REFLOG_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Handler: gui.handleCopySelectedSideContextItemToClipboard,
Description: gui.c.Tr.LcCopyCommitShaToClipboard,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GoInto),
Handler: gui.handleViewSubCommitFiles,
Description: gui.c.Tr.LcViewCommitFiles,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
Handler: gui.handleCheckoutSubCommit,
Description: gui.c.Tr.LcCheckoutCommit,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateSubCommitResetMenu,
Description: gui.c.Tr.LcViewResetOptions,
@ -637,35 +638,35 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.New),
Handler: gui.handleNewBranchOffCurrentItem,
Description: gui.c.Tr.LcNewBranch,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.CherryPickCopy),
Handler: gui.handleCopyCommit,
Description: gui.c.Tr.LcCherryPickCopy,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.CherryPickCopyRange),
Handler: gui.handleCopyCommitRange,
Description: gui.c.Tr.LcCherryPickCopyRange,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Commits.ResetCherryPick),
Handler: gui.exitCherryPickingMode,
Description: gui.c.Tr.LcResetCherryPick,
},
{
ViewName: "branches",
Contexts: []string{string(SUB_COMMITS_CONTEXT_KEY)},
Contexts: []string{string(context.SUB_COMMITS_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Handler: gui.handleCopySelectedSideContextItemToClipboard,
Description: gui.c.Tr.LcCopyCommitShaToClipboard,
@ -826,14 +827,14 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "secondary",
Contexts: []string{string(MAIN_NORMAL_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_NORMAL_CONTEXT_KEY)},
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleMouseDownSecondary,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_NORMAL_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_NORMAL_CONTEXT_KEY)},
Key: gocui.MouseWheelDown,
Handler: gui.scrollDownMain,
Description: gui.c.Tr.ScrollDown,
@ -841,7 +842,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_NORMAL_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_NORMAL_CONTEXT_KEY)},
Key: gocui.MouseWheelUp,
Handler: gui.scrollUpMain,
Description: gui.c.Tr.ScrollUp,
@ -849,133 +850,133 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_NORMAL_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_NORMAL_CONTEXT_KEY)},
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleMouseDownMain,
},
{
ViewName: "secondary",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleTogglePanelClick,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Return),
Handler: gui.handleStagingEscape,
Description: gui.c.Tr.ReturnToFilesPanel,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
Handler: gui.handleToggleStagedSelection,
Description: gui.c.Tr.StageSelection,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Remove),
Handler: gui.handleResetSelection,
Description: gui.c.Tr.ResetSelection,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.TogglePanel),
Handler: gui.handleTogglePanel,
Description: gui.c.Tr.TogglePanel,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Return),
Handler: gui.handleEscapePatchBuildingPanel,
Description: gui.c.Tr.ExitLineByLineMode,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.OpenFile),
Handler: gui.handleOpenFileAtLine,
Description: gui.c.Tr.LcOpenFile,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItem),
Handler: gui.handleSelectPrevLine,
Description: gui.c.Tr.PrevLine,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItem),
Handler: gui.handleSelectNextLine,
Description: gui.c.Tr.NextLine,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItemAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectPrevLine,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItemAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectNextLine,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseWheelUp,
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseWheelDown,
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevBlock),
Handler: gui.handleSelectPrevHunk,
Description: gui.c.Tr.PrevHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevBlockAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectPrevHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextBlock),
Handler: gui.handleSelectNextHunk,
Description: gui.c.Tr.NextHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextBlockAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectNextHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Modifier: gocui.ModNone,
Handler: gui.copySelectedToClipboard,
@ -983,21 +984,21 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Edit),
Handler: gui.handleLineByLineEdit,
Description: gui.c.Tr.LcEditFile,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.OpenFile),
Handler: gui.Controllers.Files.Open,
Description: gui.c.Tr.LcOpenFile,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextPage),
Modifier: gocui.ModNone,
Handler: gui.handleLineByLineNextPage,
@ -1006,7 +1007,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevPage),
Modifier: gocui.ModNone,
Handler: gui.handleLineByLinePrevPage,
@ -1015,7 +1016,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GotoTop),
Modifier: gocui.ModNone,
Handler: gui.handleLineByLineGotoTop,
@ -1024,7 +1025,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.GotoBottom),
Modifier: gocui.ModNone,
Handler: gui.handleLineByLineGotoBottom,
@ -1033,7 +1034,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.StartSearch),
Handler: func() error { return gui.handleOpenSearch("main") },
Description: gui.c.Tr.LcStartSearch,
@ -1041,14 +1042,14 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
Handler: gui.handleToggleSelectionForPatch,
Description: gui.c.Tr.ToggleSelectionForPatch,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Main.ToggleDragSelect),
Handler: gui.handleToggleSelectRange,
Description: gui.c.Tr.ToggleDragSelect,
@ -1056,175 +1057,175 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
// Alias 'V' -> 'v'
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Main.ToggleDragSelectAlt),
Handler: gui.handleToggleSelectRange,
Description: gui.c.Tr.ToggleDragSelect,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Main.ToggleSelectHunk),
Handler: gui.handleToggleSelectHunk,
Description: gui.c.Tr.ToggleSelectHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleLBLMouseDown,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseLeft,
Modifier: gocui.ModMotion,
Handler: gui.handleMouseDrag,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseWheelUp,
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gocui.MouseWheelDown,
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY), string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY), string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.ScrollLeft),
Handler: gui.scrollLeftMain,
Description: gui.c.Tr.LcScrollLeft,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY), string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_PATCH_BUILDING_CONTEXT_KEY), string(context.MAIN_STAGING_CONTEXT_KEY), string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.ScrollRight),
Handler: gui.scrollRightMain,
Description: gui.c.Tr.LcScrollRight,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Files.CommitChanges),
Handler: gui.Controllers.Files.HandleCommitPress,
Description: gui.c.Tr.CommitChanges,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Files.CommitChangesWithoutHook),
Handler: gui.Controllers.Files.HandleWIPCommitPress,
Description: gui.c.Tr.LcCommitChangesWithoutHook,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_STAGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_STAGING_CONTEXT_KEY)},
Key: gui.getKey(config.Files.CommitChangesWithEditor),
Handler: gui.Controllers.Files.HandleCommitEditorPress,
Description: gui.c.Tr.CommitChangesWithEditor,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Return),
Handler: gui.handleEscapeMerge,
Description: gui.c.Tr.ReturnToFilesPanel,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Files.OpenMergeTool),
Handler: gui.Controllers.Files.OpenMergeTool,
Description: gui.c.Tr.LcOpenMergeTool,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
Handler: gui.handlePickHunk,
Description: gui.c.Tr.PickHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Main.PickBothHunks),
Handler: gui.handlePickAllHunks,
Description: gui.c.Tr.PickAllHunks,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevBlock),
Handler: gui.handleSelectPrevConflict,
Description: gui.c.Tr.PrevConflict,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextBlock),
Handler: gui.handleSelectNextConflict,
Description: gui.c.Tr.NextConflict,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItem),
Handler: gui.handleSelectPrevConflictHunk,
Description: gui.c.Tr.SelectPrevHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItem),
Handler: gui.handleSelectNextConflictHunk,
Description: gui.c.Tr.SelectNextHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevBlockAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectPrevConflict,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextBlockAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectNextConflict,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItemAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectPrevConflictHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItemAlt),
Modifier: gocui.ModNone,
Handler: gui.handleSelectNextConflictHunk,
},
{
ViewName: "main",
Contexts: []string{string(MAIN_MERGING_CONTEXT_KEY)},
Contexts: []string{string(context.MAIN_MERGING_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Undo),
Handler: gui.handleMergeConflictUndo,
Description: gui.c.Tr.LcUndo,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Select),
// gonna use the exact same handler as the 'n' keybinding because everybody wants this to happen when they checkout a remote branch
Handler: gui.handleNewBranchOffCurrentItem,
@ -1232,35 +1233,35 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.New),
Handler: gui.handleNewBranchOffCurrentItem,
Description: gui.c.Tr.LcNewBranch,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.MergeIntoCurrentBranch),
Handler: guards.OutsideFilterMode(gui.handleMergeRemoteBranch),
Description: gui.c.Tr.LcMergeIntoCurrentBranch,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.Remove),
Handler: gui.handleDeleteRemoteBranch,
Description: gui.c.Tr.LcDeleteBranch,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.RebaseBranch),
Handler: guards.OutsideFilterMode(gui.handleRebaseOntoRemoteBranch),
Description: gui.c.Tr.LcRebaseBranch,
},
{
ViewName: "branches",
Contexts: []string{string(REMOTE_BRANCHES_CONTEXT_KEY)},
Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)},
Key: gui.getKey(config.Branches.SetUpstream),
Handler: gui.handleSetBranchUpstream,
Description: gui.c.Tr.LcSetUpstream,
@ -1309,14 +1310,14 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "files",
Contexts: []string{string(SUBMODULES_CONTEXT_KEY)},
Contexts: []string{string(context.SUBMODULES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.CopyToClipboard),
Handler: gui.handleCopySelectedSideContextItemToClipboard,
Description: gui.c.Tr.LcCopySubmoduleNameToClipboard,
},
{
ViewName: "files",
Contexts: []string{string(FILES_CONTEXT_KEY)},
Contexts: []string{string(context.FILES_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.ToggleWhitespaceInDiffView),
Handler: gui.toggleWhitespaceInDiffView,
Description: gui.c.Tr.ToggleWhitespaceInDiffView,
@ -1353,7 +1354,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Contexts: []string{string(context.COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollUpExtra,
@ -1361,7 +1362,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Contexts: []string{string(context.COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItem),
Modifier: gocui.ModNone,
Handler: gui.scrollUpExtra,
@ -1369,7 +1370,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Contexts: []string{string(context.COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItem),
Modifier: gocui.ModNone,
Handler: gui.scrollDownExtra,
@ -1377,7 +1378,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Contexts: []string{string(context.COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollDownExtra,

View File

@ -33,7 +33,7 @@ func (gui *Gui) filesListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "files",
WindowName: "files",
Key: FILES_CONTEXT_KEY,
Key: context.FILES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return gui.State.FileTreeViewModel.GetItemsLength() },
@ -62,7 +62,7 @@ func (gui *Gui) branchesListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "branches",
WindowName: "branches",
Key: LOCAL_BRANCHES_CONTEXT_KEY,
Key: context.LOCAL_BRANCHES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.Branches) },
@ -84,7 +84,7 @@ func (gui *Gui) remotesListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "branches",
WindowName: "branches",
Key: REMOTES_CONTEXT_KEY,
Key: context.REMOTES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.Remotes) },
@ -106,7 +106,7 @@ func (gui *Gui) remoteBranchesListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "branches",
WindowName: "branches",
Key: REMOTE_BRANCHES_CONTEXT_KEY,
Key: context.REMOTE_BRANCHES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.RemoteBranches) },
@ -153,7 +153,7 @@ func (gui *Gui) branchCommitsListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "commits",
WindowName: "commits",
Key: BRANCH_COMMITS_CONTEXT_KEY,
Key: context.BRANCH_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.Commits) },
@ -163,7 +163,7 @@ func (gui *Gui) branchCommitsListContext() types.IListContext {
Gui: gui,
GetDisplayStrings: func(startIdx int, length int) [][]string {
selectedCommitSha := ""
if gui.currentContext().GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
if gui.currentContext().GetKey() == context.BRANCH_COMMITS_CONTEXT_KEY {
selectedCommit := gui.getSelectedLocalCommit()
if selectedCommit != nil {
selectedCommitSha = selectedCommit.Sha
@ -196,7 +196,7 @@ func (gui *Gui) subCommitsListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "branches",
WindowName: "branches",
Key: SUB_COMMITS_CONTEXT_KEY,
Key: context.SUB_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.SubCommits) },
@ -205,7 +205,7 @@ func (gui *Gui) subCommitsListContext() types.IListContext {
Gui: gui,
GetDisplayStrings: func(startIdx int, length int) [][]string {
selectedCommitSha := ""
if gui.currentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY {
if gui.currentContext().GetKey() == context.SUB_COMMITS_CONTEXT_KEY {
selectedCommit := gui.getSelectedSubCommit()
if selectedCommit != nil {
selectedCommitSha = selectedCommit.Sha
@ -257,7 +257,7 @@ func (gui *Gui) reflogCommitsListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "commits",
WindowName: "commits",
Key: REFLOG_COMMITS_CONTEXT_KEY,
Key: context.REFLOG_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
@ -285,7 +285,7 @@ func (gui *Gui) stashListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "stash",
WindowName: "stash",
Key: STASH_CONTEXT_KEY,
Key: context.STASH_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.StashEntries) },
@ -307,7 +307,7 @@ func (gui *Gui) commitFilesListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "commitFiles",
WindowName: "commits",
Key: COMMIT_FILES_CONTEXT_KEY,
Key: context.COMMIT_FILES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return gui.State.CommitFileTreeViewModel.GetItemsLength() },
@ -340,7 +340,7 @@ func (gui *Gui) submodulesListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "files",
WindowName: "files",
Key: SUBMODULES_CONTEXT_KEY,
Key: context.SUBMODULES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
}),
GetItemsLength: func() int { return len(gui.State.Submodules) },
@ -362,7 +362,7 @@ func (gui *Gui) suggestionsListContext() types.IListContext {
BaseContext: context.NewBaseContext(context.NewBaseContextOpts{
ViewName: "suggestions",
WindowName: "suggestions",
Key: SUGGESTIONS_CONTEXT_KEY,
Key: context.SUGGESTIONS_CONTEXT_KEY,
Kind: types.PERSISTENT_POPUP,
}),
GetItemsLength: func() int { return len(gui.State.Suggestions) },

View File

@ -8,6 +8,7 @@ import (
"math"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -287,7 +288,7 @@ func (gui *Gui) refreshMergeState() error {
gui.State.Panels.Merging.Lock()
defer gui.State.Panels.Merging.Unlock()
if gui.currentContext().GetKey() != MAIN_MERGING_CONTEXT_KEY {
if gui.currentContext().GetKey() != context.MAIN_MERGING_CONTEXT_KEY {
return nil
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -82,7 +83,7 @@ func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
}
func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error {
if gui.State.MainContext == MAIN_PATCH_BUILDING_CONTEXT_KEY {
if gui.State.MainContext == context.MAIN_PATCH_BUILDING_CONTEXT_KEY {
return gui.handleEscapePatchBuildingPanel()
}
return nil
@ -188,7 +189,7 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
func (gui *Gui) handleResetPatch() error {
gui.git.Patch.PatchManager.Reset()
if gui.currentContextKeyIgnoringPopups() == MAIN_PATCH_BUILDING_CONTEXT_KEY {
if gui.currentContextKeyIgnoringPopups() == context.MAIN_PATCH_BUILDING_CONTEXT_KEY {
if err := gui.c.PushContext(gui.State.Contexts.CommitFiles); err != nil {
return err
}