1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/window.go

45 lines
1.3 KiB
Go
Raw Normal View History

2020-08-16 05:58:29 +02:00
package gui
2021-04-04 17:10:23 +02:00
import "github.com/jesseduffield/gocui"
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
}
2021-04-04 17:10:23 +02:00
func (gui *Gui) getWindowForView(view *gocui.View) string {
if view == gui.Views.CommitFiles {
2021-04-03 06:56:11 +02:00
return gui.State.Contexts.CommitFiles.GetWindowName()
2020-08-16 05:58:29 +02:00
}
2021-04-04 17:10:23 +02:00
return view.Name()
2020-08-16 05:58:29 +02:00
}
2021-04-04 17:10:23 +02:00
func (gui *Gui) setViewAsActiveForWindow(view *gocui.View) {
2020-08-16 05:58:29 +02:00
if gui.State.WindowViewNameMap == nil {
gui.State.WindowViewNameMap = map[string]string{}
}
2021-04-04 17:10:23 +02:00
gui.State.WindowViewNameMap[gui.getWindowForView(view)] = view.Name()
2020-08-16 05:58:29 +02:00
}
func (gui *Gui) currentWindow() string {
2021-04-04 17:10:23 +02:00
return gui.getWindowForView(gui.g.CurrentView())
2020-08-16 05:58:29 +02:00
}
2020-08-21 12:08:42 +02:00
2021-04-04 17:10:23 +02:00
func (gui *Gui) resetWindowForView(view *gocui.View) {
window := gui.getWindowForView(view)
2020-08-21 12:08:42 +02:00
// we assume here that the window contains as its default view a view with the same name as the window
gui.State.WindowViewNameMap[window] = window
}