-
Notifications
You must be signed in to change notification settings - Fork 1
/
tab_common.go
91 lines (73 loc) · 1.86 KB
/
tab_common.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"github.com/lxn/walk"
)
type tab interface {
Index() int
Title() string
StatusIcon() string
StatusText() string
HasFocus() bool
Focus()
Close()
}
type tabWithInput interface {
tab // inherit all from above
Send(string) // send to channel/nick
}
type tabWithTextBuffer interface {
tab
Padlen(string) int // just shoehorning this in here for now
NickColor(string) int // ditto
Logln(string) // chatlogging
Errorln(string, [][]int) // print error to buffer
Println(string, [][]int) // print text to buffer
// TODO(tso): better name for Notify/t.notify/asterisk what are words
Notify(bool) // put a * in the tab title
Clear() // clear buffer
}
type tabCommon struct {
tabTitle string
tabPage *walk.TabPage
statusIcon string
statusText string
}
func (t *tabCommon) Index() int {
return tabWidget.Pages().Index(t.tabPage)
}
func (t *tabCommon) StatusIcon() string {
return t.statusIcon
}
func (t *tabCommon) StatusText() string {
return t.statusText
}
func (t *tabCommon) Title() string { return "##################" }
func (t *tabCommon) Focus() {}
func (t *tabCommon) HasFocus() bool {
return mainWindowFocused && t.Index() == tabWidget.CurrentIndex()
}
func (t *tabCommon) Close() {
// for when we implement closing tabs in ways other than /close
shouldChangeTabFocus := t.HasFocus()
myIndexWas := t.Index()
mw.Synchronize(func() {
tabWidget.SetCurrentIndex(0)
checkErr(tabWidget.Pages().Remove(t.tabPage))
t.tabPage.Dispose()
tabWidget.SaveState()
if tabWidget.Pages().Len() == 0 {
tabWidget.Pages().Clear()
shouldChangeTabFocus = false
}
if shouldChangeTabFocus {
newIndex := myIndexWas - 1
if newIndex < 0 {
newIndex = 0
}
checkErr(tabWidget.SetCurrentIndex(newIndex))
tabWidget.SaveState()
} else {
tabWidget.SetCurrentIndex(tabWidget.CurrentIndex())
}
})
}