using CommunityToolkit.Mvvm.ComponentModel; using OpenTap; using OpenTap.Addin; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using UILib; namespace OpenTapEditor { /// /// VariablesControl.xaml 的交互逻辑 /// [ObservableObject] public partial class VariablesControl : UserControl { public event EventHandler SequenceChanged; public event EventHandler selectedSequenceChanged; public event EventHandler SelectedSequenceChanged { add { selectedSequenceChanged += value; } remove { selectedSequenceChanged -= value; } } [ObservableProperty] private ObservableCollection variables; [ObservableProperty] private ObservableCollection sequences; [ObservableProperty] private TestStepList selectedSequence; private TestPlan plan; public VariablesControl() { DataContext = this; Variables = new ObservableCollection() { new TestVariable(){ Name = "Locals", Type = TestVariableType.Container }, new TestVariable(){ Name = "FileGlobals", Type = TestVariableType.Container }, new TestVariable(){ Name = "StationGlobals", Type = TestVariableType.Container, Children = UIStationGlobalsManager.Instance.Datasource }, }; InitializeComponent(); } public void SetPlan(TestPlan plan) { this.plan = plan; Variables[1].Children = plan.Variables; Sequences = plan.Sequences; SelectedSequence = Sequences[0]; Variables[0].Children = SelectedSequence.Variables; } private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { UIStationGlobalsManager.Instance.WriteToLocal(UIStationGlobalsManager.Instance.Datasource); } private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e) { Sequences.Add(new TestStepList { SequenceName = DateTime.Now.ToString("yyyyMMddHHmmssfff"), Parent = this.plan }); SequenceChanged?.Invoke(this, new EventArgs()); } private bool SequenceNamePreSubmit(object value, object source) { if (Sequences.FirstOrDefault(s => s.SequenceName == value.ToString() && s != source) != null) { MessageBox.Show("名称不能重复"); return false; } return true; } private void SequenceNameSubmited(EditBox box, object oldValue, object newValue) { SequenceChanged?.Invoke(this, new EventArgs()); } partial void OnSelectedSequenceChanged(TestStepList value) { Variables[0].Children = value.Variables; selectedSequenceChanged?.Invoke(this, value); } } }