错误程序子程序优化
This commit is contained in:
@@ -568,20 +568,38 @@ namespace TestingModule.ViewModels
|
||||
{
|
||||
// 查找最近的未匹配循环开始
|
||||
StepVM? lastUnmatchedLoopStart = null;
|
||||
for (int i = Program.StepCollection.Count - 1; i >= 0; i--)
|
||||
if (_ScopedContext.SelectedStepList == "主程序")
|
||||
{
|
||||
if (Program.StepCollection[i].StepType == "循环开始")
|
||||
for (int i = Program.StepCollection.Count - 1; i >= 0; i--)
|
||||
{
|
||||
bool isMatched = Program.StepCollection.Any(s => s.StepType == "循环结束" && s.LoopStartStepId == Program.StepCollection[i].ID);
|
||||
|
||||
if (!isMatched)
|
||||
if (Program.StepCollection[i].StepType == "循环开始")
|
||||
{
|
||||
lastUnmatchedLoopStart = Program.StepCollection[i];
|
||||
break;
|
||||
bool isMatched = Program.StepCollection.Any(s => s.StepType == "循环结束" && s.LoopStartStepId == Program.StepCollection[i].ID);
|
||||
|
||||
if (!isMatched)
|
||||
{
|
||||
lastUnmatchedLoopStart = Program.StepCollection[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = Program.ErrorStepCollection.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (Program.ErrorStepCollection[i].StepType == "循环开始")
|
||||
{
|
||||
bool isMatched = Program.ErrorStepCollection.Any(s => s.StepType == "循环结束" && s.LoopStartStepId == Program.StepCollection[i].ID);
|
||||
|
||||
if (!isMatched)
|
||||
{
|
||||
lastUnmatchedLoopStart = Program.ErrorStepCollection[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var newStep = new StepVM
|
||||
{
|
||||
Name = "循环结束",
|
||||
|
||||
@@ -99,39 +99,24 @@ namespace TestingModule.ViewModels
|
||||
public ICommand GoBackCommand { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 子程序导航
|
||||
#region 子程序导航(主程序 / 错误程序各自独立)
|
||||
|
||||
// --- 主程序 Tab 导航属性 ---
|
||||
public ProgramVM MainCurrentProgram => _ScopedContext.MainNav.CurrentProgram;
|
||||
public string MainBreadcrumbPath => _ScopedContext.MainNav.BreadcrumbPath;
|
||||
public bool MainCanGoBack => _ScopedContext.MainNav.CanGoBack;
|
||||
public ObservableCollection<StepVM> MainDisplaySteps => _ScopedContext.MainNav.DisplaySteps;
|
||||
|
||||
// --- 错误程序 Tab 导航属性 ---
|
||||
public ProgramVM ErrorCurrentProgram => _ScopedContext.ErrorNav.CurrentProgram;
|
||||
public string ErrorBreadcrumbPath => _ScopedContext.ErrorNav.BreadcrumbPath;
|
||||
public bool ErrorCanGoBack => _ScopedContext.ErrorNav.CanGoBack;
|
||||
public ObservableCollection<StepVM> ErrorDisplaySteps => _ScopedContext.ErrorNav.DisplaySteps;
|
||||
|
||||
/// <summary>
|
||||
/// 当前显示的程序(绑定到 DataGrid 的 ItemsSource 根)。
|
||||
/// 委托到 ScopedContext.CurrentProgram,保证 ShellViewModel 也能通过 ScopedContext 访问。
|
||||
/// 当前激活的导航状态(根据选中的 Tab 决定)
|
||||
/// </summary>
|
||||
public ProgramVM CurrentProgram
|
||||
{
|
||||
get => _ScopedContext.CurrentProgram;
|
||||
set
|
||||
{
|
||||
if (_ScopedContext.CurrentProgram != value)
|
||||
{
|
||||
_ScopedContext.CurrentProgram = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string BreadcrumbPath
|
||||
{
|
||||
get => _ScopedContext.BreadcrumbPath;
|
||||
set
|
||||
{
|
||||
if (_ScopedContext.BreadcrumbPath != value)
|
||||
{
|
||||
_ScopedContext.BreadcrumbPath = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanGoBack => _ScopedContext.CanGoBack;
|
||||
private ProgramNavigationState ActiveNav => _ScopedContext.ActiveNav;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -153,19 +138,36 @@ namespace TestingModule.ViewModels
|
||||
Program.PropertyChanged += Program_PropertyChanged;
|
||||
Admin = _globalInfo.IsAdmin;
|
||||
|
||||
// 初始化 CurrentProgram 为根程序
|
||||
_ScopedContext.CurrentProgram = Program;
|
||||
_ScopedContext.BreadcrumbPath = "主程序";
|
||||
// 初始化两套导航状态
|
||||
_ScopedContext.MainNav.Initialize(Program, "主程序");
|
||||
_ScopedContext.ErrorNav.Initialize(Program, "错误程序");
|
||||
|
||||
// 订阅 ScopedContext 属性变化,外部(ShellViewModel)修改时转发通知给 UI
|
||||
_ScopedContext.PropertyChanged += (s, e) =>
|
||||
// 订阅主程序导航状态变化 → 转发给 UI
|
||||
_ScopedContext.MainNav.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(ScopedContext.CurrentProgram))
|
||||
RaisePropertyChanged(nameof(CurrentProgram));
|
||||
else if (e.PropertyName == nameof(ScopedContext.BreadcrumbPath))
|
||||
RaisePropertyChanged(nameof(BreadcrumbPath));
|
||||
else if (e.PropertyName == nameof(ScopedContext.CanGoBack))
|
||||
RaisePropertyChanged(nameof(CanGoBack));
|
||||
if (e.PropertyName == nameof(ProgramNavigationState.CurrentProgram))
|
||||
{
|
||||
RaisePropertyChanged(nameof(MainCurrentProgram));
|
||||
RaisePropertyChanged(nameof(MainDisplaySteps));
|
||||
}
|
||||
else if (e.PropertyName == nameof(ProgramNavigationState.BreadcrumbPath))
|
||||
RaisePropertyChanged(nameof(MainBreadcrumbPath));
|
||||
else if (e.PropertyName == nameof(ProgramNavigationState.CanGoBack))
|
||||
RaisePropertyChanged(nameof(MainCanGoBack));
|
||||
};
|
||||
|
||||
// 订阅错误程序导航状态变化 → 转发给 UI
|
||||
_ScopedContext.ErrorNav.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(ProgramNavigationState.CurrentProgram))
|
||||
{
|
||||
RaisePropertyChanged(nameof(ErrorCurrentProgram));
|
||||
RaisePropertyChanged(nameof(ErrorDisplaySteps));
|
||||
}
|
||||
else if (e.PropertyName == nameof(ProgramNavigationState.BreadcrumbPath))
|
||||
RaisePropertyChanged(nameof(ErrorBreadcrumbPath));
|
||||
else if (e.PropertyName == nameof(ProgramNavigationState.CanGoBack))
|
||||
RaisePropertyChanged(nameof(ErrorCanGoBack));
|
||||
};
|
||||
|
||||
// 订阅子程序导航事件(运行时由 StepRunning 发布)
|
||||
@@ -272,45 +274,38 @@ namespace TestingModule.ViewModels
|
||||
#region 子程序导航方法
|
||||
|
||||
/// <summary>
|
||||
/// 编辑模式:右键打开子程序
|
||||
/// 编辑模式:右键打开子程序(操作当前激活的 Tab 的导航状态)
|
||||
/// </summary>
|
||||
private void OpenSubProgram()
|
||||
{
|
||||
if (SelectedStep == null || SelectedStep.StepType != "子程序" || SelectedStep.SubProgram == null)
|
||||
return;
|
||||
|
||||
// 压栈:保存当前程序
|
||||
_ScopedContext.SubProgramNavigationStack.Push(CurrentProgram);
|
||||
_ScopedContext.UpdateCanGoBack();
|
||||
// 更新面包屑
|
||||
var nav = ActiveNav;
|
||||
nav.NavigationStack.Push(nav.CurrentProgram);
|
||||
nav.UpdateCanGoBack();
|
||||
var stepName = SelectedStep.Name ?? "子程序";
|
||||
BreadcrumbPath = $"{BreadcrumbPath} > {stepName}";
|
||||
// 切换到子程序
|
||||
CurrentProgram = SelectedStep.SubProgram;
|
||||
RaisePropertyChanged(nameof(CanGoBack));
|
||||
nav.BreadcrumbPath = $"{nav.BreadcrumbPath} > {stepName}";
|
||||
nav.CurrentProgram = SelectedStep.SubProgram;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回上一级程序
|
||||
/// 返回上一级程序(操作当前激活的 Tab 的导航状态)
|
||||
/// </summary>
|
||||
private void GoBack()
|
||||
{
|
||||
if (_ScopedContext.SubProgramNavigationStack.Count == 0)
|
||||
var nav = ActiveNav;
|
||||
if (nav.NavigationStack.Count == 0)
|
||||
return;
|
||||
|
||||
// 出栈:恢复上一级程序
|
||||
var parentProgram = _ScopedContext.SubProgramNavigationStack.Pop();
|
||||
_ScopedContext.UpdateCanGoBack();
|
||||
CurrentProgram = parentProgram;
|
||||
var parentProgram = nav.NavigationStack.Pop();
|
||||
nav.UpdateCanGoBack();
|
||||
nav.CurrentProgram = parentProgram;
|
||||
|
||||
// 更新面包屑:去掉最后一段
|
||||
var parts = BreadcrumbPath.Split(" > ");
|
||||
if (parts.Length > 1)
|
||||
BreadcrumbPath = string.Join(" > ", parts.Take(parts.Length - 1));
|
||||
else
|
||||
BreadcrumbPath = "主程序";
|
||||
|
||||
RaisePropertyChanged(nameof(CanGoBack));
|
||||
var parts = nav.BreadcrumbPath.Split(" > ");
|
||||
nav.BreadcrumbPath = parts.Length > 1
|
||||
? string.Join(" > ", parts.Take(parts.Length - 1))
|
||||
: nav == _ScopedContext.MainNav ? "主程序" : "错误程序";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -318,18 +313,25 @@ namespace TestingModule.ViewModels
|
||||
/// </summary>
|
||||
private void OnSubProgramNavigate(SubProgramNavigatePayload payload)
|
||||
{
|
||||
var nav = payload.IsErrorProgram ? _ScopedContext.ErrorNav : _ScopedContext.MainNav;
|
||||
if (payload.Action == NavigateAction.Enter && payload.SubProgram != null)
|
||||
{
|
||||
_ScopedContext.SubProgramNavigationStack.Push(CurrentProgram);
|
||||
_ScopedContext.UpdateCanGoBack();
|
||||
CurrentProgram = payload.SubProgram;
|
||||
nav.NavigationStack.Push(nav.CurrentProgram);
|
||||
nav.UpdateCanGoBack();
|
||||
nav.CurrentProgram = payload.SubProgram;
|
||||
var stepName = payload.StepName ?? "子程序";
|
||||
BreadcrumbPath = $"{BreadcrumbPath} > {stepName}";
|
||||
RaisePropertyChanged(nameof(CanGoBack));
|
||||
nav.BreadcrumbPath = $"{nav.BreadcrumbPath} > {stepName}";
|
||||
}
|
||||
else if (payload.Action == NavigateAction.Exit)
|
||||
{
|
||||
GoBack();
|
||||
if (nav.NavigationStack.Count == 0) return;
|
||||
var parentProgram = nav.NavigationStack.Pop();
|
||||
nav.UpdateCanGoBack();
|
||||
nav.CurrentProgram = parentProgram;
|
||||
var parts = nav.BreadcrumbPath.Split(" > ");
|
||||
nav.BreadcrumbPath = parts.Length > 1
|
||||
? string.Join(" > ", parts.Take(parts.Length - 1))
|
||||
: nav == _ScopedContext.MainNav ? "主程序" : "错误程序";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user