-
Notifications
You must be signed in to change notification settings - Fork 6
/
sourcePanel.go
64 lines (54 loc) · 1.37 KB
/
sourcePanel.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
package tutorial
import (
"context"
"fmt"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/action"
. "github.com/goradd/goradd/pkg/page/control"
"github.com/goradd/goradd/pkg/page/event"
"path/filepath"
)
const (
FileAction = iota + 1
CloseAction
)
type SourcePanel struct {
Panel
ButtonPanel *Panel
FilePanel *FilePanel
}
func NewSourcePanel(parent page.ControlI, id string) *SourcePanel {
p := &SourcePanel{}
p.Self = p
p.Init(parent, id)
return p
}
func (p *SourcePanel) Init(parent page.ControlI, id string) {
p.Panel.Init(parent, id)
p.ButtonPanel = NewPanel(p, "buttonPanel")
p.FilePanel = NewFilePanel(p) // we will be doing our own escaping
}
// show shows the panel and loads the button bar with buttons
func (p *SourcePanel) show(files []string) {
p.ButtonPanel.RemoveChildren()
for i, path := range files {
base := filepath.Base(path)
b := NewButton(p.ButtonPanel, "")
b.SetLabel(fmt.Sprintf("%d. %s", i, base))
b.SetActionValue(path)
b.On(event.Click(), action.Ajax(p.ID(), FileAction))
}
}
func (p *SourcePanel) Action(ctx context.Context, a action.Params) {
switch a.ID {
case FileAction:
file := a.ControlValueString()
p.FilePanel.SetFile(file)
}
}
func init() {
page.RegisterControl(&SourcePanel{})
}
func GetSourcePanel(p page.ControlI) *SourcePanel {
return p.Page().GetControl("sourcePanel").(*SourcePanel)
}