summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-06-13 11:01:26 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-08-06 13:49:11 +1000
commit524bf83a4a681408c3fb57818f6968cab632e0ae (patch)
tree8858b4ee8d4670dcdd1637fe5fedf00ff080c154 /pkg/gui
parent6dfef08efc5c7f262194c0af35fd777428f33a1a (diff)
refactor to only have one context per view
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/arrangement.go11
-rw-r--r--pkg/gui/branches_panel.go1
-rw-r--r--pkg/gui/command_log_panel.go8
-rw-r--r--pkg/gui/commit_files_panel.go45
-rw-r--r--pkg/gui/commits_panel.go16
-rw-r--r--pkg/gui/confirmation_panel.go9
-rw-r--r--pkg/gui/context.go192
-rw-r--r--pkg/gui/context/base_context.go62
-rw-r--r--pkg/gui/context/branches_context.go9
-rw-r--r--pkg/gui/context/commit_files_context.go9
-rw-r--r--pkg/gui/context/context.go189
-rw-r--r--pkg/gui/context/list_context_trait.go25
-rw-r--r--pkg/gui/context/local_commits_context.go9
-rw-r--r--pkg/gui/context/menu_context.go15
-rw-r--r--pkg/gui/context/patch_explorer_context.go134
-rw-r--r--pkg/gui/context/reflog_commits_context.go9
-rw-r--r--pkg/gui/context/remote_branches_context.go9
-rw-r--r--pkg/gui/context/remotes_context.go9
-rw-r--r--pkg/gui/context/simple_context.go41
-rw-r--r--pkg/gui/context/stash_context.go9
-rw-r--r--pkg/gui/context/sub_commits_context.go9
-rw-r--r--pkg/gui/context/submodules_context.go9
-rw-r--r--pkg/gui/context/suggestions_context.go9
-rw-r--r--pkg/gui/context/tags_context.go9
-rw-r--r--pkg/gui/context/view_trait.go8
-rw-r--r--pkg/gui/context/working_tree_context.go9
-rw-r--r--pkg/gui/context_config.go209
-rw-r--r--pkg/gui/controllers.go103
-rw-r--r--pkg/gui/controllers/bisect_controller.go2
-rw-r--r--pkg/gui/controllers/commits_files_controller.go10
-rw-r--r--pkg/gui/controllers/context_lines_controller.go116
-rw-r--r--pkg/gui/controllers/files_controller.go32
-rw-r--r--pkg/gui/controllers/helpers/patch_building_helper.go37
-rw-r--r--pkg/gui/controllers/list_controller.go37
-rw-r--r--pkg/gui/controllers/patch_building_controller.go138
-rw-r--r--pkg/gui/controllers/patch_explorer_controller.go289
-rw-r--r--pkg/gui/controllers/scroll_controller.go70
-rw-r--r--pkg/gui/controllers/staging_controller.go242
-rw-r--r--pkg/gui/custom_patch_options_panel.go (renamed from pkg/gui/patch_options_panel.go)34
-rw-r--r--pkg/gui/diff_context_size.go78
-rw-r--r--pkg/gui/diffing.go1
-rw-r--r--pkg/gui/files_panel.go36
-rw-r--r--pkg/gui/global_handlers.go47
-rw-r--r--pkg/gui/gui.go80
-rw-r--r--pkg/gui/gui_common.go22
-rw-r--r--pkg/gui/keybindings.go401
-rw-r--r--pkg/gui/layout.go64
-rw-r--r--pkg/gui/line_by_line_panel.go275
-rw-r--r--pkg/gui/list_context_config.go32
-rw-r--r--pkg/gui/main_panels.go91
-rw-r--r--pkg/gui/merge_panel.go12
-rw-r--r--pkg/gui/modes.go2
-rw-r--r--pkg/gui/options_menu_panel.go4
-rw-r--r--pkg/gui/patch_building_panel.go134
-rw-r--r--pkg/gui/patch_exploring/focus.go (renamed from pkg/gui/lbl/focus.go)2
-rw-r--r--pkg/gui/patch_exploring/focus_test.go (renamed from pkg/gui/lbl/focus_test.go)2
-rw-r--r--pkg/gui/patch_exploring/state.go (renamed from pkg/gui/lbl/state.go)19
-rw-r--r--pkg/gui/pty.go18
-rw-r--r--pkg/gui/recent_repos_panel.go1
-rw-r--r--pkg/gui/reflog_panel.go1
-rw-r--r--pkg/gui/refresh.go168
-rw-r--r--pkg/gui/remote_branches_panel.go1
-rw-r--r--pkg/gui/remotes_panel.go1
-rw-r--r--pkg/gui/services/custom_commands/keybinding_creator.go15
-rw-r--r--pkg/gui/side_window.go14
-rw-r--r--pkg/gui/staging_panel.go227
-rw-r--r--pkg/gui/stash_panel.go1
-rw-r--r--pkg/gui/status_panel.go3
-rw-r--r--pkg/gui/sub_commits_panel.go1
-rw-r--r--pkg/gui/submodules_panel.go1
-rw-r--r--pkg/gui/tags_panel.go9
-rw-r--r--pkg/gui/tasks_adapter.go6
-rw-r--r--pkg/gui/types/common.go4
-rw-r--r--pkg/gui/types/context.go40
-rw-r--r--pkg/gui/types/keybindings.go1
-rw-r--r--pkg/gui/types/refresh.go3
-rw-r--r--pkg/gui/view_helpers.go78
-rw-r--r--pkg/gui/views.go160
-rw-r--r--pkg/gui/window.go73
79 files changed, 2394 insertions, 1917 deletions
diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go
index 5ab8ab5dd..89236ae5c 100644
--- a/pkg/gui/arrangement.go
+++ b/pkg/gui/arrangement.go
@@ -105,20 +105,13 @@ func (gui *Gui) mainSectionChildren() []*boxlayout.Box {
}
}
- main := "main"
- secondary := "secondary"
- if gui.secondaryViewFocused() {
- // when you think you've focused the secondary view, we've actually just swapped them around in the layout
- main, secondary = secondary, main
- }
-
return []*boxlayout.Box{
{
- Window: main,
+ Window: "main",
Weight: 1,
},
{
- Window: secondary,
+ Window: "secondary",
Weight: 1,
},
}
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index a8593e9f3..aa03c9880 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -12,6 +12,7 @@ func (gui *Gui) branchesRenderToMain() error {
}
return gui.refreshMainViews(refreshMainOpts{
+ pair: gui.normalMainContextPair(),
main: &viewUpdateOpts{
title: gui.c.Tr.LogTitle,
task: task,
diff --git a/pkg/gui/command_log_panel.go b/pkg/gui/command_log_panel.go
index 409fa0023..33f410043 100644
--- a/pkg/gui/command_log_panel.go
+++ b/pkg/gui/command_log_panel.go
@@ -12,10 +12,10 @@ import (
)
// our UI command log looks like this:
-// Stage File
-// git add -- 'filename'
-// Unstage File
-// git reset HEAD 'filename'
+// Stage File:
+// git add -- 'filename'
+// Unstage File:
+// git reset HEAD 'filename'
//
// The 'Stage File' and 'Unstage File' lines are actions i.e they group up a set
// of command logs (typically there's only one command under an action but there may be more).
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index 5a3bb653a..213f2e2ae 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -2,14 +2,9 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
)
-// TODO: do we need this?
-func (gui *Gui) onCommitFileFocus() error {
- gui.escapeLineByLinePanel()
- return nil
-}
-
func (gui *Gui) commitFilesRenderToMain() error {
node := gui.State.Contexts.CommitFiles.GetSelected()
if node == nil {
@@ -23,16 +18,16 @@ func (gui *Gui) commitFilesRenderToMain() error {
cmdObj := gui.git.WorkingTree.ShowFileDiffCmdObj(from, to, reverse, node.GetPath(), false)
task := NewRunPtyTask(cmdObj.GetCmd())
- mainContext := gui.State.Contexts.Normal
+ pair := gui.normalMainContextPair()
if node.File != nil {
- mainContext = gui.State.Contexts.PatchBuilding
+ pair = gui.patchBuildingMainContextPair()
}
return gui.refreshMainViews(refreshMainOpts{
+ pair: pair,
main: &viewUpdateOpts{
- title: "Patch",
- task: task,
- context: mainContext,
+ title: gui.Tr.Patch,
+ task: task,
},
secondary: gui.secondaryPatchPanelUpdateOpts(),
})
@@ -46,33 +41,11 @@ func (gui *Gui) SwitchToCommitFilesContext(opts controllers.SwitchToCommitFilesC
gui.State.Contexts.CommitFiles.SetParentContext(opts.Context)
gui.State.Contexts.CommitFiles.SetWindowName(opts.Context.GetWindowName())
- if err := gui.refreshCommitFilesContext(); err != nil {
+ if err := gui.c.Refresh(types.RefreshOptions{
+ Scope: []types.RefreshableView{types.COMMIT_FILES},
+ }); err != nil {
return err
}
return gui.c.PushContext(gui.State.Contexts.CommitFiles)
}
-
-func (gui *Gui) refreshCommitFilesContext() error {
- ref := gui.State.Contexts.CommitFiles.GetRef()
- to := ref.RefName()
- from, reverse := gui.State.Modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
-
- files, err := gui.git.Loaders.CommitFiles.GetFilesInDiff(from, to, reverse)
- if err != nil {
- return gui.c.Error(err)
- }
- gui.State.Model.CommitFiles = files
- gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.SetTree()
-
- return gui.c.PostRefreshUpdate(gui.State.Contexts.CommitFiles)
-}
-
-func (gui *Gui) getSelectedCommitFileName() string {
- node := gui.State.Contexts.CommitFiles.GetSelected()
- if node == nil {
- return ""
- }
-
- return node.Path
-}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 126fac3a7..ee40b927a 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -25,8 +25,6 @@ func (gui *Gui) onCommitFocus() error {
})
}
- gui.escapeLineByLinePanel()
-
return nil
}
@@ -41,6 +39,7 @@ func (gui *Gui) branchCommitsRenderToMain() error {
}
return gui.refreshMainViews(refreshMainOpts{
+ pair: gui.normalMainContextPair(),
main: &viewUpdateOpts{
title: "Patch",
task: task,
@@ -49,6 +48,19 @@ func (gui *Gui) branchCommitsRenderToMain() error {
})
}
+func (gui *Gui) secondaryPatchPanelUpdateOpts() *viewUpdateOpts {
+ if gui.git.Patch.PatchManager.Active() {
+ patch := gui.git.Patch.PatchManager.RenderAggregatedPatchColored(false)
+
+ return &viewUpdateOpts{
+ task: NewRenderStringWithoutScrollTask(patch),
+ title: gui.Tr.CustomPatch,
+ }
+ }
+
+ return nil
+}
+
func (gui *Gui) refForLog() string {
bisectInfo := gui.git.Bisect.GetInfo()
gui.State.Model.BisectInfo = bisectInfo
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go
index 4177a689b..86ae41812 100644
--- a/pkg/gui/confirmation_panel.go
+++ b/pkg/gui/confirmation_panel.go
@@ -5,7 +5,6 @@ import (
"strings"
"github.com/jesseduffield/gocui"
- "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/theme"
@@ -221,25 +220,21 @@ func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
bindings := []*types.Binding{
{
ViewName: "confirmation",
- Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Confirm),
Handler: onConfirm,
},
{
ViewName: "confirmation",
- Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
Handler: onConfirm,
},
{
ViewName: "confirmation",
- Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Return),
Handler: gui.wrappedConfirmationFunction(opts.HandleClose),
},
{
ViewName: "confirmation",
- Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
Handler: func() error {
if len(gui.State.Suggestions) > 0 {
@@ -250,25 +245,21 @@ func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
},
{
ViewName: "suggestions",
- Contexts: []string{string(context.SUGGESTIONS_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Confirm),
Handler: onSuggestionConfirm,
},
{
ViewName: "suggestions",
- Contexts: []string{string(context.SUGGESTIONS_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
Handler: onSuggestionConfirm,
},
{
ViewName: "suggestions",
- Contexts: []string{string(context.SUGGESTIONS_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Return),
Handler: gui.wrappedConfirmationFunction(opts.HandleClose),
},
{
ViewName: "suggestions",
- Contexts: []string{string(context.SUGGESTIONS_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
Handler: func() error { return gui.replaceContext(gui.State.Contexts.Confirmation) },
},
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index f08acec06..e4719ab13 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -1,8 +1,6 @@
package gui
import (
- "errors"
- "fmt"
"sort"
"strings"
@@ -28,24 +26,6 @@ func (gui *Gui) popupViewNames() []string {
})
}
-func (gui *Gui) currentContextKeyIgnoringPopups() types.ContextKey {
- gui.State.ContextManager.RLock()
- defer gui.State.ContextManager.RUnlock()
-
- stack := gui.State.ContextManager.ContextStack
-
- for i := range stack {
- reversedIndex := len(stack) - 1 - i
- context := stack[reversedIndex]
- kind := stack[reversedIndex].GetKind()
- if kind != types.TEMPORARY_POPUP && kind != types.PERSISTENT_POPUP {
- return context.GetKey()
- }
- }
-
- return ""
-}
-
// use replaceContext when you don't want to return to the original context upon
// hitting escape: you want to go that context's parent instead.
func (gui *Gui) replaceContext(c types.Context) error {
@@ -64,31 +44,43 @@ func (gui *Gui) replaceContext(c types.Context) error {
defer gui.State.ContextManager.Unlock()
- return gui.activateContext(c)
+ return gui.activateContext(c, types.OnFocusOpts{})
}
-func (gui *Gui) pushContext(c types.Context, opts ...types.OnFocusOpts) error {
- // using triple dot but you should only ever pass one of these opt structs
- if len(opts) > 1 {
- return errors.New("cannot pass multiple opts to pushContext")
- }
-
+func (gui *Gui) pushContext(c types.Context, opts types.OnFocusOpts) error {
if !c.IsFocusable() {
return nil
}
+ contextsToDeactivate := gui.pushToContextStack(c)
+
+ for _, contextToDeactivate := range contextsToDeactivate {
+ if err := gui.deactivateContext(contextToDeactivate, types.OnFocusLostOpts{NewContextKey: c.GetKey()}); err != nil {
+ return err
+ }
+ }
+
+ return gui.activateContext(c, opts)
+}
+
+// Adjusts the context stack based on the context that's being pushed and returns contexts to deactivate
+func (gui *Gui) pushToContextStack(c types.Context) []types.Context {
+ contextsToDeactivate := []types.Context{}
+
gui.State.ContextManager.Lock()
+ defer gui.State.ContextManager.Unlock()
if len(gui.State.ContextManager.ContextStack) == 0 {
gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack, c)
} else if c.GetKind() == types.SIDE_CONTEXT {
// if we are switching to a side context, remove all other contexts in the stack
+ contextsToDeactivate = gui.State.ContextManager.ContextStack
+ gui.State.ContextManager.ContextStack = []types.Context{c}
+ } else if c.GetKind() == types.MAIN_CONTEXT {
+ // if we're switching to a main context, remove all other main contexts in the stack
for _, stackContext := range gui.State.ContextManager.ContextStack {
- if stackContext.GetKey() != c.GetKey() {
- if err := gui.deactivateContext(stackContext); err != nil {
- gui.State.ContextManager.Unlock()
- return err
- }
+ if stackContext.GetKind() == types.MAIN_CONTEXT {
+ contextsToDeactivate = append(contextsToDeactivate, stackContext)
}
}
gui.State.ContextManager.ContextStack = []types.Context{c}
@@ -101,12 +93,11 @@ func (gui *Gui) pushContext(c types.Context, opts ...types.OnFocusOpts) error {
// escape back to previous temporary popups, but because we're currently reusing
// views for this, you might not be able to get back to where you previously were.
// The exception is when going to the search context e.g. for searching a menu.
- if topContext.GetKind() == types.TEMPORARY_POPUP && c.GetKey() != context.SEARCH_CONTEXT_KEY {
- if err := gui.deactivateContext(topContext); err != nil {
- gui.State.ContextManager.Unlock()
- return err