Phase 6: 一键多开 (工具组合) 功能

- 数据模型: ToolItem 新增 IsGroup(bool) + SubToolIds(List<string>) 字段

- 执行逻辑: ProcessExecutionService 改为 ExecuteAsync, 组合卡片遍历子工具逐一启动(500ms延迟), 孤儿ID跳过并打印警告

- 组合编辑: GroupEditViewModel + GroupEditWindow, 复选框列表勾选非组合工具

- 主界面: 标题栏新增 '+添加组合' 按钮(蓝色), 组合卡片右下角显示 📦 角标

- 右键菜单: 区分 '编辑工具' (普通) 和 '编辑组合' (IsGroup=true)

- 快捷键: HotKeyManager 适配 ExecuteAsync 异步调用

- 测试: 82 tests total (ProcessExecution 4->6, GroupEdit 5 new)
This commit is contained in:
2026-05-10 00:15:39 +08:00
parent 599964f078
commit 2c985e8d63
14 changed files with 668 additions and 31 deletions

View File

@@ -0,0 +1,100 @@
<Window x:Class="PersonalToolBox.Views.GroupEditWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding WindowTitle}" Height="500" Width="500"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
Background="{DynamicResource Theme.Background}">
<Grid Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- 组合名称 -->
<TextBlock Grid.Row="0" Grid.Column="0"
Text="名称:" Foreground="{DynamicResource Theme.Foreground}"
VerticalAlignment="Center" Margin="0,0,0,10"/>
<TextBox Grid.Row="0" Grid.Column="1"
Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"
Background="{DynamicResource Theme.InputBackground}"
Foreground="{DynamicResource Theme.Foreground}"
BorderBrush="{DynamicResource Theme.InputBorder}"
Height="28" Margin="0,0,0,10" Padding="6,0"/>
<!-- 所属分类 -->
<TextBlock Grid.Row="1" Grid.Column="0"
Text="分类:" Foreground="{DynamicResource Theme.Foreground}"
VerticalAlignment="Center" Margin="0,0,0,10"/>
<ComboBox Grid.Row="1" Grid.Column="1"
ItemsSource="{Binding Categories}"
SelectedItem="{Binding SelectedCategory}"
DisplayMemberPath="Name"
Height="28" Margin="0,0,0,10" Padding="4,0"/>
<!-- 快捷键 -->
<TextBlock Grid.Row="2" Grid.Column="0"
Text="快捷键:" Foreground="{DynamicResource Theme.Foreground}"
VerticalAlignment="Center" Margin="0,0,0,10"/>
<TextBox Grid.Row="2" Grid.Column="1"
Text="{Binding HotKey, UpdateSourceTrigger=PropertyChanged}"
Background="{DynamicResource Theme.InputBackground}"
Foreground="{DynamicResource Theme.Foreground}"
BorderBrush="{DynamicResource Theme.InputBorder}"
Height="28" Margin="0,0,0,10" Padding="6,0"/>
<!-- 子工具选择 -->
<TextBlock Grid.Row="3" Grid.Column="0"
Text="包含工具:" Foreground="{DynamicResource Theme.Foreground}"
VerticalAlignment="Top" Margin="0,4,0,0"/>
<Border Grid.Row="3" Grid.Column="1"
Background="{DynamicResource Theme.InputBackground}"
BorderBrush="{DynamicResource Theme.InputBorder}"
BorderThickness="1"
Margin="0,0,0,10">
<ListBox ItemsSource="{Binding AvailableTools}"
Background="Transparent"
BorderThickness="0"
MaxHeight="240">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected}"
Content="{Binding Tool.Name}"
Foreground="{DynamicResource Theme.Foreground}"
Margin="4,2"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
<!-- 按钮 -->
<StackPanel Grid.Row="5" Grid.Column="1"
Orientation="Horizontal" HorizontalAlignment="Right"
Margin="0,10,0,0">
<Button Content="保存"
Command="{Binding SaveCommand}"
Background="{DynamicResource Theme.ButtonBackground}"
Foreground="{DynamicResource Theme.ButtonForeground}"
BorderThickness="0"
Width="80" Height="30" FontSize="13"
Cursor="Hand" Margin="0,0,10,0"/>
<Button Content="取消"
Command="{Binding CancelCommand}"
Background="{DynamicResource Theme.CardBackground}"
Foreground="{DynamicResource Theme.Foreground}"
BorderBrush="{DynamicResource Theme.CardBorder}"
BorderThickness="1"
Width="80" Height="30" FontSize="13"
Cursor="Hand"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,17 @@
using System.Windows;
using PersonalToolBox.ViewModels;
namespace PersonalToolBox.Views;
public partial class GroupEditWindow : Window
{
public GroupEditWindow(GroupEditViewModel viewModel)
{
InitializeComponent();
viewModel.CloseAction = (result) => { DialogResult = result; };
Owner = Application.Current.MainWindow;
DataContext = viewModel;
}
}

View File

@@ -38,17 +38,59 @@
<MenuItem Header="运行"
Command="{Binding PlacementTarget.Tag.ExecuteToolCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
CommandParameter="{Binding}"/>
<MenuItem Header="编辑"
<MenuItem Header="编辑工具"
Command="{Binding PlacementTarget.Tag.EditToolCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
CommandParameter="{Binding}"/>
CommandParameter="{Binding}">
<MenuItem.Style>
<Style TargetType="MenuItem">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsGroup}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
</MenuItem>
<MenuItem Header="编辑组合"
Command="{Binding PlacementTarget.Tag.EditGroupCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
CommandParameter="{Binding}">
<MenuItem.Style>
<Style TargetType="MenuItem">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsGroup}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
</MenuItem>
</ContextMenu>
</Border.ContextMenu>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="{Binding Name, Converter={StaticResource FirstCharConverter}}"
FontSize="28"
Foreground="{DynamicResource Theme.Accent}"
HorizontalAlignment="Center"
Margin="0,0,0,6"/>
<Grid HorizontalAlignment="Center" Margin="0,0,0,4">
<TextBlock Text="{Binding Name, Converter={StaticResource FirstCharConverter}}"
FontSize="28"
Foreground="{DynamicResource Theme.Accent}"
HorizontalAlignment="Center"/>
<!-- 组合角标 -->
<TextBlock Text="📦" FontSize="11"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="0,0,-12,-4">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsGroup}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
<TextBlock Text="{Binding Name}"
FontSize="12"
Foreground="{DynamicResource Theme.Foreground}"
@@ -214,6 +256,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0"
@@ -236,6 +279,23 @@
BorderThickness="0"
FontSize="12"
Height="32"
Cursor="Hand"
Margin="0,0,6,0">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="4"/>
</Style>
</Button.Resources>
</Button>
<Button Grid.Column="2"
Content="+ 添加组合"
Command="{Binding AddGroupCommand}"
Background="{DynamicResource Theme.Accent}"
Foreground="{DynamicResource Theme.ButtonForeground}"
BorderThickness="0"
FontSize="12"
Height="32"
Cursor="Hand">
<Button.Resources>
<Style TargetType="Border">