-
Notifications
You must be signed in to change notification settings - Fork 0
/
filevalueview.go
80 lines (69 loc) · 2.03 KB
/
filevalueview.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
// Copyright (c) 2018, The GoKi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package giv
import (
"reflect"
"github.com/goki/gi/gi"
"github.com/goki/gi/units"
"github.com/goki/ki/ki"
"github.com/goki/ki/kit"
)
////////////////////////////////////////////////////////////////////////////////////////
// FileValueView
// FileValueView presents an action for displaying a FileName and selecting
// icons from FileChooserDialog
type FileValueView struct {
ValueViewBase
}
var KiT_FileValueView = kit.Types.AddType(&FileValueView{}, nil)
func (vv *FileValueView) WidgetType() reflect.Type {
vv.WidgetTyp = gi.KiT_Action
return vv.WidgetTyp
}
func (vv *FileValueView) UpdateWidget() {
if vv.Widget == nil {
return
}
ac := vv.Widget.(*gi.Action)
txt := kit.ToString(vv.Value.Interface())
if txt == "" {
txt = "(click to open file chooser)"
}
ac.SetText(txt)
}
func (vv *FileValueView) ConfigWidget(widg gi.Node2D) {
vv.Widget = widg
vv.StdConfigWidget(widg)
ac := vv.Widget.(*gi.Action)
ac.SetProp("border-radius", units.NewPx(4))
ac.ActionSig.ConnectOnly(vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
vvv, _ := recv.Embed(KiT_FileValueView).(*FileValueView)
ac := vvv.Widget.(*gi.Action)
vvv.Activate(ac.Viewport, nil, nil)
})
vv.UpdateWidget()
}
func (vv *FileValueView) HasAction() bool {
return true
}
func (vv *FileValueView) Activate(vp *gi.Viewport2D, dlgRecv ki.Ki, dlgFunc ki.RecvFunc) {
if vv.IsInactive() {
return
}
cur := kit.ToString(vv.Value.Interface())
ext, _ := vv.Tag("ext")
desc, _ := vv.Tag("desc")
FileViewDialog(vp, cur, ext, DlgOpts{Title: vv.Name(), Prompt: desc}, nil,
vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if sig == int64(gi.DialogAccepted) {
dlg, _ := send.Embed(gi.KiT_Dialog).(*gi.Dialog)
fn := FileViewDialogValue(dlg)
vv.SetValue(fn)
vv.UpdateWidget()
}
if dlgRecv != nil && dlgFunc != nil {
dlgFunc(dlgRecv, send, sig, data)
}
})
}