func newValueView(val types.Object, currentPkg *types.Package) *typeView { var t *types.Type name := new(string) switch val := val.(type) { case *types.Var: t, name = &val.Type, &val.Name case *types.Func: if isMethod(val) { m := types.Type(val.Type) t, name = &m, &val.Name } case field: t = &val.Type if !val.Anonymous { name = &val.Name } } v := newTypeView(t, currentPkg) v.val = val v.name = NewText(*name) v.name.SetTextColor(color(val, true, false)) v.name.SetBackgroundColor(noColor) v.name.Validate = validateID v.name.TextChanged = func(text string) { *name = text v.reform() } v.Add(v.name) v.reform() return v }
func (v *typeView) editType(done func()) { switch t := (*v.typ).(type) { case nil: opts := browserOptions{acceptTypes: true} opts.objFilter = map[typeViewMode]func(types.Object) bool{ anyType: isType, comparableType: isComparableType, compositeOrPtrType: isCompositeOrPtrType, compositeType: isCompositeType, makeableType: isMakeableType, }[v.mode] b := newBrowser(opts, v) v.Add(b) b.Move(Center(v)) b.accepted = func(obj types.Object) { b.Close() n := obj.(*types.TypeName) if n.Type != nil { v.setType(n.Type) } else { v.setType(newProtoType(n)) } v.editType(done) } b.canceled = func() { b.Close() done() } SetKeyFocus(b) case *types.Basic, *types.Named: done() case *types.Pointer, *types.Array, *types.Slice, *types.Chan: if elt := v.elems.right[0]; *elt.typ == nil { elt.editType(func() { if *elt.typ == nil { v.setType(nil) } v.editType(done) }) } else { done() } case *types.Map: key := v.elems.left[0] val := v.elems.right[0] switch types.Type(nil) { case *key.typ: key.editType(func() { if *key.typ == nil { v.setType(nil) } v.editType(done) }) case *val.typ: val.editType(func() { if *val.typ == nil { key.setType(nil) } v.editType(done) }) default: done() } case *types.Struct: v.addVars(&t.Fields, &v.elems.right, done) case *types.Signature: v.addVars(&t.Params, &v.elems.left, func() { v.addVars(&t.Results, &v.elems.right, done) }) case *types.Interface: v.addMethods(&t.Methods, &v.elems.right, done) } }