improve:快捷键和墨迹渐隐

This commit is contained in:
2025-08-24 09:17:58 +08:00
parent d1eed23399
commit 7710b77255
4 changed files with 198 additions and 116 deletions
+54 -1
View File
@@ -165,6 +165,59 @@ namespace Ink_Canvas.Helpers
return new List<HotkeyInfo>(_registeredHotkeys.Values); return new List<HotkeyInfo>(_registeredHotkeys.Values);
} }
/// <summary>
/// 获取配置文件中的快捷键信息(不注册,仅用于显示)
/// </summary>
/// <returns>配置文件中的快捷键列表</returns>
public List<HotkeyInfo> GetHotkeysFromConfigFile()
{
try
{
if (!File.Exists(HotkeyConfigFile))
{
LogHelper.WriteLogToFile("快捷键配置文件不存在", LogHelper.LogType.Info);
return new List<HotkeyInfo>();
}
// 读取配置文件内容
string jsonContent = File.ReadAllText(HotkeyConfigFile, System.Text.Encoding.UTF8);
if (string.IsNullOrEmpty(jsonContent))
{
LogHelper.WriteLogToFile("快捷键配置文件为空", LogHelper.LogType.Warning);
return new List<HotkeyInfo>();
}
// 反序列化配置
var config = JsonConvert.DeserializeObject<HotkeyConfig>(jsonContent);
if (config?.Hotkeys == null || config.Hotkeys.Count == 0)
{
LogHelper.WriteLogToFile("快捷键配置为空或格式错误", LogHelper.LogType.Warning);
return new List<HotkeyInfo>();
}
// 转换为HotkeyInfo列表(不注册,仅用于显示)
var hotkeyList = new List<HotkeyInfo>();
foreach (var hotkeyConfig in config.Hotkeys)
{
hotkeyList.Add(new HotkeyInfo
{
Name = hotkeyConfig.Name,
Key = hotkeyConfig.Key,
Modifiers = hotkeyConfig.Modifiers,
Action = null // 不设置动作,仅用于显示
});
}
LogHelper.WriteLogToFile($"从配置文件读取到 {hotkeyList.Count} 个快捷键信息", LogHelper.LogType.Info);
return hotkeyList;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"从配置文件读取快捷键信息时出错: {ex.Message}", LogHelper.LogType.Error);
return new List<HotkeyInfo>();
}
}
/// <summary> /// <summary>
/// 注册默认快捷键集合 /// 注册默认快捷键集合
/// </summary> /// </summary>
@@ -211,7 +264,7 @@ namespace Ink_Canvas.Helpers
} }
/// <summary> /// <summary>
/// 从设置加载快捷键 /// 从配置文件加载快捷键
/// </summary> /// </summary>
public void LoadHotkeysFromSettings() public void LoadHotkeysFromSettings()
{ {
+117 -105
View File
@@ -4061,7 +4061,7 @@
</Border> </Border>
<Border> <Border>
<Grid Margin="0,5,0,5" Width="0"> <Grid Margin="0,5,0,5" Width="0">
<Grid Name="BoardPenPaletteGrid" Margin="-160,-200,-33,50" <Grid Name="BoardPenPaletteGrid" Margin="-160,-200,-53,50"
RenderTransformOrigin="0,1"> RenderTransformOrigin="0,1">
<Grid.RenderTransform> <Grid.RenderTransform>
<TransformGroup> <TransformGroup>
@@ -4176,57 +4176,69 @@
Margin="12,8,12,0" HorizontalAlignment="Center" Margin="12,8,12,0" HorizontalAlignment="Center"
VerticalAlignment="Center" Stretch="Fill"> VerticalAlignment="Center" Stretch="Fill">
<ui:SimpleStackPanel> <ui:SimpleStackPanel>
<Controls:UniformGrid Columns="2" Width="300" <ui:SimpleStackPanel Orientation="Horizontal"
Height="35" Margin="0,0,0,8">
<Label Content="笔锋" Margin="0,0,6,0"
Foreground="{DynamicResource FloatBarForeground}"
FontSize="16" FontWeight="Bold"
VerticalAlignment="Center" />
<ComboBox Height="30"
VerticalAlignment="Center"
Name="BoardComboBoxPenStyle"
FontFamily="Microsoft YaHei UI"
SelectedIndex="0"
SelectionChanged="ComboBoxPenStyle_SelectionChanged">
<ComboBoxItem Content="基于点集"
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="基于速率"
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="关闭笔锋"
FontFamily="Microsoft YaHei UI" />
</ComboBox>
</ui:SimpleStackPanel>
<Controls:UniformGrid Columns="3" Width="300"
Height="55"> Height="55">
<ui:SimpleStackPanel Orientation="Horizontal" <ui:SimpleStackPanel
Height="35"> x:Name="BoardNibModeSimpleStackPanel"
<Label Content="笔锋" Margin="0,0,6,0" Orientation="Horizontal" Width="100">
Foreground="{DynamicResource FloatBarForeground}" <Label Content="笔尖模式" FontSize="15"
FontSize="16" FontWeight="Bold" VerticalAlignment="Center" />
VerticalAlignment="Center" /> <ui:ToggleSwitch
<ComboBox Height="30" x:Name="BoardToggleSwitchEnableNibMode"
VerticalAlignment="Center" MinWidth="0"
Name="BoardComboBoxPenStyle"
FontFamily="Microsoft YaHei UI" FontFamily="Microsoft YaHei UI"
SelectedIndex="0" Width="80" Margin="10,0,0,0"
SelectionChanged="ComboBoxPenStyle_SelectionChanged"> Toggled="ToggleSwitchEnableNibMode_Toggled"
<ComboBoxItem Content="基于点集" IsOn="True" />
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="基于速率"
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="关闭笔锋"
FontFamily="Microsoft YaHei UI" />
</ComboBox>
</ui:SimpleStackPanel> </ui:SimpleStackPanel>
<ui:SimpleStackPanel Margin="0,-5,0,-5" <ui:SimpleStackPanel Orientation="Horizontal"
VerticalAlignment="Center"> Width="100">
<ui:SimpleStackPanel <Label Margin="0,0,10,0" Content="墨迹纠正"
x:Name="BoardNibModeSimpleStackPanel" Foreground="{DynamicResource FloatBarForeground}"
Orientation="Horizontal" Width="140"> FontSize="15"
<Label Content="笔尖模式" FontSize="15" VerticalAlignment="Center" />
VerticalAlignment="Center" /> <ui:ToggleSwitch
<ui:ToggleSwitch Foreground="{DynamicResource FloatBarForeground}"
x:Name="BoardToggleSwitchEnableNibMode" FontFamily="Microsoft YaHei UI"
MinWidth="0" Width="80"
FontFamily="Microsoft YaHei UI" Toggled="ToggleSwitchEnableInkToShape_Toggled"
Width="70" Margin="10,0,0,0" MinWidth="0"
Toggled="ToggleSwitchEnableNibMode_Toggled" IsOn="{Binding ElementName=ToggleSwitchEnableInkToShape, Path=IsOn}" />
IsOn="True" /> </ui:SimpleStackPanel>
</ui:SimpleStackPanel> <ui:SimpleStackPanel Orientation="Horizontal"
<ui:SimpleStackPanel Orientation="Horizontal" Width="100">
Width="140"> <Label Margin="0,0,10,0" Content="墨迹渐隐"
<Label Margin="0,0,10,0" Content="墨迹纠正" Foreground="{DynamicResource FloatBarForeground}"
Foreground="{DynamicResource FloatBarForeground}" FontSize="15"
FontSize="15" VerticalAlignment="Center" />
VerticalAlignment="Center" /> <ui:ToggleSwitch
<ui:ToggleSwitch x:Name="ToggleSwitchInkFadeInPanel"
Foreground="{DynamicResource FloatBarForeground}" Foreground="{DynamicResource FloatBarForeground}"
FontFamily="Microsoft YaHei UI" FontFamily="Microsoft YaHei UI"
Width="70" Width="90"
Toggled="ToggleSwitchEnableInkToShape_Toggled" Toggled="ToggleSwitchInkFadeInPanel_Toggled"
MinWidth="0" MinWidth="0"
IsOn="{Binding ElementName=ToggleSwitchEnableInkToShape, Path=IsOn}" /> IsOn="False" />
</ui:SimpleStackPanel>
</ui:SimpleStackPanel> </ui:SimpleStackPanel>
</Controls:UniformGrid> </Controls:UniformGrid>
@@ -7193,53 +7205,63 @@
Margin="12,8,12,0" HorizontalAlignment="Center" Margin="12,8,12,0" HorizontalAlignment="Center"
VerticalAlignment="Center" Stretch="Fill"> VerticalAlignment="Center" Stretch="Fill">
<ui:SimpleStackPanel> <ui:SimpleStackPanel>
<Controls:UniformGrid Columns="2" Width="300" Height="55"> <ui:SimpleStackPanel Orientation="Horizontal"
<ui:SimpleStackPanel Orientation="Horizontal" Height="35" Margin="0,0,0,8">
Height="35"> <Label Content="笔锋" Margin="0,0,6,0"
<Label Content="笔锋" Margin="0,0,6,0" Foreground="{DynamicResource FloatBarForeground}"
Foreground="{DynamicResource FloatBarForeground}" FontSize="16" FontWeight="Bold"
FontSize="16" FontWeight="Bold" VerticalAlignment="Center" />
<ComboBox Height="30" VerticalAlignment="Center"
Name="ComboBoxPenStyle"
FontFamily="Microsoft YaHei UI"
SelectedIndex="0"
SelectionChanged="ComboBoxPenStyle_SelectionChanged">
<ComboBoxItem Content="基于点集"
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="基于速率"
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="关闭笔锋"
FontFamily="Microsoft YaHei UI" />
</ComboBox>
</ui:SimpleStackPanel>
<Controls:UniformGrid Columns="3" Width="300" Height="55">
<ui:SimpleStackPanel
x:Name="NibModeSimpleStackPanel"
Orientation="Horizontal" Width="100">
<Label Content="笔尖模式" FontSize="15"
VerticalAlignment="Center" /> VerticalAlignment="Center" />
<ComboBox Height="30" VerticalAlignment="Center" <ui:ToggleSwitch
Name="ComboBoxPenStyle" x:Name="ToggleSwitchEnableNibMode"
FontFamily="Microsoft YaHei UI" MinWidth="0"
SelectedIndex="0" FontFamily="Microsoft YaHei UI"
SelectionChanged="ComboBoxPenStyle_SelectionChanged"> Width="80" Margin="10,0,0,0"
<ComboBoxItem Content="基于点集" Toggled="ToggleSwitchEnableNibMode_Toggled"
FontFamily="Microsoft YaHei UI" /> IsOn="True" />
<ComboBoxItem Content="基于速率"
FontFamily="Microsoft YaHei UI" />
<ComboBoxItem Content="关闭笔锋"
FontFamily="Microsoft YaHei UI" />
</ComboBox>
</ui:SimpleStackPanel> </ui:SimpleStackPanel>
<ui:SimpleStackPanel Margin="0,-5,0,-5" <ui:SimpleStackPanel Orientation="Horizontal"
VerticalAlignment="Center"> Width="100">
<ui:SimpleStackPanel <Label Margin="0,0,10,0" Content="墨迹纠正"
x:Name="NibModeSimpleStackPanel" Foreground="{DynamicResource FloatBarForeground}"
Orientation="Horizontal" Width="140"> FontSize="15" VerticalAlignment="Center" />
<Label Content="笔尖模式" FontSize="15" <ui:ToggleSwitch
VerticalAlignment="Center" /> Foreground="{DynamicResource FloatBarForeground}"
<ui:ToggleSwitch FontFamily="Microsoft YaHei UI" Width="80"
x:Name="ToggleSwitchEnableNibMode" Toggled="ToggleSwitchEnableInkToShape_Toggled"
MinWidth="0" MinWidth="0"
FontFamily="Microsoft YaHei UI" IsOn="{Binding ElementName=ToggleSwitchEnableInkToShape, Path=IsOn}" />
Width="70" Margin="10,0,0,0" </ui:SimpleStackPanel>
Toggled="ToggleSwitchEnableNibMode_Toggled" <ui:SimpleStackPanel Orientation="Horizontal"
IsOn="True" /> Width="100">
</ui:SimpleStackPanel> <Label Margin="0,0,10,0" Content="墨迹渐隐"
<ui:SimpleStackPanel Orientation="Horizontal" Foreground="{DynamicResource FloatBarForeground}"
Width="140"> FontSize="15" VerticalAlignment="Center" />
<Label Margin="0,0,10,0" Content="墨迹纠正" <ui:ToggleSwitch
Foreground="{DynamicResource FloatBarForeground}" x:Name="ToggleSwitchInkFadeInPanel2"
FontSize="15" VerticalAlignment="Center" /> Foreground="{DynamicResource FloatBarForeground}"
<ui:ToggleSwitch FontFamily="Microsoft YaHei UI" Width="90"
Foreground="{DynamicResource FloatBarForeground}" Toggled="ToggleSwitchInkFadeInPanel_Toggled"
FontFamily="Microsoft YaHei UI" Width="70" MinWidth="0"
Toggled="ToggleSwitchEnableInkToShape_Toggled" IsOn="{Binding ElementName=ToggleSwitchInkFadeInPanel, Path=IsOn}" />
MinWidth="0"
IsOn="{Binding ElementName=ToggleSwitchEnableInkToShape, Path=IsOn}" />
</ui:SimpleStackPanel>
</ui:SimpleStackPanel> </ui:SimpleStackPanel>
</Controls:UniformGrid> </Controls:UniformGrid>
@@ -7994,17 +8016,7 @@
</Canvas> </Canvas>
</ui:SimpleStackPanel> </ui:SimpleStackPanel>
</Border> </Border>
<!-- 墨迹渐隐开关 -->
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left"
Margin="8,8,8,4" Spacing="8">
<TextBlock Foreground="#1e3a8a" Text="墨迹渐隐" FontSize="12"
VerticalAlignment="Center" FontWeight="SemiBold" />
<ui:ToggleSwitch OnContent="" OffContent="" Name="ToggleSwitchInkFadeInPanel"
IsOn="False" FontFamily="Microsoft YaHei UI"
FontWeight="Bold" Toggled="ToggleSwitchInkFadeInPanel_Toggled" />
</ui:SimpleStackPanel>
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="315" Y2="0"
Stroke="#e5e7eb" StrokeThickness="1" Margin="8,0,8,4" />
<ui:SimpleStackPanel Orientation="Horizontal" Height="38" Spacing="2" <ui:SimpleStackPanel Orientation="Horizontal" Height="38" Spacing="2"
Margin="4,6,4,0"> Margin="4,6,4,0">
<ui:SimpleStackPanel Name="BoardImageDrawLine" <ui:SimpleStackPanel Name="BoardImageDrawLine"
@@ -907,6 +907,12 @@ namespace Ink_Canvas
ToggleSwitchInkFadeInPanel.IsOn = Settings.Canvas.EnableInkFade; ToggleSwitchInkFadeInPanel.IsOn = Settings.Canvas.EnableInkFade;
} }
// 同步普通画笔面板中的开关状态
if (ToggleSwitchInkFadeInPanel2 != null)
{
ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade;
}
// 同步滑块值 // 同步滑块值
if (InkFadeTimeSlider != null) if (InkFadeTimeSlider != null)
{ {
+21 -10
View File
@@ -34,8 +34,10 @@ namespace Ink_Canvas.Windows
{ {
try try
{ {
// 不自动启用快捷键注册功能,让用户手动决定 // 不启用快捷键注册功能,只读取配置文件中的快捷键信息用于显示
// 只加载当前已注册的快捷键 // 这样用户可以看到配置文件中保存的快捷键,但不会自动注册
// 加载当前快捷键(包括配置文件中的)
LoadCurrentHotkeys(); LoadCurrentHotkeys();
SetupEventHandlers(); SetupEventHandlers();
} }
@@ -124,22 +126,31 @@ namespace Ink_Canvas.Windows
{ {
try try
{ {
var registeredHotkeys = _hotkeyManager.GetRegisteredHotkeys(); // 首先尝试从配置文件获取快捷键信息
LogHelper.WriteLogToFile($"当前已注册快捷键数量: {registeredHotkeys.Count}", LogHelper.LogType.Info); var configHotkeys = _hotkeyManager.GetHotkeysFromConfigFile();
LogHelper.WriteLogToFile($"配置文件中的快捷键数量: {configHotkeys.Count}", LogHelper.LogType.Info);
// 显示已注册的快捷键 // 显示配置文件中的快捷键
foreach (var hotkey in registeredHotkeys) foreach (var hotkey in configHotkeys)
{ {
if (_hotkeyItems.TryGetValue(hotkey.Name, out var hotkeyItem)) if (_hotkeyItems.TryGetValue(hotkey.Name, out var hotkeyItem))
{ {
hotkeyItem.SetCurrentHotkey(hotkey.Key, hotkey.Modifiers); hotkeyItem.SetCurrentHotkey(hotkey.Key, hotkey.Modifiers);
LogHelper.WriteLogToFile($"设置快捷键项: {hotkey.Name} -> {hotkey.Modifiers}+{hotkey.Key}", LogHelper.LogType.Info); LogHelper.WriteLogToFile($"从配置文件设置快捷键项: {hotkey.Name} -> {hotkey.Modifiers}+{hotkey.Key}", LogHelper.LogType.Info);
} }
} }
// 对于没有快捷键的项目,不设置任何值,保持为空状态 // 没有快捷键的项目设置默认显示值(仅用于UI显示,不实际注册)
// 这样用户就能清楚地知道哪些快捷键还没有设置 foreach (var kvp in _hotkeyItems)
LogHelper.WriteLogToFile("未注册的快捷键项保持为空状态", LogHelper.LogType.Info); {
var hotkeyItem = kvp.Value;
if (hotkeyItem.GetCurrentHotkey().key == Key.None)
{
// 根据DefaultKey和DefaultModifiers设置默认显示值
SetDefaultHotkeyForItem(hotkeyItem);
LogHelper.WriteLogToFile($"设置默认显示值: {hotkeyItem.HotkeyName}", LogHelper.LogType.Info);
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {