summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-02-25 16:13:49 +0100
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-02-25 16:13:49 +0100
commit8e420c29832039bb4b01a5d1c8725763726ebff4 (patch)
treee263da955f1eebf12b56da77adec9cdb05bd764c
parentDataBinder: Some small fixes (diff)
downloadwireguard-windows-8e420c29832039bb4b01a5d1c8725763726ebff4.tar.xz
wireguard-windows-8e420c29832039bb4b01a5d1c8725763726ebff4.zip
boolProperty: Accept source of type Expression
-rw-r--r--declarative/builder.go4
-rw-r--r--property.go20
2 files changed, 23 insertions, 1 deletions
diff --git a/declarative/builder.go b/declarative/builder.go
index b01a110c..e376fd9d 100644
--- a/declarative/builder.go
+++ b/declarative/builder.go
@@ -683,6 +683,10 @@ func (se subExpressions) Get(name string) (interface{}, error) {
return nil, fmt.Errorf(`invalid sub expression: "%s"`, name)
}
+func (e *expression) String() string {
+ return e.text
+}
+
func (e *expression) Value() interface{} {
val, err := e.expr.Eval(e.subExprsByPath)
if err != nil {
diff --git a/property.go b/property.go
index 0230860f..55fc5043 100644
--- a/property.go
+++ b/property.go
@@ -8,6 +8,7 @@ package walk
import (
"errors"
+ "fmt"
)
var (
@@ -251,8 +252,25 @@ func (bp *boolProperty) SetSource(source interface{}) error {
bp.Set(source.Satisfied())
})
+ case Expression:
+ if err := checkPropertySource(bp, source); err != nil {
+ return err
+ }
+
+ if satisfied, ok := source.Value().(bool); ok {
+ if err := bp.Set(satisfied); err != nil {
+ return err
+ }
+ }
+
+ bp.sourceChangedHandle = source.Changed().Attach(func() {
+ if satisfied, ok := source.Value().(bool); ok {
+ bp.Set(satisfied)
+ }
+ })
+
default:
- return newError("invalid source type")
+ return newError(fmt.Sprintf(`invalid source: "%s" of type %T`, source, source))
}
}