summaryrefslogtreecommitdiffstats
path: root/pkg/gui/gui.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-22 11:05:37 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commitfbd61fcd17d495e9605bcf1f765663f861839cac (patch)
treed5d9eaa12e3e5fbefa5c50282af8f8207d5bb6a3 /pkg/gui/gui.go
parentb1529f19ad527d29a469de09c11c37d7f61d8d16 (diff)
refactor how we handle different modes
Diffstat (limited to 'pkg/gui/gui.go')
-rw-r--r--pkg/gui/gui.go45
1 files changed, 33 insertions, 12 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index b0249b37a..7cebf5362 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -227,11 +227,25 @@ const (
)
// if ref is blank we're not diffing anything
-type DiffState struct {
+type Diffing struct {
Ref string
Reverse bool
}
+type Filtering struct {
+ Path string // the filename that gets passed to git log
+}
+
+type CherryPicking struct {
+ CherryPickedCommits []*commands.Commit
+}
+
+type Modes struct {
+ Filtering Filtering
+ CherryPicking CherryPicking
+ Diffing Diffing
+}
+
type guiState struct {
Files []*commands.File
Branches []*commands.Branch
@@ -253,7 +267,6 @@ type guiState struct {
Updating bool
Panels *panelStates
MainContext string // used to keep the main and secondary views' contexts in sync
- CherryPickedCommits []*commands.Commit
SplitMainPanel bool
RetainOriginalDir bool
IsRefreshingFiles bool
@@ -266,9 +279,9 @@ type guiState struct {
PrevMainWidth int
PrevMainHeight int
OldInformation string
- StartupStage int // one of INITIAL and COMPLETE. Allows us to not load everything at once
- FilterPath string // the filename that gets passed to git log
- Diff DiffState
+ StartupStage int // one of INITIAL and COMPLETE. Allows us to not load everything at once
+
+ Modes Modes
ContextStack []Context
ViewContextMap map[string]Context
@@ -284,10 +297,20 @@ type guiState struct {
func (gui *Gui) resetState() {
// we carry over the filter path and diff state
prevFilterPath := ""
- prevDiff := DiffState{}
+ prevDiff := Diffing{}
if gui.State != nil {
- prevFilterPath = gui.State.FilterPath
- prevDiff = gui.State.Diff
+ prevFilterPath = gui.State.Modes.Filtering.Path
+ prevDiff = gui.State.Modes.Diffing
+ }
+
+ modes := Modes{
+ Filtering: Filtering{
+ Path: prevFilterPath,
+ },
+ CherryPicking: CherryPicking{
+ CherryPickedCommits: make([]*commands.Commit, 0),
+ },
+ Diffing: prevDiff,
}
gui.State = &guiState{
@@ -295,7 +318,6 @@ func (gui *Gui) resetState() {
Commits: make([]*commands.Commit, 0),
FilteredReflogCommits: make([]*commands.Commit, 0),
ReflogCommits: make([]*commands.Commit, 0),
- CherryPickedCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0),
Panels: &panelStates{
// TODO: work out why some of these are -1 and some are 0. Last time I checked there was a good reason but I'm less certain now
@@ -319,8 +341,7 @@ func (gui *Gui) resetState() {
},
SideView: nil,
Ptmx: nil,
- FilterPath: prevFilterPath,
- Diff: prevDiff,
+ Modes: modes,
ViewContextMap: gui.initialViewContextMap(),
}
}
@@ -341,7 +362,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
}
gui.resetState()
- gui.State.FilterPath = filterPath
+ gui.State.Modes.Filtering.Path = filterPath
gui.Contexts = gui.contextTree()
gui.ViewTabContextMap = gui.viewTabContextMap()