summaryrefslogtreecommitdiffstats
path: root/pkg/gui/side_window.go
blob: 2aad00c37e1edd7e927076d6a4e90acaf1ac4218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gui

func (gui *Gui) nextSideWindow() error {
	windows := gui.getCyclableWindows()
	currentWindow := gui.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
			}
		}
	}
	if err := gui.resetOrigin(gui.Views.Main); err != nil {
		return err
	}

	viewName := gui.getViewNameForWindow(newWindow)

	return gui.pushContextWithView(viewName)
}

func (gui *Gui) previousSideWindow() error {
	windows := gui.getCyclableWindows()
	currentWindow := gui.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
			}
		}
	}
	if err := gui.resetOrigin(gui.Views.Main); err != nil {
		return err
	}

	viewName := gui.getViewNameForWindow(newWindow)

	return gui.pushContextWithView(viewName)
}

func (gui *Gui) goToSideWindow(sideViewName string) func() error {
	return func() error {
		return gui.pushContextWithView(sideViewName)
	}
}