summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context_config.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/context_config.go')
-rw-r--r--pkg/gui/context_config.go209
1 files changed, 145 insertions, 64 deletions
diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go
index a983ffdd5..1ff8aad75 100644
--- a/pkg/gui/context_config.go
+++ b/pkg/gui/context_config.go
@@ -9,26 +9,27 @@ func (gui *Gui) contextTree() *context.ContextTree {
return &context.ContextTree{
Global: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
- Kind: types.GLOBAL_CONTEXT,
- ViewName: "",
- WindowName: "",
- Key: context.GLOBAL_CONTEXT_KEY,
- Focusable: false,
+ Kind: types.GLOBAL_CONTEXT,
+ View: nil,
+ WindowName: "",
+ Key: context.GLOBAL_CONTEXT_KEY,
+ Focusable: false,
+ HasUncontrolledBounds: true, // setting to true because the global context doesn't even have a view
}),
context.ContextCallbackOpts{
- OnRenderToMain: OnFocusWrapper(gui.statusRenderToMain),
+ OnRenderToMain: gui.statusRenderToMain,
},
),
Status: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.SIDE_CONTEXT,
- ViewName: "status",
+ View: gui.Views.Status,
WindowName: "status",
Key: context.STATUS_CONTEXT_KEY,
Focusable: true,
}),
context.ContextCallbackOpts{
- OnRenderToMain: OnFocusWrapper(gui.statusRenderToMain),
+ OnRenderToMain: gui.statusRenderToMain,
},
),
Files: gui.filesListContext(),
@@ -47,84 +48,150 @@ func (gui *Gui) contextTree() *context.ContextTree {
Normal: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
- ViewName: "main",
+ View: gui.Views.Main,
WindowName: "main",
- Key: context.MAIN_NORMAL_CONTEXT_KEY,
+ Key: context.NORMAL_MAIN_CONTEXT_KEY,
Focusable: false,
}),
context.ContextCallbackOpts{
- OnFocus: func(opts ...types.OnFocusOpts) error {
+ OnFocus: func(opts types.OnFocusOpts) error {
return nil // TODO: should we do something here? We should allow for scrolling the panel
},
},
),
- Staging: context.NewSimpleContext(
+ NormalSecondary: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
- ViewName: "main",
- WindowName: "main",
- Key: context.MAIN_STAGING_CONTEXT_KEY,
- Focusable: true,
+ View: gui.Views.Secondary,
+ WindowName: "secondary",
+ Key: context.NORMAL_SECONDARY_CONTEXT_KEY,
+ Focusable: false,
}),
- context.ContextCallbackOpts{
- 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
- }
- }
- return gui.onStagingFocus(forceSecondaryFocused, selectedLineIdx)
- },
+ context.ContextCallbackOpts{},
+ ),
+ Staging: context.NewPatchExplorerContext(
+ gui.Views.Staging,
+ "main",
+ context.STAGING_MAIN_CONTEXT_KEY,
+ func(opts types.OnFocusOpts) error {
+ gui.Views.Staging.Wrap = false
+ gui.Views.StagingSecondary.Wrap = false
+
+ return gui.refreshStagingPanel(opts)
+ },
+ func(opts types.OnFocusLostOpts) error {
+ gui.State.Contexts.Staging.SetState(nil)
+
+ if opts.NewContextKey != context.STAGING_SECONDARY_CONTEXT_KEY {
+ gui.Views.Staging.Wrap = true
+ gui.Views.StagingSecondary.Wrap = true
+ _ = gui.State.Contexts.Staging.Render(false)
+ _ = gui.State.Contexts.StagingSecondary.Render(false)
+ }
+ return nil
},
+ func() []int { return nil },
+ gui.c,
),
- PatchBuilding: context.NewSimpleContext(
+ StagingSecondary: context.NewPatchExplorerContext(
+ gui.Views.StagingSecondary,
+ "secondary",
+ context.STAGING_SECONDARY_CONTEXT_KEY,
+ func(opts types.OnFocusOpts) error {
+ gui.Views.Staging.Wrap = false
+ gui.Views.StagingSecondary.Wrap = false
+
+ return gui.refreshStagingPanel(opts)
+ },
+ func(opts types.OnFocusLostOpts) error {
+ gui.State.Contexts.StagingSecondary.SetState(nil)
+
+ if opts.NewContextKey != context.STAGING_MAIN_CONTEXT_KEY {
+ gui.Views.Staging.Wrap = true
+ gui.Views.StagingSecondary.Wrap = true
+ _ = gui.State.Contexts.Staging.Render(false)
+ _ = gui.State.Contexts.StagingSecondary.Render(false)
+ }
+ return nil
+ },
+ func() []int { return nil },
+ gui.c,
+ ),
+ CustomPatchBuilder: context.NewPatchExplorerContext(
+ gui.Views.PatchBuilding,
+ "main",
+ context.PATCH_BUILDING_MAIN_CONTEXT_KEY,
+ func(opts types.OnFocusOpts) error {
+ // no need to change wrap on the secondary view because it can't be interacted with
+ gui.Views.PatchBuilding.Wrap = false
+
+ return gui.refreshPatchBuildingPanel(opts)
+ },
+ func(opts types.OnFocusLostOpts) error {
+ gui.Views.PatchBuilding.Wrap = true
+
+ if gui.git.Patch.PatchManager.IsEmpty() {
+ gui.git.Patch.PatchManager.Reset()
+ }
+
+ return nil
+ },
+ func() []int {
+ filename := gui.State.Contexts.CommitFiles.GetSelectedPath()
+ includedLineIndices, err := gui.git.Patch.PatchManager.GetFileIncLineIndices(filename)
+ if err != nil {
+ gui.Log.Error(err)
+ return nil
+ }
+
+ return includedLineIndices
+ },
+ gui.c,
+ ),
+ CustomPatchBuilderSecondary: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
- ViewName: "main",
- WindowName: "main",
- Key: context.MAIN_PATCH_BUILDING_CONTEXT_KEY,
- Focusable: true,
+ View: gui.Views.PatchBuildingSecondary,
+ WindowName: "secondary",
+ Key: context.PATCH_BUILDING_SECONDARY_CONTEXT_KEY,
+ Focusable: false,
}),
- context.ContextCallbackOpts{
- OnFocus: func(opts ...types.OnFocusOpts) error {
- selectedLineIdx := -1
- if len(opts) > 0 && (opts[0].ClickedViewName == "main" || opts[0].ClickedViewName == "secondary") {
- selectedLineIdx = opts[0].ClickedViewLineIdx
- }
-
- return gui.onPatchBuildingFocus(selectedLineIdx)
- },
- },
+ context.ContextCallbackOpts{},
),
Merging: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
- ViewName: "main",
+ View: gui.Views.Merging,
WindowName: "main",
- Key: context.MAIN_MERGING_CONTEXT_KEY,
+ Key: context.MERGING_MAIN_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
Focusable: true,
}),
context.ContextCallbackOpts{
- OnFocus: OnFocusWrapper(func() error { return gui.renderConflictsWithLock(true) }),
+ OnFocus: OnFocusWrapper(func() error {
+ gui.Views.Merging.Wrap = false
+
+ return gui.renderConflictsWithLock(true)
+ }),
+ OnFocusLost: func(types.OnFocusLostOpts) error {
+ gui.Views.Merging.Wrap = true
+
+ return nil
+ },
},
),
Confirmation: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
- Kind: types.TEMPORARY_POPUP,
- ViewName: "confirmation",
- WindowName: "confirmation",
- Key: context.CONFIRMATION_CONTEXT_KEY,
- Focusable: true,
+ Kind: types.TEMPORARY_POPUP,
+ View: gui.Views.Confirmation,
+ WindowName: "confirmation",
+ Key: context.CONFIRMATION_CONTEXT_KEY,
+ Focusable: true,
+ HasUncontrolledBounds: true,
}),
context.ContextCallbackOpts{
OnFocus: OnFocusWrapper(gui.handleAskFocused),
- OnFocusLost: func() error {
+ OnFocusLost: func(types.OnFocusLostOpts) error {
gui.deactivateConfirmationPrompt()
return nil
},
@@ -132,11 +199,12 @@ func (gui *Gui) contextTree() *context.ContextTree {
),
CommitMessage: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
- Kind: types.PERSISTENT_POPUP,
- ViewName: "commitMessage",
- WindowName: "commitMessage",
- Key: context.COMMIT_MESSAGE_CONTEXT_KEY,
- Focusable: true,
+ Kind: types.PERSISTENT_POPUP,
+ View: gui.Views.CommitMessage,
+ WindowName: "commitMessage",
+ Key: context.COMMIT_MESSAGE_CONTEXT_KEY,
+ Focusable: true,
+ HasUncontrolledBounds: true,
}),
context.ContextCallbackOpts{
OnFocus: OnFocusWrapper(gui.handleCommitMessageFocused),
@@ -145,7 +213,7 @@ func (gui *Gui) contextTree() *context.ContextTree {
Search: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.PERSISTENT_POPUP,
- ViewName: "search",
+ View: gui.Views.Search,
WindowName: "search",
Key: context.SEARCH_CONTEXT_KEY,
Focusable: true,
@@ -155,26 +223,39 @@ func (gui *Gui) contextTree() *context.ContextTree {
CommandLog: context.NewSimpleContext(
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.EXTRAS_CONTEXT,
- ViewName: "extras",
+ View: gui.Views.Extras,
WindowName: "extras",
Key: context.COMMAND_LOG_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
Focusable: true,
}),
context.ContextCallbackOpts{
- OnFocusLost: func() error {
+ OnFocusLost: func(opts types.OnFocusLostOpts) error {
gui.Views.Extras.Autoscroll = true
return nil
},
},
),
+ Options: context.NewDisplayContext(context.OPTIONS_CONTEXT_KEY, gui.Views.Options, "options"),
+ AppStatus: context.NewDisplayContext(context.APP_STATUS_CONTEXT_KEY, gui.Views.AppStatus, "appStatus"),
+ SearchPrefix: context.NewDisplayContext(context.SEARCH_PREFIX_CONTEXT_KEY, gui.Views.SearchPrefix, "searchPrefix"),
+ Information: context.NewDisplayContext(context.INFORMATION_CONTEXT_KEY, gui.Views.Information, "information"),
+ Limit: context.NewDisplayContext(context.LIMIT_CONTEXT_KEY, gui.Views.Limit, "limit"),
}
}
// 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 {
+func OnFocusWrapper(f func() error) func(opts types.OnFocusOpts) error {
+ return func(opts types.OnFocusOpts) error {
return f()
}
}
+
+func (gui *Gui) getPatchExplorerContexts() []types.IPatchExplorerContext {
+ return []types.IPatchExplorerContext{
+ gui.State.Contexts.Staging,
+ gui.State.Contexts.StagingSecondary,
+ gui.State.Contexts.CustomPatchBuilder,
+ }
+}