mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
8edad826ca
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the gui package purely for the sake of better encapsulation
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package gui
|
|
|
|
func (gui *Gui) nextSideWindow() error {
|
|
windows := gui.getCyclableWindows()
|
|
currentWindow := gui.helpers.Window.CurrentWindow()
|
|
var newWindow string
|
|
if currentWindow == "" || currentWindow == windows[len(windows)-1] {
|
|
newWindow = windows[0]
|
|
} else {
|
|
for i := range windows {
|
|
if currentWindow == windows[i] {
|
|
newWindow = windows[i+1]
|
|
break
|
|
}
|
|
if i == len(windows)-1 {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
gui.c.ResetViewOrigin(gui.Views.Main)
|
|
|
|
context := gui.helpers.Window.GetContextForWindow(newWindow)
|
|
|
|
return gui.c.PushContext(context)
|
|
}
|
|
|
|
func (gui *Gui) previousSideWindow() error {
|
|
windows := gui.getCyclableWindows()
|
|
currentWindow := gui.helpers.Window.CurrentWindow()
|
|
var newWindow string
|
|
if currentWindow == "" || currentWindow == windows[0] {
|
|
newWindow = windows[len(windows)-1]
|
|
} else {
|
|
for i := range windows {
|
|
if currentWindow == windows[i] {
|
|
newWindow = windows[i-1]
|
|
break
|
|
}
|
|
if i == len(windows)-1 {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
gui.c.ResetViewOrigin(gui.Views.Main)
|
|
|
|
context := gui.helpers.Window.GetContextForWindow(newWindow)
|
|
|
|
return gui.c.PushContext(context)
|
|
}
|
|
|
|
func (gui *Gui) goToSideWindow(window string) func() error {
|
|
return func() error {
|
|
context := gui.helpers.Window.GetContextForWindow(window)
|
|
|
|
return gui.c.PushContext(context)
|
|
}
|
|
}
|
|
|
|
func (gui *Gui) getCyclableWindows() []string {
|
|
return []string{"status", "files", "branches", "commits", "stash"}
|
|
}
|