improve:文件关联

This commit is contained in:
2025-08-31 12:03:58 +08:00
parent cdcb2d2af0
commit 147b4fc5ed
3 changed files with 130 additions and 0 deletions
+20
View File
@@ -2659,6 +2659,26 @@
</ui:SimpleStackPanel>
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
StrokeThickness="1" Margin="0,4,0,4" />
<TextBlock Text="文件关联管理" FontWeight="Bold" Foreground="#fafafa"
FontSize="16" Margin="0,8,0,8" />
<TextBlock Text="管理.icstk文件的关联设置,双击.icstk文件可直接在Ink Canvas中打开"
TextWrapping="Wrap" Foreground="#a1a1aa" Margin="0,0,0,8" />
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,8">
<Button Name="BtnUnregisterFileAssociation" Content="取消文件关联"
Padding="12,6" Margin="0,0,8,0" Click="BtnUnregisterFileAssociation_Click"
Background="#FFDC3545" Foreground="White" BorderBrush="#FFBD2130"
FontFamily="Microsoft YaHei UI" FontSize="12" />
<Button Name="BtnCheckFileAssociation" Content="检查关联状态"
Padding="12,6" Margin="0,0,8,0" Click="BtnCheckFileAssociation_Click"
Background="#FF17A2B8" Foreground="White" BorderBrush="#FF138496"
FontFamily="Microsoft YaHei UI" FontSize="12" />
<Button Name="BtnRegisterFileAssociation" Content="重新注册关联"
Padding="12,6" Click="BtnRegisterFileAssociation_Click"
Background="#FF28A745" Foreground="White" BorderBrush="#FF1E7E34"
FontFamily="Microsoft YaHei UI" FontSize="12" />
</ui:SimpleStackPanel>
<TextBlock Name="TextBlockFileAssociationStatus" Text=""
Foreground="#a1a1aa" FontSize="12" Margin="0,4,0,0" />
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#fafafa" Text="清屏时自动截图" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
+30
View File
@@ -526,6 +526,9 @@ namespace Ink_Canvas
// 处理命令行参数中的文件路径
HandleCommandLineFileOpen();
// 初始化文件关联状态显示
InitializeFileAssociationStatus();
}
private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e)
@@ -2129,6 +2132,33 @@ namespace Ink_Canvas
}
#endregion
/// <summary>
/// 初始化文件关联状态显示
/// </summary>
private void InitializeFileAssociationStatus()
{
try
{
bool isRegistered = FileAssociationManager.IsFileAssociationRegistered();
if (isRegistered)
{
TextBlockFileAssociationStatus.Text = "✓ .icstk文件关联已注册";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightGreen);
}
else
{
TextBlockFileAssociationStatus.Text = "✗ .icstk文件关联未注册";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
}
}
catch (Exception ex)
{
TextBlockFileAssociationStatus.Text = "✗ 检查文件关联状态时出错";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
LogHelper.WriteLogToFile($"初始化文件关联状态显示时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 处理命令行参数中的文件路径
/// </summary>
+80
View File
@@ -3080,5 +3080,85 @@ namespace Ink_Canvas
SaveSettingsToFile();
}
#region
private void BtnUnregisterFileAssociation_Click(object sender, RoutedEventArgs e)
{
try
{
bool success = FileAssociationManager.UnregisterFileAssociation();
if (success)
{
TextBlockFileAssociationStatus.Text = "✓ 文件关联已成功取消";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightGreen);
ShowNotification("文件关联已取消");
}
else
{
TextBlockFileAssociationStatus.Text = "✗ 取消文件关联失败,可能需要管理员权限";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
ShowNotification("取消文件关联失败");
}
}
catch (Exception ex)
{
TextBlockFileAssociationStatus.Text = $"✗ 取消文件关联时出错: {ex.Message}";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
LogHelper.WriteLogToFile($"取消文件关联时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private void BtnCheckFileAssociation_Click(object sender, RoutedEventArgs e)
{
try
{
bool isRegistered = FileAssociationManager.IsFileAssociationRegistered();
if (isRegistered)
{
TextBlockFileAssociationStatus.Text = "✓ .icstk文件关联已注册";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightGreen);
}
else
{
TextBlockFileAssociationStatus.Text = "✗ .icstk文件关联未注册";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
}
}
catch (Exception ex)
{
TextBlockFileAssociationStatus.Text = $"✗ 检查文件关联状态时出错: {ex.Message}";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
LogHelper.WriteLogToFile($"检查文件关联状态时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
private void BtnRegisterFileAssociation_Click(object sender, RoutedEventArgs e)
{
try
{
bool success = FileAssociationManager.RegisterFileAssociation();
if (success)
{
TextBlockFileAssociationStatus.Text = "✓ 文件关联已成功注册";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightGreen);
ShowNotification("文件关联已注册");
}
else
{
TextBlockFileAssociationStatus.Text = "✗ 注册文件关联失败,可能需要管理员权限";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
ShowNotification("注册文件关联失败");
}
}
catch (Exception ex)
{
TextBlockFileAssociationStatus.Text = $"✗ 注册文件关联时出错: {ex.Message}";
TextBlockFileAssociationStatus.Foreground = new SolidColorBrush(Colors.LightCoral);
LogHelper.WriteLogToFile($"注册文件关联时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
#endregion
}
}