1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-02 03:37:14 +02:00

refactoring

This commit is contained in:
Jesse Duffield 2021-06-05 15:08:36 +10:00
parent 82022615dd
commit 93bf691fd6
6 changed files with 53 additions and 35 deletions

View File

@ -5,11 +5,11 @@ import "github.com/jesseduffield/lazygit/pkg/commands/models"
// you can only copy from one context at a time, because the order and position of commits matter
func (gui *Gui) resetCherryPickingIfNecessary(context Context) error {
oldContextKey := gui.State.Modes.CherryPicking.ContextKey
oldContextKey := ContextKey(gui.State.Modes.CherryPicking.ContextKey)
if oldContextKey != context.GetKey() {
// need to reset the cherry picking mode
gui.State.Modes.CherryPicking.ContextKey = context.GetKey()
gui.State.Modes.CherryPicking.ContextKey = string(context.GetKey())
gui.State.Modes.CherryPicking.CherryPickedCommits = make([]*models.Commit, 0)
return gui.rerenderContextViewIfPresent(oldContextKey)
@ -156,7 +156,7 @@ func (gui *Gui) HandlePasteCommits() error {
}
func (gui *Gui) exitCherryPickingMode() error {
contextKey := gui.State.Modes.CherryPicking.ContextKey
contextKey := ContextKey(gui.State.Modes.CherryPicking.ContextKey)
gui.State.Modes.CherryPicking.ContextKey = ""
gui.State.Modes.CherryPicking.CherryPickedCommits = nil

View File

@ -3,10 +3,12 @@ package gui
import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
)
func (gui *Gui) exitDiffMode() error {
gui.State.Modes.Diffing = Diffing{}
gui.State.Modes.Diffing = diffing.New()
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
}
@ -145,7 +147,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error {
{
displayString: gui.Tr.LcExitDiffMode,
onPress: func() error {
gui.State.Modes.Diffing = Diffing{}
gui.State.Modes.Diffing = diffing.New()
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
},
},

View File

@ -21,6 +21,8 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/lbl"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
@ -269,31 +271,10 @@ const (
COMPLETE
)
// if ref is blank we're not diffing anything
type Diffing struct {
Ref string
Reverse bool
}
func (m *Diffing) Active() bool {
return m.Ref != ""
}
type CherryPicking struct {
CherryPickedCommits []*models.Commit
// we only allow cherry picking from one context at a time, so you can't copy a commit from the local commits context and then also copy a commit in the reflog context
ContextKey ContextKey
}
func (m *CherryPicking) Active() bool {
return len(m.CherryPickedCommits) > 0
}
type Modes struct {
Filtering filtering.Filtering
CherryPicking CherryPicking
Diffing Diffing
CherryPicking cherrypicking.CherryPicking
Diffing diffing.Diffing
}
type guiMutexes struct {
@ -424,12 +405,9 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) {
},
Ptmx: nil,
Modes: Modes{
Filtering: filtering.NewFiltering(filterPath),
CherryPicking: CherryPicking{
CherryPickedCommits: make([]*models.Commit, 0),
ContextKey: "",
},
Diffing: Diffing{},
Filtering: filtering.New(filterPath),
CherryPicking: cherrypicking.New(),
Diffing: diffing.New(),
},
ViewContextMap: contexts.initialViewContextMap(),
ViewTabContextMap: contexts.initialViewTabContextMap(),

View File

@ -0,0 +1,23 @@
package cherrypicking
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
type CherryPicking struct {
CherryPickedCommits []*models.Commit
// we only allow cherry picking from one context at a time, so you can't copy a commit from the local commits context and then also copy a commit in the reflog context
ContextKey string
}
func New() CherryPicking {
return CherryPicking{
CherryPickedCommits: make([]*models.Commit, 0),
ContextKey: "",
}
}
func (m *CherryPicking) Active() bool {
return len(m.CherryPickedCommits) > 0
}

View File

@ -0,0 +1,15 @@
package diffing
// if ref is blank we're not diffing anything
type Diffing struct {
Ref string
Reverse bool
}
func New() Diffing {
return Diffing{}
}
func (m *Diffing) Active() bool {
return m.Ref != ""
}

View File

@ -4,7 +4,7 @@ type Filtering struct {
path string // the filename that gets passed to git log
}
func NewFiltering(path string) Filtering {
func New(path string) Filtering {
return Filtering{path: path}
}