-
Notifications
You must be signed in to change notification settings - Fork 1
/
tab_privmsg.go
115 lines (98 loc) · 2.68 KB
/
tab_privmsg.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"math/rand"
"github.com/lxn/walk"
"github.com/lxn/win"
)
type tabPrivmsg struct {
tabChatbox
send func(string)
nickColor func(string) int
}
func (t *tabPrivmsg) NickColor(nick string) int {
return t.nickColor(nick)
}
func (t *tabPrivmsg) Send(message string) {
t.send(message)
}
func (t *tabPrivmsg) Update(servState *serverState, pmState *privmsgState) {
t.disconnected = servState.connState != CONNECTED
t.statusIcon = servState.tab.statusIcon
t.statusText = servState.tab.statusText
if t.tabPage != nil {
mw.WindowBase.Synchronize(func() {
t.tabPage.SetTitle(t.Title())
if t.HasFocus() {
SetStatusBarIcon(t.statusIcon)
SetStatusBarText(t.statusText)
}
})
}
SetSystrayContextMenu()
}
func newPrivmsgTab(servConn *serverConnection, servState *serverState, pmState *privmsgState, tabIndex int) *tabPrivmsg {
t := &tabPrivmsg{}
t.tabTitle = pmState.nick
t.send = func(msg string) {
servConn.conn.Privmsg(pmState.nick, msg)
nick := newNick(servState.user.nick)
privateMessage(t, nick.String(), msg)
}
color := rand.Intn(98)
t.nickColor = func(nick string) int {
if nick == servState.user.nick {
return DarkGray
}
return color
}
t.chatlogger = NewChatLogger(servState.networkName + "-" + pmState.nick)
mw.WindowBase.Synchronize(func() {
var err error
t.tabPage, err = walk.NewTabPage()
checkErr(err)
t.tabPage.SetTitle(t.tabTitle)
t.tabPage.SetLayout(walk.NewVBoxLayout())
t.textBuffer, err = NewRichEdit(t.tabPage)
checkErr(err)
// WTF(tso): textBuffer (*RichEdit) is already attached
// to t.tabPage (*walk.TabPage) because of walk.InitWidget but that
// *doesn't happen* when you use the walk/declarative interface
// wtf -tso 7/12/2018 1:54:43 AM
// checkErr(t.tabPage.Children().Add(t.textBuffer))
t.textInput = NewTextInput(t)
checkErr(t.tabPage.Children().Add(t.textInput))
// remove borders
win.SetWindowLong(t.textInput.Handle(), win.GWL_EXSTYLE, 0)
{
index := servState.tab.Index()
if servState.channelList != nil {
index = servState.channelList.Index()
}
for _, ch := range servState.channels {
i := ch.tab.Index()
if i > index {
index = i
}
}
for _, pm := range servState.privmsgs {
i := pm.tab.Index()
if i > index {
index = i
}
}
index++
checkErr(tabWidget.Pages().Insert(index, t.tabPage))
}
// NOTE(tso): don't steal focus
// index := tabWidget.Pages().Index(t.tabPage)
// checkErr(tabWidget.SetCurrentIndex(index))
tabWidget.SaveState()
pmState.tab = t
servState.privmsgs[pmState.nick] = pmState
servState.tab.Update(servState)
})
mw.Synchronize(func() {
applyThemeToTab(t)
})
return t
}