gui, lib/config, lib/model: Support auto-accepting folders (fixes #2299)
Also introduces a new Waiter interface for config changes and segments the configuration GUI. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4551
This commit is contained in:
committed by
Jakob Borg
parent
c005b8dcb0
commit
445c4edeca
@@ -7,6 +7,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"sort"
|
||||
@@ -70,6 +71,31 @@ func SetDefaults(data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CopyMatchingTag copies fields tagged tag:"value" from "from" struct onto "to" struct.
|
||||
func CopyMatchingTag(from interface{}, to interface{}, tag string, shouldCopy func(value string) bool) {
|
||||
fromStruct := reflect.ValueOf(from).Elem()
|
||||
fromType := fromStruct.Type()
|
||||
|
||||
toStruct := reflect.ValueOf(to).Elem()
|
||||
toType := toStruct.Type()
|
||||
|
||||
if fromType != toType {
|
||||
panic(fmt.Sprintf("non equal types: %s != %s", fromType, toType))
|
||||
}
|
||||
|
||||
for i := 0; i < toStruct.NumField(); i++ {
|
||||
fromField := fromStruct.Field(i)
|
||||
toField := toStruct.Field(i)
|
||||
|
||||
structTag := toType.Field(i).Tag
|
||||
|
||||
v := structTag.Get(tag)
|
||||
if shouldCopy(v) {
|
||||
toField.Set(fromField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UniqueStrings returns a list on unique strings, trimming and sorting them
|
||||
// at the same time.
|
||||
func UniqueStrings(ss []string) []string {
|
||||
|
||||
Reference in New Issue
Block a user