1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00

WIP constants for context keys

This commit is contained in:
Jesse Duffield 2020-08-20 09:00:55 +10:00
parent 146722beb8
commit 433d54fcec
4 changed files with 77 additions and 55 deletions

View File

@ -16,6 +16,28 @@ const (
func GetKindWrapper(k int) func() int { return func() int { return k } }
const (
STATUS_CONTEXT_KEY = "status"
FILES_CONTEXT_KEY = "files"
LOCAL_BRANCHES_CONTEXT_KEY = "localBranches"
REMOTES_CONTEXT_KEY = "remotes"
REMOTE_BRANCHES_CONTEXT_KEY = "remoteBranches"
TAGS_CONTEXT_KEY = "tags"
BRANCH_COMMITS_CONTEXT_KEY = "commits"
REFLOG_COMMITS_CONTEXT_KEY = "reflogCommits"
COMMIT_FILES_CONTEXT_KEY = "commitFiles"
STASH_CONTEXT_KEY = "stash"
MAIN_NORMAL_CONTEXT_KEY = "normal"
MAIN_MERGING_CONTEXT_KEY = "merging"
MAIN_PATCH_BUILDING_CONTEXT_KEY = "patchBuilding"
MAIN_STAGING_CONTEXT_KEY = "staging"
MENU_CONTEXT_KEY = "menu"
CREDENTIALS_CONTEXT_KEY = "credentials"
CONFIRMATION_CONTEXT_KEY = "confirmation"
SEARCH_CONTEXT_KEY = "confirmation"
COMMIT_MESSAGE_CONTEXT_KEY = "commitMessage"
)
type Context interface {
HandleFocus() error
HandleFocusLost() error
@ -232,7 +254,7 @@ func (gui *Gui) contextTree() ContextTree {
OnFocus: func() error { return gui.handleCommitMessageFocused() },
Kind: PERSISTENT_POPUP,
ViewName: "commitMessage",
Key: "commit-message", // admittedly awkward to have view names in camelCase and contexts in kebab-case
Key: "commitMessage",
},
},
Search: SimpleContextNode{

View File

@ -46,12 +46,12 @@ func (gui *Gui) currentDiffTerminals() []string {
// not supporting files for now
case "commitFiles":
// not supporting commit files for now
case "branch-commits":
case "branchCommits":
item := gui.getSelectedCommit()
if item != nil {
return []string{item.RefName()}
}
case "reflog-commits":
case "reflogCommits":
item := gui.getSelectedReflogCommit()
if item != nil {
return []string{item.RefName()}
@ -62,7 +62,7 @@ func (gui *Gui) currentDiffTerminals() []string {
return []string{item.RefName()}
}
case "local-branches":
case "localBranches":
branch := gui.getSelectedBranch()
if branch != nil {
names := []string{branch.RefName()}
@ -77,7 +77,7 @@ func (gui *Gui) currentDiffTerminals() []string {
if item != nil {
return []string{item.RefName()}
}
case "remote-branches":
case "remoteBranches":
item := gui.getSelectedRemoteBranch()
if item != nil {
return []string{item.RefName()}

View File

@ -466,91 +466,91 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("universal.select"),
Handler: gui.handleBranchPress,
Description: gui.Tr.SLocalize("checkout"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.createPullRequest"),
Handler: gui.handleCreatePullRequestPress,
Description: gui.Tr.SLocalize("createPullRequest"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.checkoutBranchByName"),
Handler: gui.handleCheckoutByName,
Description: gui.Tr.SLocalize("checkoutByName"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.forceCheckoutBranch"),
Handler: gui.handleForceCheckout,
Description: gui.Tr.SLocalize("forceCheckout"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("universal.new"),
Handler: gui.handleNewBranch,
Description: gui.Tr.SLocalize("newBranch"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("universal.remove"),
Handler: gui.handleDeleteBranch,
Description: gui.Tr.SLocalize("deleteBranch"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.rebaseBranch"),
Handler: gui.handleRebaseOntoLocalBranch,
Description: gui.Tr.SLocalize("rebaseBranch"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.mergeIntoCurrentBranch"),
Handler: gui.handleMerge,
Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.viewGitFlowOptions"),
Handler: gui.handleCreateGitFlowMenu,
Description: gui.Tr.SLocalize("gitFlowOptions"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.FastForward"),
Handler: gui.handleFastForward,
Description: gui.Tr.SLocalize("FastForward"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("commits.viewResetOptions"),
Handler: gui.handleCreateResetToBranchMenu,
Description: gui.Tr.SLocalize("viewResetOptions"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("branches.renameBranch"),
Handler: gui.handleRenameBranch,
Description: gui.Tr.SLocalize("renameBranch"),
},
{
ViewName: "branches",
Contexts: []string{"local-branches"},
Contexts: []string{"localBranches"},
Key: gui.getKey("universal.copyToClipboard"),
Handler: gui.handleClipboardCopyBranch,
Description: gui.Tr.SLocalize("copyBranchNameToClipboard"),
@ -604,14 +604,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("universal.return"),
Handler: gui.handleRemoteBranchesEscape,
Description: gui.Tr.SLocalize("ReturnToRemotesList"),
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("commits.viewResetOptions"),
Handler: gui.handleCreateResetToRemoteBranchMenu,
Description: gui.Tr.SLocalize("viewResetOptions"),
@ -637,147 +637,147 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.squashDown"),
Handler: gui.handleCommitSquashDown,
Description: gui.Tr.SLocalize("squashDown"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.renameCommit"),
Handler: gui.handleRenameCommit,
Description: gui.Tr.SLocalize("renameCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.renameCommitWithEditor"),
Handler: gui.handleRenameCommitEditor,
Description: gui.Tr.SLocalize("renameCommitEditor"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.viewResetOptions"),
Handler: gui.handleCreateCommitResetMenu,
Description: gui.Tr.SLocalize("resetToThisCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.markCommitAsFixup"),
Handler: gui.handleCommitFixup,
Description: gui.Tr.SLocalize("fixupCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.createFixupCommit"),
Handler: gui.handleCreateFixupCommit,
Description: gui.Tr.SLocalize("createFixupCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.squashAboveCommits"),
Handler: gui.handleSquashAllAboveFixupCommits,
Description: gui.Tr.SLocalize("squashAboveCommits"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("universal.remove"),
Handler: gui.handleCommitDelete,
Description: gui.Tr.SLocalize("deleteCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.moveDownCommit"),
Handler: gui.handleCommitMoveDown,
Description: gui.Tr.SLocalize("moveDownCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.moveUpCommit"),
Handler: gui.handleCommitMoveUp,
Description: gui.Tr.SLocalize("moveUpCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("universal.edit"),
Handler: gui.handleCommitEdit,
Description: gui.Tr.SLocalize("editCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.amendToCommit"),
Handler: gui.handleCommitAmendTo,
Description: gui.Tr.SLocalize("amendToCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.pickCommit"),
Handler: gui.handleCommitPick,
Description: gui.Tr.SLocalize("pickCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.revertCommit"),
Handler: gui.handleCommitRevert,
Description: gui.Tr.SLocalize("revertCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.cherryPickCopy"),
Handler: gui.handleCopyCommit,
Description: gui.Tr.SLocalize("cherryPickCopy"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("universal.copyToClipboard"),
Handler: gui.handleClipboardCopyCommit,
Description: gui.Tr.SLocalize("copyCommitShaToClipboard"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.cherryPickCopyRange"),
Handler: gui.handleCopyCommitRange,
Description: gui.Tr.SLocalize("cherryPickCopyRange"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.pasteCommits"),
Handler: gui.HandlePasteCommits,
Description: gui.Tr.SLocalize("pasteCommits"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("universal.goInto"),
Handler: gui.wrappedHandler(gui.handleSwitchToCommitFilesPanel),
Description: gui.Tr.SLocalize("viewCommitFiles"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.checkoutCommit"),
Handler: gui.handleCheckoutCommit,
Description: gui.Tr.SLocalize("checkoutCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("universal.new"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleNewBranchOffCommit),
@ -785,28 +785,28 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.tagCommit"),
Handler: gui.handleTagCommit,
Description: gui.Tr.SLocalize("tagCommit"),
},
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
Contexts: []string{"branchCommits"},
Key: gui.getKey("commits.resetCherryPick"),
Handler: gui.handleResetCherryPick,
Description: gui.Tr.SLocalize("resetCherryPick"),
},
{
ViewName: "commits",
Contexts: []string{"reflog-commits"},
Contexts: []string{"reflogCommits"},
Key: gui.getKey("universal.select"),
Handler: gui.handleCheckoutReflogCommit,
Description: gui.Tr.SLocalize("checkoutCommit"),
},
{
ViewName: "commits",
Contexts: []string{"reflog-commits"},
Contexts: []string{"reflogCommits"},
Key: gui.getKey("commits.viewResetOptions"),
Handler: gui.handleCreateReflogResetMenu,
Description: gui.Tr.SLocalize("viewResetOptions"),
@ -1300,14 +1300,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("universal.select"),
Handler: gui.handleCheckoutRemoteBranch,
Description: gui.Tr.SLocalize("checkout"),
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("universal.new"),
Handler: gui.handleNewBranchOffRemote,
Description: gui.Tr.SLocalize("newBranch"),
@ -1315,28 +1315,28 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("branches.mergeIntoCurrentBranch"),
Handler: gui.handleMergeRemoteBranch,
Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"),
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("universal.remove"),
Handler: gui.handleDeleteRemoteBranch,
Description: gui.Tr.SLocalize("deleteBranch"),
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("branches.rebaseBranch"),
Handler: gui.handleRebaseOntoRemoteBranch,
Description: gui.Tr.SLocalize("rebaseBranch"),
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},
Contexts: []string{"remoteBranches"},
Key: gui.getKey("branches.setUpstream"),
Handler: gui.handleSetBranchUpstream,
Description: gui.Tr.SLocalize("setUpstream"),

View File

@ -248,7 +248,7 @@ func (gui *Gui) filesListContext() *ListContext {
func (gui *Gui) branchesListContext() *ListContext {
return &ListContext{
ViewName: "branches",
ContextKey: "local-branches",
ContextKey: "localBranches",
GetItemsLength: func() int { return len(gui.State.Branches) },
GetPanelState: func() IListPanelState { return gui.State.Panels.Branches },
OnFocus: gui.handleBranchSelect,
@ -281,7 +281,7 @@ func (gui *Gui) remotesListContext() *ListContext {
func (gui *Gui) remoteBranchesListContext() *ListContext {
return &ListContext{
ViewName: "branches",
ContextKey: "remote-branches",
ContextKey: "remoteBranches",
GetItemsLength: func() int { return len(gui.State.RemoteBranches) },
GetPanelState: func() IListPanelState { return gui.State.Panels.RemoteBranches },
OnFocus: gui.handleRemoteBranchSelect,
@ -313,7 +313,7 @@ func (gui *Gui) tagsListContext() *ListContext {
func (gui *Gui) branchCommitsListContext() *ListContext {
return &ListContext{
ViewName: "commits",
ContextKey: "branch-commits",
ContextKey: "branchCommits",
GetItemsLength: func() int { return len(gui.State.Commits) },
GetPanelState: func() IListPanelState { return gui.State.Panels.Commits },
OnFocus: gui.handleCommitSelect,
@ -330,7 +330,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
func (gui *Gui) reflogCommitsListContext() *ListContext {
return &ListContext{
ViewName: "commits",
ContextKey: "reflog-commits",
ContextKey: "reflogCommits",
GetItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
GetPanelState: func() IListPanelState { return gui.State.Panels.ReflogCommits },
OnFocus: gui.handleReflogCommitSelect,