mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-10 04:07:18 +02:00
centralise split main panel code
This commit is contained in:
parent
a12d18146c
commit
0f7b2c45d7
@ -10,7 +10,7 @@ func (gui *Gui) mainSectionChildren() []*boxlayout.Box {
|
||||
|
||||
// if we're not in split mode we can just show the one main panel. Likewise if
|
||||
// the main panel is focused and we're in full-screen mode
|
||||
if !gui.State.SplitMainPanel || (gui.State.ScreenMode == SCREEN_FULL && currentViewName == "main") {
|
||||
if !gui.isMainPanelSplit() || (gui.State.ScreenMode == SCREEN_FULL && currentViewName == "main") {
|
||||
return []*boxlayout.Box{
|
||||
{
|
||||
ViewName: "main",
|
||||
@ -47,7 +47,7 @@ func (gui *Gui) getMidSectionWeights() (int, int) {
|
||||
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
|
||||
sideSectionWeight := 1
|
||||
|
||||
if gui.State.SplitMainPanel {
|
||||
if gui.isMainPanelSplit() {
|
||||
mainSectionWeight = 5 // need to shrink side panel to make way for main panels if side-by-side
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ func (gui *Gui) handleBranchSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Log"
|
||||
|
||||
|
@ -19,7 +19,7 @@ func (gui *Gui) exitDiffMode() error {
|
||||
|
||||
func (gui *Gui) renderDiff() error {
|
||||
gui.getMainView().Title = "Diff"
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
filterArg := ""
|
||||
if gui.inFilterMode() {
|
||||
filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath)
|
||||
|
@ -37,7 +37,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
||||
|
||||
file := gui.getSelectedFile()
|
||||
if file == nil {
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
gui.getMainView().Title = ""
|
||||
return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles"))
|
||||
}
|
||||
@ -53,12 +53,12 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
||||
|
||||
if file.HasInlineMergeConflicts {
|
||||
gui.getMainView().Title = gui.Tr.SLocalize("MergeConflictsTitle")
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
return gui.refreshMergePanel()
|
||||
}
|
||||
|
||||
if file.HasStagedChanges && file.HasUnstagedChanges {
|
||||
gui.State.SplitMainPanel = true
|
||||
gui.splitMainPanel(true)
|
||||
gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges")
|
||||
gui.getSecondaryView().Title = gui.Tr.SLocalize("StagedChanges")
|
||||
cmdStr := gui.GitCommand.DiffCmdStr(file, false, true)
|
||||
@ -67,7 +67,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
if file.HasUnstagedChanges {
|
||||
gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges")
|
||||
} else {
|
||||
|
@ -10,7 +10,7 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error {
|
||||
return gui.handleEscapePatchBuildingPanel()
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = true
|
||||
gui.splitMainPanel(true)
|
||||
|
||||
gui.getMainView().Title = "Patch"
|
||||
gui.getSecondaryView().Title = "Custom Patch"
|
||||
@ -80,7 +80,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error {
|
||||
|
||||
if gui.GitCommand.PatchManager.IsEmpty() {
|
||||
gui.GitCommand.PatchManager.Reset()
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
}
|
||||
|
||||
return gui.switchContext(gui.Contexts.BranchCommits.Files.Context)
|
||||
@ -88,7 +88,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error {
|
||||
|
||||
func (gui *Gui) refreshSecondaryPatchPanel() error {
|
||||
if gui.GitCommand.PatchManager.CommitSelected() {
|
||||
gui.State.SplitMainPanel = true
|
||||
gui.splitMainPanel(true)
|
||||
secondaryView := gui.getSecondaryView()
|
||||
secondaryView.Highlight = true
|
||||
secondaryView.Wrap = false
|
||||
@ -98,7 +98,7 @@ func (gui *Gui) refreshSecondaryPatchPanel() error {
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -23,7 +23,7 @@ func (gui *Gui) handleReflogCommitSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Reflog Entry"
|
||||
|
||||
|
@ -24,7 +24,7 @@ func (gui *Gui) handleRemoteBranchSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Remote Branch"
|
||||
|
||||
|
@ -27,7 +27,7 @@ func (gui *Gui) handleRemoteSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Remote"
|
||||
|
||||
|
@ -8,17 +8,10 @@ import (
|
||||
)
|
||||
|
||||
func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx int) error {
|
||||
gui.State.SplitMainPanel = true
|
||||
gui.splitMainPanel(true)
|
||||
|
||||
state := gui.State.Panels.LineByLine
|
||||
|
||||
// // We need to force focus here because the confirmation panel for safely staging lines does not return focus automatically.
|
||||
// // This is because if we tell it to return focus it will unconditionally return it to the main panel which may not be what we want
|
||||
// // e.g. in the event that there's nothing left to stage.
|
||||
// if err := gui.switchContext(nil, gui.getMainView()); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
file := gui.getSelectedFile()
|
||||
if file == nil {
|
||||
return gui.handleStagingEscape()
|
||||
|
@ -22,7 +22,7 @@ func (gui *Gui) handleStashEntrySelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Stash"
|
||||
|
||||
|
@ -93,7 +93,7 @@ func (gui *Gui) handleStatusSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = ""
|
||||
|
||||
|
@ -22,7 +22,7 @@ func (gui *Gui) handleTagSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Tag"
|
||||
|
||||
|
@ -368,3 +368,16 @@ func (gui *Gui) clearEditorView(v *gocui.View) {
|
||||
_ = v.SetCursor(0, 0)
|
||||
_ = v.SetOrigin(0, 0)
|
||||
}
|
||||
|
||||
func (gui *Gui) splitMainPanel(state bool) {
|
||||
gui.State.SplitMainPanel = state
|
||||
|
||||
// no need to set view on bottom when state is false: it will have zero size anyway thanks to our view arrangement code.
|
||||
if state {
|
||||
_, _ = gui.g.SetViewOnTop("secondary")
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) isMainPanelSplit() bool {
|
||||
return gui.State.SplitMainPanel
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user