using CommunityToolkit.Mvvm.ComponentModel;
using OpenTap;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using UILib;
namespace OpenTapEditor
{
///
/// ChildSeqPanel.xaml 的交互逻辑
///
[ObservableObject]
public partial class ChildSeqPanel : UserControl
{
public event EventHandler SequencePropertyChanged;
public event EventHandler selectedSequenceChanged;
public event EventHandler SelectedSequenceChanged
{
add
{
selectedSequenceChanged += value;
}
remove
{
selectedSequenceChanged -= value;
}
}
[ObservableProperty]
private ObservableCollection sequences;
[ObservableProperty]
private TestStepList selectedSequence;
private TestPlan plan;
public void SetPlan(TestPlan plan)
{
this.plan = plan;
Sequences = plan.Sequences;
SelectedSequence = Sequences[0];
}
public ChildSeqPanel()
{
this.DataContext = this;
InitializeComponent();
}
private void MenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
{
MenuItem item = (MenuItem)sender;
if (item.Tag.ToString() == "添加")
{
Sequences.Add(new TestStepList { SequenceName = DateTime.Now.ToString("yyyyMMddHHmmssfff"), Parent = this.plan });
SequencePropertyChanged?.Invoke(this, new EventArgs());
return;
}
if (item.Tag.ToString() == "删除")
{
if (SelectedSequence.SequenceName == TestPlan.MAIN_SEQ_NAME)
{
return;
}
Sequences.Remove(SelectedSequence);
SequencePropertyChanged?.Invoke(this, new EventArgs());
return;
}
}
private bool SequenceNamePreSubmit(object sender, 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)
{
SequencePropertyChanged?.Invoke(this, new EventArgs());
}
partial void OnSelectedSequenceChanged(TestStepList value)
{
selectedSequenceChanged?.Invoke(this, value);
}
}
}