/
convert.go
58 lines (51 loc) · 1.13 KB
/
convert.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
// Copyright 2014 Gordon Klaus. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/gordonklaus/flux/go/types"
. "github.com/gordonklaus/flux/gui"
)
type convertNode struct {
*nodeBase
}
func newConvertNode(currentPkg *types.Package) *convertNode {
n := &convertNode{}
n.nodeBase = newNodeBase(n)
in := n.newInput(nil)
out := n.newOutput(nil)
in.connsChanged = func() {
t := untypedToTyped(inputType(in))
in.setType(t)
if t != nil {
out.setType(*n.typ.typ)
} else {
out.setType(nil)
}
}
n.typ = newTypeView(new(types.Type), currentPkg)
n.typ.mode = anyType
n.Add(n.typ)
return n
}
func (n *convertNode) editType() {
n.typ.editType(func() {
if t := *n.typ.typ; t != nil {
n.setType(t)
} else {
n.blk.removeNode(n)
SetKeyFocus(n.blk)
}
})
}
func (n *convertNode) setType(t types.Type) {
n.typ.setType(t)
if t != nil {
n.blk.func_().addPkgRef(t)
n.reform()
SetKeyFocus(n)
}
}
func (n *convertNode) connectable(t types.Type, dst *port) bool {
return types.ConvertibleTo(t, *n.typ.typ)
}