2020-08-16 05:58:29 +02:00
|
|
|
package gui
|
|
|
|
|
2022-02-05 05:42:56 +02:00
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
2021-04-04 17:10:23 +02:00
|
|
|
|
2020-08-16 05:58:29 +02:00
|
|
|
// A window refers to a place on the screen which can hold one or more views.
|
|
|
|
// A view is a box that renders content, and within a window only one view will
|
|
|
|
// appear at a time. When a view appears within a window, it occupies the whole
|
|
|
|
// space. Right now most windows are 1:1 with views, except for commitFiles which
|
2020-08-23 02:13:56 +02:00
|
|
|
// is a view that moves between windows
|
2020-08-16 05:58:29 +02:00
|
|
|
|
|
|
|
func (gui *Gui) getViewNameForWindow(window string) string {
|
|
|
|
viewName, ok := gui.State.WindowViewNameMap[window]
|
|
|
|
if !ok {
|
|
|
|
return window
|
|
|
|
}
|
|
|
|
|
|
|
|
return viewName
|
|
|
|
}
|
|
|
|
|
2022-02-05 05:42:56 +02:00
|
|
|
// for now all we actually care about is the context's view so we're storing that
|
|
|
|
func (gui *Gui) setWindowContext(c types.Context) {
|
2020-08-16 05:58:29 +02:00
|
|
|
if gui.State.WindowViewNameMap == nil {
|
|
|
|
gui.State.WindowViewNameMap = map[string]string{}
|
|
|
|
}
|
|
|
|
|
2022-03-26 05:23:47 +02:00
|
|
|
if c.IsTransient() {
|
|
|
|
gui.resetWindowContext(c)
|
|
|
|
}
|
|
|
|
|
2022-02-05 05:42:56 +02:00
|
|
|
gui.State.WindowViewNameMap[c.GetWindowName()] = c.GetViewName()
|
2020-08-16 05:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) currentWindow() string {
|
2022-02-05 05:42:56 +02:00
|
|
|
return gui.currentContext().GetWindowName()
|
2020-08-16 05:58:29 +02:00
|
|
|
}
|
2020-08-21 12:08:42 +02:00
|
|
|
|
2022-03-26 05:23:47 +02:00
|
|
|
// assumes the context's windowName has been set to the new window if necessary
|
2022-02-05 05:42:56 +02:00
|
|
|
func (gui *Gui) resetWindowContext(c types.Context) {
|
2022-03-26 05:23:47 +02:00
|
|
|
for windowName, viewName := range gui.State.WindowViewNameMap {
|
|
|
|
if viewName == c.GetViewName() && windowName != c.GetWindowName() {
|
|
|
|
// we assume here that the window contains as its default view a view with the same name as the window
|
|
|
|
gui.State.WindowViewNameMap[windowName] = windowName
|
|
|
|
}
|
2022-03-24 13:07:30 +02:00
|
|
|
}
|
2020-08-21 12:08:42 +02:00
|
|
|
}
|