加宽加步骤按钮并按选中位置插入

This commit is contained in:
wanglei 2026-11-28 15:04:23 +08:00
parent 5ca58e10a2
commit 0aff2994b2
3 changed files with 47 additions and 8 deletions

View File

@ -93,7 +93,12 @@ public class RecipeNode : EditorNode
AddRegionCommand = new DelegateCommand(() => { AddRegion(); Changed?.Invoke(); });
RemoveRegionCommand = new DelegateCommand<RegionNode>(node => { RemoveRegion(node); Changed?.Invoke(); }, node => node is not null);
AddStepCommand = new DelegateCommand(() => { AddStep(); Changed?.Invoke(); });
AddStepCommand = new DelegateCommand(() =>
{
var selectedIndex = SelectedStep is { } selected ? Steps.IndexOf(selected) : -1;
InsertStep(selectedIndex < 0 ? Steps.Count : selectedIndex);
Changed?.Invoke();
});
RemoveStepCommand = new DelegateCommand<StepNode>(node => { RemoveStep(node); Changed?.Invoke(); }, node => node is not null);
MoveStepUpCommand = new DelegateCommand<StepNode>(node => { MoveStepUp(node); Changed?.Invoke(); }, node => node is not null && Steps.Any(s => s.Id < node.Id));
MoveStepDownCommand = new DelegateCommand<StepNode>(node => { MoveStepDown(node); Changed?.Invoke(); }, node => node is not null && Steps.Any(s => s.Id > node.Id));
@ -108,7 +113,7 @@ public class RecipeNode : EditorNode
/// <summary>删区域</summary>
public DelegateCommand<RegionNode> RemoveRegionCommand { get; }
/// <summary>加步骤</summary>
/// <summary>在选中步骤前新增;未选中时追加到末尾。</summary>
public DelegateCommand AddStepCommand { get; }
/// <summary>删步骤后按当前顺序从 1 连续编号。</summary>
@ -259,18 +264,24 @@ public class RecipeNode : EditorNode
SelectedRegion = Regions.FirstOrDefault();
}
/// <summary>加步骤(Id 取当前最大 +1,执行顺序按 Id 升序)</summary>
/// <remarks>新增可编辑步骤并维护当前步骤集合。</remarks>
public StepNode AddStep()
/// <summary>在末尾追加步骤并选中,供按顺序写入步骤的调用方使用。</summary>
public StepNode AddStep() => InsertStep(Steps.Count);
/// <summary>在指定列表位置新增步骤并选中。</summary>
private StepNode InsertStep(int index)
{
var append = index == Steps.Count;
var node = new StepNode
{
Id = Steps.Count == 0 ? 1 : Steps.Max(s => s.Id) + 1,
Id = append && Steps.Count > 0 ? Steps.Max(s => s.Id) + 1 : index + 1,
Name = "新步骤",
Detection = new ConditionNode(),
};
Steps.Add(node);
Steps.Insert(index, node);
// 保存和执行都按 Id 排序,插入中间时按列表顺序重新编号。
if (!append)
for (var i = 0; i < Steps.Count; i++) Steps[i].Id = i + 1;
SelectedStep = node;
return node;

View File

@ -121,7 +121,8 @@
</WrapPanel>
<TextBlock Text="{Binding StepTransferStatus}" TextWrapping="Wrap" Foreground="{StaticResource FgDim}" FontSize="12" />
</StackPanel>
<Button DockPanel.Dock="Bottom" Content="加步骤" Margin="0,8,0,0" Padding="0,6" Command="{Binding Recipe.AddStepCommand}" />
<!-- 增加按钮两侧留白,便于点击。 -->
<Button DockPanel.Dock="Bottom" Content="加步骤" Margin="0,8,0,0" Padding="12,6" Command="{Binding Recipe.AddStepCommand}" />
<ListBox ItemTemplate="{StaticResource StepRow}" ItemsSource="{Binding Recipe.Steps}" SelectedItem="{Binding Recipe.SelectedStep}" Classes="Pick StepNavigation" />
</DockPanel>
<Grid Grid.Row="1" RowDefinitions="Auto,*" Margin="0,8,0,0" x:Name="StepDecisionLogPanel">

View File

@ -36,6 +36,12 @@ internal static class Smoke
[STAThread]
public static int Main(string[] args)
{
if (args.Contains("--add-step-only"))
{
CheckAddStep();
return 0;
}
_visionOnly=args.Contains("--vision-only");
if (args.Contains("--license-ui-only")) Licensing.Expire();
_processImagesOnly=args.Contains("--process-images-only");
@ -1214,8 +1220,29 @@ internal static class Smoke
}
}
/// <summary>验证新增步骤命令的插入位置、选中项以及保存后的执行顺序。</summary>
private static void CheckAddStep()
{
var insertion = new RecipeNode();
var first = insertion.AddStep();
var second = insertion.AddStep();
first.Name = "第一步";
second.Name = "第二步";
insertion.AddStepCommand.Execute();
var inserted = insertion.SelectedStep;
Check(inserted is not null && insertion.Steps.SequenceEqual(new[] { first, inserted, second })
&& insertion.ToConfig().Sop.Steps.Select(step => step.Name).SequenceEqual(new[] { "第一步", "新步骤", "第二步" }),
"Adding with a selected step inserts and saves the new step immediately above it");
insertion.SelectedStep = null;
insertion.AddStepCommand.Execute();
Check(insertion.Steps.Count == 4 && insertion.Steps[^2] == second
&& insertion.Steps[^1] == insertion.SelectedStep && insertion.Steps[^1].Id == 4,
"Adding without a selection appends and selects the new step");
}
private static async Task CheckVisionConfirmation(App app,SopPageViewModel sop)
{
CheckAddStep();
var numbering=new RecipeNode();
var numbered=new[]{numbering.AddStep(),numbering.AddStep(),numbering.AddStep(),numbering.AddStep()};
for(var i=0;i<numbered.Length;i++)numbered[i].Name="step-"+(i+1);