mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-24 05:36:19 +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
|
// 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
|
// 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{
|
return []*boxlayout.Box{
|
||||||
{
|
{
|
||||||
ViewName: "main",
|
ViewName: "main",
|
||||||
@ -47,7 +47,7 @@ func (gui *Gui) getMidSectionWeights() (int, int) {
|
|||||||
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
|
mainSectionWeight := int(1/sidePanelWidthRatio) - 1
|
||||||
sideSectionWeight := 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
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = "Log"
|
gui.getMainView().Title = "Log"
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ func (gui *Gui) exitDiffMode() error {
|
|||||||
|
|
||||||
func (gui *Gui) renderDiff() error {
|
func (gui *Gui) renderDiff() error {
|
||||||
gui.getMainView().Title = "Diff"
|
gui.getMainView().Title = "Diff"
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
filterArg := ""
|
filterArg := ""
|
||||||
if gui.inFilterMode() {
|
if gui.inFilterMode() {
|
||||||
filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath)
|
filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath)
|
||||||
|
@ -37,7 +37,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
|||||||
|
|
||||||
file := gui.getSelectedFile()
|
file := gui.getSelectedFile()
|
||||||
if file == nil {
|
if file == nil {
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
gui.getMainView().Title = ""
|
gui.getMainView().Title = ""
|
||||||
return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles"))
|
return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles"))
|
||||||
}
|
}
|
||||||
@ -53,12 +53,12 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
|||||||
|
|
||||||
if file.HasInlineMergeConflicts {
|
if file.HasInlineMergeConflicts {
|
||||||
gui.getMainView().Title = gui.Tr.SLocalize("MergeConflictsTitle")
|
gui.getMainView().Title = gui.Tr.SLocalize("MergeConflictsTitle")
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
return gui.refreshMergePanel()
|
return gui.refreshMergePanel()
|
||||||
}
|
}
|
||||||
|
|
||||||
if file.HasStagedChanges && file.HasUnstagedChanges {
|
if file.HasStagedChanges && file.HasUnstagedChanges {
|
||||||
gui.State.SplitMainPanel = true
|
gui.splitMainPanel(true)
|
||||||
gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges")
|
gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges")
|
||||||
gui.getSecondaryView().Title = gui.Tr.SLocalize("StagedChanges")
|
gui.getSecondaryView().Title = gui.Tr.SLocalize("StagedChanges")
|
||||||
cmdStr := gui.GitCommand.DiffCmdStr(file, false, true)
|
cmdStr := gui.GitCommand.DiffCmdStr(file, false, true)
|
||||||
@ -67,7 +67,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
if file.HasUnstagedChanges {
|
if file.HasUnstagedChanges {
|
||||||
gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges")
|
gui.getMainView().Title = gui.Tr.SLocalize("UnstagedChanges")
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,7 +10,7 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error {
|
|||||||
return gui.handleEscapePatchBuildingPanel()
|
return gui.handleEscapePatchBuildingPanel()
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = true
|
gui.splitMainPanel(true)
|
||||||
|
|
||||||
gui.getMainView().Title = "Patch"
|
gui.getMainView().Title = "Patch"
|
||||||
gui.getSecondaryView().Title = "Custom Patch"
|
gui.getSecondaryView().Title = "Custom Patch"
|
||||||
@ -80,7 +80,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error {
|
|||||||
|
|
||||||
if gui.GitCommand.PatchManager.IsEmpty() {
|
if gui.GitCommand.PatchManager.IsEmpty() {
|
||||||
gui.GitCommand.PatchManager.Reset()
|
gui.GitCommand.PatchManager.Reset()
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.switchContext(gui.Contexts.BranchCommits.Files.Context)
|
return gui.switchContext(gui.Contexts.BranchCommits.Files.Context)
|
||||||
@ -88,7 +88,7 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error {
|
|||||||
|
|
||||||
func (gui *Gui) refreshSecondaryPatchPanel() error {
|
func (gui *Gui) refreshSecondaryPatchPanel() error {
|
||||||
if gui.GitCommand.PatchManager.CommitSelected() {
|
if gui.GitCommand.PatchManager.CommitSelected() {
|
||||||
gui.State.SplitMainPanel = true
|
gui.splitMainPanel(true)
|
||||||
secondaryView := gui.getSecondaryView()
|
secondaryView := gui.getSecondaryView()
|
||||||
secondaryView.Highlight = true
|
secondaryView.Highlight = true
|
||||||
secondaryView.Wrap = false
|
secondaryView.Wrap = false
|
||||||
@ -98,7 +98,7 @@ func (gui *Gui) refreshSecondaryPatchPanel() error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -23,7 +23,7 @@ func (gui *Gui) handleReflogCommitSelect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = "Reflog Entry"
|
gui.getMainView().Title = "Reflog Entry"
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func (gui *Gui) handleRemoteBranchSelect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = "Remote Branch"
|
gui.getMainView().Title = "Remote Branch"
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func (gui *Gui) handleRemoteSelect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = "Remote"
|
gui.getMainView().Title = "Remote"
|
||||||
|
|
||||||
|
@ -8,17 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx int) error {
|
func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx int) error {
|
||||||
gui.State.SplitMainPanel = true
|
gui.splitMainPanel(true)
|
||||||
|
|
||||||
state := gui.State.Panels.LineByLine
|
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()
|
file := gui.getSelectedFile()
|
||||||
if file == nil {
|
if file == nil {
|
||||||
return gui.handleStagingEscape()
|
return gui.handleStagingEscape()
|
||||||
|
@ -22,7 +22,7 @@ func (gui *Gui) handleStashEntrySelect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = "Stash"
|
gui.getMainView().Title = "Stash"
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ func (gui *Gui) handleStatusSelect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = ""
|
gui.getMainView().Title = ""
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func (gui *Gui) handleTagSelect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.SplitMainPanel = false
|
gui.splitMainPanel(false)
|
||||||
|
|
||||||
gui.getMainView().Title = "Tag"
|
gui.getMainView().Title = "Tag"
|
||||||
|
|
||||||
|
@ -368,3 +368,16 @@ func (gui *Gui) clearEditorView(v *gocui.View) {
|
|||||||
_ = v.SetCursor(0, 0)
|
_ = v.SetCursor(0, 0)
|
||||||
_ = v.SetOrigin(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…
x
Reference in New Issue
Block a user