命令树优化,测试编辑区域优化
This commit is contained in:
@@ -178,10 +178,15 @@ namespace TestingModule.ViewModels
|
||||
|
||||
private void SelectionChanged(object parameter)
|
||||
{
|
||||
var selectedList = parameter as IList;
|
||||
if (selectedList != null)
|
||||
if (parameter is IList list && list.Count > 0)
|
||||
{
|
||||
SelectedItems = selectedList.Cast<StepVM>().ToList();
|
||||
SelectedItems = list.Cast<StepVM>().ToList();
|
||||
}
|
||||
else if (parameter is IEnumerable enumerable && parameter is not string)
|
||||
{
|
||||
var items = enumerable.Cast<StepVM>().ToList();
|
||||
if (items.Count > 0)
|
||||
SelectedItems = items;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,13 +205,19 @@ namespace TestingModule.ViewModels
|
||||
}
|
||||
private void CopyStep()
|
||||
{
|
||||
if (_globalInfo.IsAdmin && SelectedItems.Any())
|
||||
if (!_globalInfo.IsAdmin) return;
|
||||
|
||||
// 优先用多选列表,回退到单选
|
||||
var source = (SelectedItems != null && SelectedItems.Any())
|
||||
? SelectedItems
|
||||
: (SelectedStep != null ? new List<StepVM> { SelectedStep } : null);
|
||||
|
||||
if (source == null || !source.Any()) return;
|
||||
|
||||
tmpCopyList.Clear();
|
||||
foreach (var item in source)
|
||||
{
|
||||
tmpCopyList.Clear();
|
||||
foreach (var item in SelectedItems)
|
||||
{
|
||||
tmpCopyList.Add(item);
|
||||
}
|
||||
tmpCopyList.Add(item);
|
||||
}
|
||||
}
|
||||
private void PasteStep()
|
||||
@@ -243,31 +254,29 @@ namespace TestingModule.ViewModels
|
||||
}
|
||||
private void DeleteStep()
|
||||
{
|
||||
// 确保有选中的项
|
||||
if (_globalInfo.IsAdmin && SelectedItems != null && SelectedItems.Any())
|
||||
if (!_globalInfo.IsAdmin) return;
|
||||
|
||||
// 优先用多选列表,回退到单选
|
||||
var source = (SelectedItems != null && SelectedItems.Any())
|
||||
? SelectedItems.ToList()
|
||||
: (SelectedStep != null ? new List<StepVM> { SelectedStep } : null);
|
||||
|
||||
if (source == null || !source.Any()) return;
|
||||
|
||||
foreach (var item in source)
|
||||
{
|
||||
// 创建一个副本进行循环,防止在 Remove 过程中集合变化导致的问题
|
||||
var toDelete = SelectedItems.ToList();
|
||||
_eventAggregator.GetEvent<DeletedStepEvent>().Publish(item.ID);
|
||||
|
||||
foreach (var item in toDelete)
|
||||
{
|
||||
_eventAggregator.GetEvent<DeletedStepEvent>().Publish(item.ID);
|
||||
|
||||
if (_ScopedContext.SelectedStepList == "主程序")
|
||||
{
|
||||
Program.StepCollection.Remove(item);
|
||||
}
|
||||
else if (_ScopedContext.SelectedStepList == "错误程序")
|
||||
{
|
||||
Program.ErrorStepCollection.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 清空 ViewModel 的选中状态,避免悬挂引用
|
||||
SelectedStep = null;
|
||||
SelectedItems.Clear();
|
||||
_ScopedContext.SelectedStep = null;
|
||||
if (_ScopedContext.SelectedStepList == "主程序")
|
||||
Program.StepCollection.Remove(item);
|
||||
else if (_ScopedContext.SelectedStepList == "错误程序")
|
||||
Program.ErrorStepCollection.Remove(item);
|
||||
}
|
||||
|
||||
// 清空 ViewModel 的选中状态,避免悬挂引用
|
||||
SelectedStep = null;
|
||||
SelectedItems?.Clear();
|
||||
_ScopedContext.SelectedStep = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -313,6 +322,7 @@ namespace TestingModule.ViewModels
|
||||
/// </summary>
|
||||
private void OnSubProgramNavigate(SubProgramNavigatePayload payload)
|
||||
{
|
||||
if (_ScopedContext == null || payload == null) return;
|
||||
var nav = payload.IsErrorProgram ? _ScopedContext.ErrorNav : _ScopedContext.MainNav;
|
||||
if (payload.Action == NavigateAction.Enter && payload.SubProgram != null)
|
||||
{
|
||||
@@ -381,6 +391,12 @@ namespace TestingModule.ViewModels
|
||||
UnsubscribeStepCollections();
|
||||
SubscribeStepCollections();
|
||||
|
||||
// 通知 UI 刷新 DisplaySteps(导航状态虽然引用同一 Program,但集合实例已变)
|
||||
RaisePropertyChanged(nameof(MainDisplaySteps));
|
||||
RaisePropertyChanged(nameof(ErrorDisplaySteps));
|
||||
RaisePropertyChanged(nameof(MainCurrentProgram));
|
||||
RaisePropertyChanged(nameof(ErrorCurrentProgram));
|
||||
|
||||
// 集合被整体替换后,对新集合重新编号
|
||||
Application.Current?.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
@@ -433,7 +449,7 @@ namespace TestingModule.ViewModels
|
||||
Program.PropertyChanged -= Program_PropertyChanged;
|
||||
}
|
||||
|
||||
// 3. 【核心修复】必须显式退订 Prism 全局事件
|
||||
// 3. 显式退订全局 Prism 事件
|
||||
_eventAggregator?.GetEvent<AlarmEvent>()?.Unsubscribe(null);
|
||||
_eventAggregator?.GetEvent<SubProgramNavigateEvent>()?.Unsubscribe(null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user