1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/context_config.go

177 lines
5.5 KiB
Go
Raw Normal View History

package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
2022-01-31 13:20:28 +02:00
func (gui *Gui) contextTree() *context.ContextTree {
return &context.ContextTree{
2022-02-05 08:04:10 +02:00
Global: context.NewSimpleContext(
2022-02-05 05:42:56 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.GLOBAL_CONTEXT,
ViewName: "",
WindowName: "",
Key: context.GLOBAL_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: false,
2022-02-05 05:42:56 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-02-05 05:42:56 +02:00
OnRenderToMain: OnFocusWrapper(gui.statusRenderToMain),
},
),
2022-02-05 08:04:10 +02:00
Status: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.SIDE_CONTEXT,
ViewName: "status",
WindowName: "status",
2022-02-05 05:42:56 +02:00
Key: context.STATUS_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnRenderToMain: OnFocusWrapper(gui.statusRenderToMain),
},
),
Files: gui.filesListContext(),
Submodules: gui.submodulesListContext(),
Menu: gui.menuListContext(),
Remotes: gui.remotesListContext(),
RemoteBranches: gui.remoteBranchesListContext(),
2022-02-13 08:01:53 +02:00
LocalCommits: gui.branchCommitsListContext(),
CommitFiles: gui.commitFilesListContext(),
ReflogCommits: gui.reflogCommitsListContext(),
SubCommits: gui.subCommitsListContext(),
Branches: gui.branchesListContext(),
Tags: gui.tagsListContext(),
Stash: gui.stashListContext(),
2022-01-29 10:09:20 +02:00
Suggestions: gui.suggestionsListContext(),
2022-02-05 08:04:10 +02:00
Normal: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
2022-01-29 10:15:46 +02:00
Key: context.MAIN_NORMAL_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: false,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocus: func(opts ...types.OnFocusOpts) error {
return nil // TODO: should we do something here? We should allow for scrolling the panel
},
},
2022-01-29 10:09:20 +02:00
),
2022-02-05 08:04:10 +02:00
Staging: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
2022-01-29 10:15:46 +02:00
Key: context.MAIN_STAGING_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocus: func(opts ...types.OnFocusOpts) error {
forceSecondaryFocused := false
selectedLineIdx := -1
if len(opts) > 0 && opts[0].ClickedViewName != "" {
if opts[0].ClickedViewName == "main" || opts[0].ClickedViewName == "secondary" {
selectedLineIdx = opts[0].ClickedViewLineIdx
}
if opts[0].ClickedViewName == "secondary" {
forceSecondaryFocused = true
}
}
2022-01-29 10:09:20 +02:00
return gui.onStagingFocus(forceSecondaryFocused, selectedLineIdx)
},
},
2022-01-29 10:09:20 +02:00
),
2022-02-05 08:04:10 +02:00
PatchBuilding: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
2022-01-29 10:15:46 +02:00
Key: context.MAIN_PATCH_BUILDING_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocus: func(opts ...types.OnFocusOpts) error {
selectedLineIdx := -1
if len(opts) > 0 && (opts[0].ClickedViewName == "main" || opts[0].ClickedViewName == "secondary") {
selectedLineIdx = opts[0].ClickedViewLineIdx
}
2022-01-29 10:09:20 +02:00
return gui.onPatchBuildingFocus(selectedLineIdx)
},
},
),
2022-02-05 08:04:10 +02:00
Merging: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
2022-01-29 10:15:46 +02:00
Key: context.MAIN_MERGING_CONTEXT_KEY,
2022-01-29 10:09:20 +02:00
OnGetOptionsMap: gui.getMergingOptions,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocus: OnFocusWrapper(func() error { return gui.renderConflictsWithLock(true) }),
},
),
2022-02-05 08:04:10 +02:00
Confirmation: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.TEMPORARY_POPUP,
ViewName: "confirmation",
WindowName: "confirmation",
2022-01-29 10:15:46 +02:00
Key: context.CONFIRMATION_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocus: OnFocusWrapper(gui.handleAskFocused),
},
),
2022-02-05 08:04:10 +02:00
CommitMessage: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.PERSISTENT_POPUP,
ViewName: "commitMessage",
WindowName: "commitMessage",
2022-01-29 10:15:46 +02:00
Key: context.COMMIT_MESSAGE_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocus: OnFocusWrapper(gui.handleCommitMessageFocused),
},
2022-01-29 10:09:20 +02:00
),
2022-02-05 08:04:10 +02:00
Search: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.PERSISTENT_POPUP,
ViewName: "search",
WindowName: "search",
2022-01-29 10:15:46 +02:00
Key: context.SEARCH_CONTEXT_KEY,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{},
2022-01-29 10:09:20 +02:00
),
2022-02-05 08:04:10 +02:00
CommandLog: context.NewSimpleContext(
2022-01-29 10:09:20 +02:00
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.EXTRAS_CONTEXT,
ViewName: "extras",
WindowName: "extras",
2022-01-29 10:15:46 +02:00
Key: context.COMMAND_LOG_CONTEXT_KEY,
2022-01-29 10:09:20 +02:00
OnGetOptionsMap: gui.getMergingOptions,
2022-02-05 07:56:36 +02:00
Focusable: true,
2022-01-29 10:09:20 +02:00
}),
2022-02-05 08:04:10 +02:00
context.ContextCallbackOpts{
2022-01-29 10:09:20 +02:00
OnFocusLost: func() error {
gui.Views.Extras.Autoscroll = true
return nil
},
2021-04-11 07:01:49 +02:00
},
2022-01-29 10:09:20 +02:00
),
}
}
// using this wrapper for when an onFocus function doesn't care about any potential
// props that could be passed
func OnFocusWrapper(f func() error) func(opts ...types.OnFocusOpts) error {
return func(opts ...types.OnFocusOpts) error {
return f()
}
}