diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 1655420a..9e2143d7 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -1,6 +1,7 @@ package gui import ( + "github.com/golang-collections/collections/stack" "strings" "sync" @@ -117,7 +118,7 @@ type panelStates struct { type guiState struct { MenuItemCount int // can't store the actual list because it's of interface{} type - PreviousView string + PreviousViews *stack.Stack Platform commands.Platform Panels *panelStates SubProcessOutput string @@ -131,6 +132,10 @@ type guiState struct { // NewGui builds a new gui handler func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand *commands.OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*Gui, error) { + previousViews := stack.New() + // push dummy initial string + previousViews.Push("") + initialState := guiState{ Platform: *oSCommand.Platform, Panels: &panelStates{ @@ -144,7 +149,8 @@ func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand }, Project: &projectState{ContextIndex: 0}, }, - SessionIndex: 0, + SessionIndex: 0, + PreviousViews: previousViews, } cyclableViews := []string{"project", "containers", "images", "volumes"} diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 789af0e1..c62e5965 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -94,7 +94,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } currView := gui.g.CurrentView() - currentCyclebleView := gui.State.PreviousView + currentCyclebleView := gui.State.PreviousViews.Peek().(string) if currView != nil { viewName := currView.Name() usePreviouseView := true @@ -106,7 +106,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } } if usePreviouseView { - currentCyclebleView = gui.State.PreviousView + currentCyclebleView = gui.State.PreviousViews.Peek().(string) } } @@ -273,7 +273,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if gui.g.CurrentView() == nil { - v, err := gui.g.View(gui.State.PreviousView) + v, err := gui.g.View(gui.State.PreviousViews.Peek().(string)) if err != nil { viewName := gui.initiallyFocusedViewName() v, err = gui.g.View(viewName) diff --git a/pkg/gui/subprocess.go b/pkg/gui/subprocess.go index 7d2c72d0..6efa8ac2 100644 --- a/pkg/gui/subprocess.go +++ b/pkg/gui/subprocess.go @@ -22,7 +22,7 @@ func (gui *Gui) RunWithSubprocesses() error { break } else if err == gui.Errors.ErrSubProcess { // preparing the state for when we return - gui.State.PreviousView = gui.currentViewName() + gui.State.PreviousViews.Push(gui.currentViewName()) // giving goEvery goroutines time to finish gui.State.SessionIndex++ diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 797012b7..1268deba 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -103,7 +103,8 @@ func (gui *Gui) newLineFocused(v *gocui.View) error { } func (gui *Gui) returnFocus(g *gocui.Gui, v *gocui.View) error { - previousView, err := g.View(gui.State.PreviousView) + previousViewName := gui.State.PreviousViews.Pop().(string) + previousView, err := g.View(previousViewName) if err != nil { // always fall back to services view if there's no 'previous' view stored previousView, err = g.View(gui.initiallyFocusedViewName()) @@ -120,7 +121,7 @@ func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error { // we assume we'll never want to return focus to a popup panel i.e. // we should never stack popup panels if oldView != nil && !gui.isPopupPanel(oldView.Name()) { - gui.State.PreviousView = oldView.Name() + gui.State.PreviousViews.Push(oldView.Name()) } gui.Log.Info("setting highlight to true for view " + newView.Name())