-
Notifications
You must be signed in to change notification settings - Fork 3
/
textwidget.go
56 lines (47 loc) · 1.3 KB
/
textwidget.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
package main
import (
"fmt"
"github.com/chenqinghe/walk"
)
type TabWidgetEx struct {
*walk.TabWidget
root *MainWindowEX
pages []*TabPageEx
}
func (tw *TabWidgetEx) startNewSession(sess Session) {
tabPage, err := tw.NewTabPageEx()
if err != nil {
walk.MsgBox(nil, "ERROR", "新建标签页失败:"+err.Error(), walk.MsgBoxIconError)
return
}
tw.SetCurrentIndex(tw.Pages().Len() - 1)
tabPage.SetTitle(fmt.Sprintf("%s:%d", sess.Host, sess.Port))
tabPage.content.SetText("")
tabPage.content.AppendText(fmt.Sprintf("connecting to %s:%d ......\r\n", sess.Host, sess.Port))
go func() {
conn, err := DialRedis(sess.Host, sess.Port, sess.Password)
if err != nil {
tabPage.content.AppendText(err.Error())
return
}
tabPage.conn = conn
if r := execCmd(conn, "PING"); r != "PONG" {
tabPage.content.AppendText(r + "\r\n")
return
}
tabPage.content.AppendText("连接成功!\r\n\r\n")
tabPage.content.AppendText("> ")
tabPage.content.SetReadOnly(false)
}()
}
func (tw *TabWidgetEx) AddPage(page *TabPageEx) {
tw.Pages().Add(page.TabPage)
tw.pages = append(tw.pages, page)
}
func (tw *TabWidgetEx) CurrentPage() *TabPageEx {
idx := tw.CurrentIndex()
if idx > 0 {
return tw.pages[idx-1] // TODO: tw.Pages() contains home page, if home page could be remove, idx not -1
}
return nil
}