chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.ComponentModel;
using System.Linq;
 
namespace OpenTap
{
    
    internal class MixinBuilderUi : ValidatingObject, IDisplayAnnotation
    {
        
        public IMixinBuilder[] Items { get; }
 
        [PluginTypeSelector(ObjectSourceProperty = nameof(Items))]
        [Display("Mixin", Order: -10001)]
        public IMixinBuilder SelectedType
        {
            get => SelectedItem;
            set => SelectedItem = value;
        }
 
        public IMixinBuilder SelectedItem { get; private set; }
        public enum OkCancel { Ok, Cancel }
 
        [Submit]
        [Layout(LayoutMode.FloatBottom | LayoutMode.FullRow)]
        public OkCancel Submit { get; set; } = OkCancel.Ok;
        
        public MixinBuilderUi(IMixinBuilder[] items, IMixinBuilder selected = null)
        {
            Items = items;
            SelectedItem = selected;
            if (SelectedItem == null)
            {
                SelectedItem = Items.FirstOrDefault();
            }
            
            { // redirect validation rules.
                foreach (var mixinBuilder in items)
                {
                    if (mixinBuilder is IValidatingObject val)
                    {
                        var type = TypeData.GetTypeData(mixinBuilder);
 
                        foreach (var rule in val.Rules)
                        {
                            var member = type.GetMember(rule.PropertyName);
                            if (member == null) continue;
 
                            
                            var transformedName = MixinBuilderUiTypeData.GetTransformedName(member);
                            Rules.Add(() => rule.IsValid(), () => rule.ErrorMessage, transformedName);
                        }
                    }
                }
            }
        }
        
        [Browsable(false)]
        public bool AddMode { get; set; }
        
        string IDisplayAnnotation.Description => AddMode ? "Add a new mixin." : "Configure a mixin.";
        string[] IDisplayAnnotation.Group => Array.Empty<string>();
        string IDisplayAnnotation.Name => AddMode ? "Add Mixin" : $"Modify Mixin '{InitialMixinName ?? string.Empty}'";
        double IDisplayAnnotation.Order => 0.0;
        bool IDisplayAnnotation.Collapsed => false;
        [Browsable(false)]
        public string InitialMixinName
        {
            get;
            set;
        }
    }
}