summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-06-05 15:08:36 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-06-06 09:12:49 +1000
commit93bf691fd66cfd19702db2a674c73fbefc244467 (patch)
tree095f49a36f863a7559c17cc75c0e43d5216fabe3 /pkg
parent82022615ddc25ec5bc0631894e32d8dda380eac2 (diff)
refactoring
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/cherry_picking.go6
-rw-r--r--pkg/gui/diffing.go6
-rw-r--r--pkg/gui/gui.go36
-rw-r--r--pkg/gui/modes/cherrypicking/cherry_picking.go23
-rw-r--r--pkg/gui/modes/diffing/diffing.go15
-rw-r--r--pkg/gui/modes/filtering/filtering.go2
6 files changed, 53 insertions, 35 deletions
diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go
index fbda109b9..8f144084c 100644
--- a/pkg/gui/cherry_picking.go
+++ b/pkg/gui/cherry_picking.go
@@ -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
diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go
index 480bfc7fd..ef87b40da 100644
--- a/pkg/gui/diffing.go
+++ b/pkg/gui/diffing.go
@@ -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})
},
},
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 81f1e283c..7c4968dd7 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -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(),
diff --git a/pkg/gui/modes/cherrypicking/cherry_picking.go b/pkg/gui/modes/cherrypicking/cherry_picking.go
new file mode 100644
index 000000000..705735510
--- /dev/null
+++ b/pkg/gui/modes/cherrypicking/cherry_picking.go
@@ -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
+}
diff --git a/pkg/gui/modes/diffing/diffing.go b/pkg/gui/modes/diffing/diffing.go
new file mode 100644
index 000000000..a5e103d62
--- /dev/null
+++ b/pkg/gui/modes/diffing/diffing.go
@@ -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 != ""
+}
diff --git a/pkg/gui/modes/filtering/filtering.go b/pkg/gui/modes/filtering/filtering.go
index 010a04993..ca8026dc0 100644
--- a/pkg/gui/modes/filtering/filtering.go
+++ b/pkg/gui/modes/filtering/filtering.go
@@ -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}
}