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
using System.ComponentModel;
using System.Linq;
namespace OpenTap
{
    class MixinMenuModel: ITypeMenuModel
    {
        readonly ITypeData type;
 
        public bool TestPlanAllowsEdit => source
            .OfType<ITestStepParent>()
            .FirstNonDefault(step => step as TestPlan ?? step.GetParent<TestPlan>())
            ?.AllowEdit ?? true;
        
        public MixinMenuModel(ITypeData type) => this.type = type;
        bool? showMixins;
        public bool ShowMixins => (showMixins ??= (MixinFactory.GetMixinBuilders(type).Any())) && TestPlanAllowsEdit;
        public bool StepLocked => source.OfType<ITestStep>().Any(x => x.IsReadOnly);
        
        [Display("Add Mixin...", "Add a new mixin.", Order: 2.0, Group: "Mixins")]
        [Browsable(true)]
        [IconAnnotation(IconNames.AddMixin)]
        [EnabledIf(nameof(ShowMixins), true, HideIfDisabled = true)]
        [EnabledIf(nameof(StepLocked), false, HideIfDisabled = true)]
        
        public void AddMixin()
        {
            var builders = MixinFactory.GetMixinBuilders(type);
            
            // send the user request
            var ui = new MixinBuilderUi(builders.ToArray()) { AddMode = true };
            
            UserInput.Request(ui);
 
            if (ui.Submit == MixinBuilderUi.OkCancel.Cancel)
                return; // cancel
 
            var selectedMixin = ui.SelectedItem;
    
            var serializer = new TapSerializer();
            foreach (var src in source)
            {
                MixinFactory.LoadMixin(src, serializer.Clone(selectedMixin));
            }
        }
 
        object[] source;
        object[] IMenuModel.Source
        {
            get => source;
            set => source = value;
        }
    }
}