MCPcopy
hub / github.com/lxn/walk / SetSource

Method SetSource

property.go:232–284  ·  view source on GitHub ↗
(source interface{})

Source from the content-addressed store, hash-verified

230}
231
232func (bp *boolProperty) SetSource(source interface{}) error {
233 if bp.ReadOnly() {
234 return ErrPropertyReadOnly
235 }
236
237 if source != nil {
238 switch source := source.(type) {
239 case string:
240 // nop
241
242 case Condition:
243 if err := checkPropertySource(bp, source); err != nil {
244 return err
245 }
246
247 if err := bp.Set(source.Satisfied()); err != nil {
248 return err
249 }
250
251 bp.sourceChangedHandle = source.Changed().Attach(func() {
252 bp.Set(source.Satisfied())
253 })
254
255 case Expression:
256 if err := checkPropertySource(bp, source); err != nil {
257 return err
258 }
259
260 if satisfied, ok := source.Value().(bool); ok {
261 if err := bp.Set(satisfied); err != nil {
262 return err
263 }
264 }
265
266 bp.sourceChangedHandle = source.Changed().Attach(func() {
267 if satisfied, ok := source.Value().(bool); ok {
268 bp.Set(satisfied)
269 }
270 })
271
272 default:
273 return newError(fmt.Sprintf(`invalid source: "%s" of type %T`, source, source))
274 }
275 }
276
277 if oldCond, ok := bp.source.(Condition); ok {
278 oldCond.Changed().Detach(bp.sourceChangedHandle)
279 }
280
281 bp.source = source
282
283 return nil
284}
285
286func (bp *boolProperty) Validatable() bool {
287 return false

Callers

nothing calls this directly

Calls 9

ReadOnlyMethod · 0.95
SetMethod · 0.95
checkPropertySourceFunction · 0.85
newErrorFunction · 0.85
SatisfiedMethod · 0.65
ChangedMethod · 0.65
ValueMethod · 0.65
AttachMethod · 0.45
DetachMethod · 0.45

Tested by

no test coverage detected