2024-06-22 05:36:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-23 01:07:33 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/redis/go-redis/v9"
|
2024-06-22 05:36:25 +00:00
|
|
|
"github.com/ying32/govcl/vcl"
|
|
|
|
"github.com/ying32/govcl/vcl/types"
|
|
|
|
)
|
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
type TRedisConnectionDialogResult = *redis.Options
|
|
|
|
|
2024-06-22 05:36:25 +00:00
|
|
|
type TRedisConnectionDialog struct {
|
|
|
|
*vcl.TForm
|
|
|
|
|
|
|
|
Address *vcl.TEdit
|
|
|
|
Port *vcl.TSpinEdit
|
|
|
|
Password *vcl.TEdit
|
|
|
|
IsResp3Protocol *vcl.TCheckBox
|
2024-06-23 01:07:33 +00:00
|
|
|
ConnectBtn *vcl.TButton
|
|
|
|
|
|
|
|
// CustomReturn must be set by the caller to a *redis.Options variable.
|
|
|
|
CustomReturn *TRedisConnectionDialogResult // nil = no CustomReturn/cancelled dialog
|
2024-06-22 05:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TRedisConnectionDialog) OnFormCreate(sender vcl.IObject) {
|
|
|
|
|
|
|
|
f.SetCaption("Connect to Redis...")
|
2024-06-23 01:07:33 +00:00
|
|
|
f.SetWidth(320)
|
|
|
|
f.SetHeight(160)
|
2024-06-29 23:05:25 +00:00
|
|
|
f.SetPosition(types.PoOwnerFormCenter)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
|
|
|
// row 1
|
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
row1 := vcl_row(f, 1)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
lblAddress := vcl.NewLabel(row1)
|
2024-06-22 05:36:25 +00:00
|
|
|
lblAddress.SetParent(row1)
|
|
|
|
lblAddress.SetCaption("Address:")
|
|
|
|
lblAddress.SetAlign(types.AlLeft)
|
2024-06-23 01:07:33 +00:00
|
|
|
lblAddress.SetLayout(types.TlCenter)
|
2024-06-22 05:36:25 +00:00
|
|
|
lblAddress.SetLeft(1)
|
2024-06-23 01:07:33 +00:00
|
|
|
lblAddress.BorderSpacing().SetAround(MY_SPACING)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
|
|
|
f.Address = vcl.NewEdit(row1)
|
|
|
|
f.Address.SetParent(row1)
|
2024-06-23 01:07:33 +00:00
|
|
|
f.Address.SetAlign(types.AlClient) // grow AlLeft)
|
2024-06-22 05:36:25 +00:00
|
|
|
f.Address.SetWidth(MY_WIDTH)
|
|
|
|
f.Address.SetLeft(2)
|
2024-06-23 01:07:33 +00:00
|
|
|
f.Address.SetText("127.0.0.1")
|
|
|
|
f.Address.BorderSpacing().SetAround(MY_SPACING)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
lblPort := vcl.NewLabel(row1)
|
2024-06-22 05:36:25 +00:00
|
|
|
lblPort.SetParent(row1)
|
|
|
|
lblPort.SetCaption(":")
|
2024-06-23 01:07:33 +00:00
|
|
|
lblPort.SetAlign(types.AlRight)
|
|
|
|
lblPort.SetLayout(types.TlCenter)
|
|
|
|
lblPort.SetLeft(0)
|
2024-06-22 05:36:25 +00:00
|
|
|
lblPort.SetAutoSize(true)
|
2024-06-23 01:07:33 +00:00
|
|
|
lblPort.BorderSpacing().SetAround(MY_SPACING)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
|
|
|
f.Port = vcl.NewSpinEdit(row1)
|
|
|
|
f.Port.SetParent(row1)
|
|
|
|
f.Port.SetMinValue(1)
|
|
|
|
f.Port.SetMaxValue(65535)
|
|
|
|
f.Port.SetValue(6379) // Redis default port
|
2024-06-23 01:07:33 +00:00
|
|
|
f.Port.SetAlign(types.AlRight)
|
|
|
|
f.Port.SetLeft(1000)
|
|
|
|
f.Port.BorderSpacing().SetAround(MY_SPACING)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
|
|
|
// row 2
|
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
row2 := vcl_row(f, 2)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
lblPassword := vcl.NewLabel(row2)
|
2024-06-22 05:36:25 +00:00
|
|
|
lblPassword.SetParent(row2)
|
|
|
|
lblPassword.SetCaption("Password:")
|
|
|
|
lblPassword.SetAlign(types.AlLeft)
|
2024-06-23 01:07:33 +00:00
|
|
|
lblPassword.SetLayout(types.TlCenter)
|
2024-06-22 05:36:25 +00:00
|
|
|
lblPassword.SetLeft(1)
|
2024-06-23 01:07:33 +00:00
|
|
|
lblPassword.BorderSpacing().SetAround(MY_SPACING)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
|
|
|
f.Password = vcl.NewEdit(row2)
|
|
|
|
f.Password.SetParent(row2)
|
2024-06-23 01:07:33 +00:00
|
|
|
f.Password.SetAlign(types.AlClient) // grow
|
2024-06-22 05:36:25 +00:00
|
|
|
f.Password.SetLeft(2)
|
|
|
|
f.Password.SetWidth(MY_WIDTH)
|
|
|
|
f.Password.SetPasswordChar(uint16('*'))
|
2024-06-23 01:07:33 +00:00
|
|
|
f.Password.BorderSpacing().SetAround(MY_SPACING)
|
2024-06-22 05:36:25 +00:00
|
|
|
|
|
|
|
// row 3
|
|
|
|
|
|
|
|
f.IsResp3Protocol = vcl.NewCheckBox(f)
|
|
|
|
f.IsResp3Protocol.SetParent(f)
|
|
|
|
f.IsResp3Protocol.SetCaption("Use RESP v3 protocol")
|
|
|
|
f.IsResp3Protocol.SetChecked(true)
|
|
|
|
f.IsResp3Protocol.SetAlign(types.AlTop)
|
|
|
|
f.IsResp3Protocol.SetTop(3)
|
2024-06-23 01:07:33 +00:00
|
|
|
f.IsResp3Protocol.BorderSpacing().SetAround(MY_SPACING)
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
|
|
|
|
row4 := vcl_row(f, 4)
|
|
|
|
row4.SetAlign(types.AlBottom)
|
|
|
|
|
|
|
|
f.ConnectBtn = vcl.NewButton(row4)
|
|
|
|
f.ConnectBtn.SetParent(row4)
|
|
|
|
f.ConnectBtn.SetAlign(types.AlRight)
|
|
|
|
f.ConnectBtn.SetCaption("Connect")
|
|
|
|
f.ConnectBtn.SetOnClick(f.OnConnectBtnClick)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *TRedisConnectionDialog) OnConnectBtnClick(sender vcl.IObject) {
|
|
|
|
|
|
|
|
ret := &redis.Options{
|
|
|
|
Addr: fmt.Sprintf("%s:%d", f.Address.Text(), f.Port.Value()),
|
|
|
|
Password: f.Password.Text(),
|
|
|
|
DB: 0, // Start off with default DB, but, we will browse them ourselves
|
|
|
|
Protocol: 2, // RESP2
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.IsResp3Protocol.Checked() {
|
|
|
|
ret.Protocol = 3 // RESP3
|
|
|
|
}
|
2024-06-22 05:36:25 +00:00
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
// Success.
|
|
|
|
// Fill in target pointer and close dialog with "MrOk" sentinel
|
|
|
|
*f.CustomReturn = ret
|
|
|
|
f.SetModalResult(types.MrOk)
|
2024-06-22 05:36:25 +00:00
|
|
|
}
|