Merge pull request #465 from InkCanvasForClass/net6

合并462
This commit is contained in:
CJK_mkp
2026-05-02 17:45:07 +08:00
committed by GitHub
41 changed files with 1736 additions and 247 deletions
+293
View File
@@ -0,0 +1,293 @@
<Window x:Class="Ink_Canvas.Windows.OobePresetWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
mc:Ignorable="d"
Title="选择预设配置 - InkCanvasForClass CE"
Height="560" Width="680"
MinHeight="420" MinWidth="520"
WindowStartupLocation="CenterOwner"
Topmost="True"
ui:ThemeManager.IsThemeAware="True"
ui:TitleBar.ExtendViewIntoTitleBar="True"
ui:WindowHelper.SystemBackdropType="Mica"
ui:WindowHelper.UseModernWindowStyle="True"
ui:TitleBar.Height="40">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources CanBeAccessedAcrossThreads="True">
<ui:ThemeResources.ThemeDictionaries />
</ui:ThemeResources>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 标题栏 -->
<Border Grid.Row="0"
x:Name="AppTitleBar"
Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=(ui:TitleBar.Height)}"
Background="Transparent"
IsHitTestVisible="True"
Canvas.ZIndex="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="137" />
</Grid.ColumnDefinitions>
<ikw:SimpleStackPanel Grid.Column="0"
Orientation="Horizontal"
Spacing="12"
VerticalAlignment="Center"
Margin="16,0,0,0">
<Image Source="\Resources\icc.ico" Width="18"
RenderOptions.BitmapScalingMode="HighQuality" />
<TextBlock VerticalAlignment="Center"
Text="选择预设配置"
TextWrapping="NoWrap" />
</ikw:SimpleStackPanel>
<Rectangle Grid.Column="2"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=(ui:TitleBar.SystemOverlayRightInset)}" />
</Grid>
</Border>
<!-- Banner Header -->
<Border Grid.Row="1"
Padding="36,16,36,16"
BorderThickness="0,0,0,1"
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="#1F3B82F6" Offset="0" />
<GradientStop Color="#0A10B981" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Width="44" Height="44"
Margin="0,0,14,0"
CornerRadius="10"
Background="{DynamicResource SystemControlBackgroundChromeMediumBrush}">
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Repair}"
FontSize="22"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ikw:SimpleStackPanel Grid.Column="1" Spacing="2" VerticalAlignment="Center">
<TextBlock Style="{DynamicResource TitleTextBlockStyle}"
Text="选择预设配置" />
<TextBlock Style="{DynamicResource BodyTextBlockStyle}"
Opacity="0.85"
TextWrapping="Wrap"
Text="选择一套由开发者调校的推荐配置,一键完成设置。所有选项可在「设置」中随时修改。" />
</ikw:SimpleStackPanel>
</Grid>
</Border>
<!-- 预设列表 -->
<ScrollViewer Grid.Row="2"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled"
PanningMode="VerticalFirst"
Padding="36,16,36,8">
<ikw:SimpleStackPanel Spacing="10">
<!-- 预设卡片: 课堂标准配置 -->
<Border x:Name="CardStandard"
CornerRadius="8"
Padding="20,16"
BorderThickness="2"
Cursor="Hand"
MouseLeftButtonDown="CardStandard_Click">
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlForegroundBaseLowBrush}" />
<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}" />
</Style>
</Border.Style>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Width="40" Height="40"
CornerRadius="8"
Margin="0,0,14,0"
Background="{DynamicResource SystemControlBackgroundAccentBrush}">
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Slideshow}"
FontSize="20"
Foreground="White"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ikw:SimpleStackPanel Grid.Column="1" Spacing="3" VerticalAlignment="Center">
<TextBlock Style="{DynamicResource BodyStrongTextBlockStyle}"
Text="课堂标准配置" />
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Opacity="0.75"
TextWrapping="Wrap"
Text="启用 PPT 联动、自动保存墨迹、托盘图标、双指手势,适合大多数课堂场景。" />
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6" Margin="0,4,0,0">
<Border CornerRadius="4" Padding="6,2"
Background="{DynamicResource SystemControlBackgroundAccentBrush}">
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Foreground="White" Text="PPT 联动" />
</Border>
<Border CornerRadius="4" Padding="6,2"
Background="{DynamicResource SystemControlBackgroundAccentBrush}">
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Foreground="White" Text="自动保存" />
</Border>
<Border CornerRadius="4" Padding="6,2"
Background="{DynamicResource SystemControlBackgroundAccentBrush}">
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Foreground="White" Text="双指手势" />
</Border>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
<ui:FontIcon x:Name="IconStandard"
Grid.Column="2"
Icon="{x:Static ui:SegoeFluentIcons.RadioBullet}"
FontSize="20"
Margin="12,0,0,0"
Opacity="0"
Foreground="{DynamicResource SystemControlForegroundAccentBrush}"
VerticalAlignment="Center" />
</Grid>
</Border>
<!-- 预设卡片: 简洁轻量配置 -->
<Border x:Name="CardLite"
CornerRadius="8"
Padding="20,16"
BorderThickness="2"
Cursor="Hand"
MouseLeftButtonDown="CardLite_Click">
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlForegroundBaseLowBrush}" />
<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}" />
</Style>
</Border.Style>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Width="40" Height="40"
CornerRadius="8"
Margin="0,0,14,0"
Background="#FF6366F1">
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}"
FontSize="20"
Foreground="White"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ikw:SimpleStackPanel Grid.Column="1" Spacing="3" VerticalAlignment="Center">
<TextBlock Style="{DynamicResource BodyStrongTextBlockStyle}"
Text="简洁轻量配置" />
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Opacity="0.75"
TextWrapping="Wrap"
Text="关闭大部分自动化与联动功能,保持最小后台行为,适合简单批注场景。" />
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6" Margin="0,4,0,0">
<Border CornerRadius="4" Padding="6,2"
Background="#FF6366F1">
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Foreground="White" Text="PPT 联动" />
</Border>
<Border CornerRadius="4" Padding="6,2"
Background="#FF6366F1">
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Foreground="White" Text="托盘图标" />
</Border>
<Border CornerRadius="4" Padding="6,2"
Background="#FF6366F1">
<TextBlock Style="{DynamicResource CaptionTextBlockStyle}"
Foreground="White" Text="自动保存" />
</Border>
</ikw:SimpleStackPanel>
</ikw:SimpleStackPanel>
<ui:FontIcon x:Name="IconLite"
Grid.Column="2"
Icon="{x:Static ui:SegoeFluentIcons.RadioBullet}"
FontSize="20"
Margin="12,0,0,0"
Opacity="0"
Foreground="{DynamicResource SystemControlForegroundAccentBrush}"
VerticalAlignment="Center" />
</Grid>
</Border>
</ikw:SimpleStackPanel>
</ScrollViewer>
<!-- Footer -->
<Border Grid.Row="3"
Padding="36,12,36,16"
BorderThickness="0,1,0,0"
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Style="{DynamicResource CaptionTextBlockStyle}"
Opacity="0.7"
TextWrapping="Wrap"
Text="选择预设后将直接完成初始设置,无需逐步配置。" />
<Button Grid.Column="1"
x:Name="BtnCancel"
MinWidth="96"
Height="32"
Margin="0,0,8,0"
Click="BtnCancel_Click">
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Back}" FontSize="12" />
<TextBlock Text="返回" />
</ikw:SimpleStackPanel>
</Button>
<Button Grid.Column="2"
x:Name="BtnApply"
MinWidth="140"
Height="32"
IsEnabled="False"
Style="{DynamicResource AccentButtonStyle}"
Click="BtnApply_Click">
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="6">
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Accept}" FontSize="12" />
<TextBlock Text="应用并开始使用" />
</ikw:SimpleStackPanel>
</Button>
</Grid>
</Border>
</Grid>
</Window>
+176
View File
@@ -0,0 +1,176 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace Ink_Canvas.Windows
{
public partial class OobePresetWindow : Window
{
public enum PresetKind { None, Standard, Lite }
public PresetKind SelectedPreset { get; private set; } = PresetKind.None;
public OobePresetWindow()
{
InitializeComponent();
}
private void SelectPreset(PresetKind kind)
{
SelectedPreset = kind;
// 重置所有卡片边框
var defaultBrush = (Brush)FindResource("SystemControlForegroundBaseLowBrush");
CardStandard.BorderBrush = defaultBrush;
CardLite.BorderBrush = defaultBrush;
IconStandard.Opacity = 0;
IconLite.Opacity = 0;
var accentBrush = (Brush)FindResource("SystemControlForegroundAccentBrush");
switch (kind)
{
case PresetKind.Standard:
CardStandard.BorderBrush = accentBrush;
IconStandard.Opacity = 1;
break;
case PresetKind.Lite:
CardLite.BorderBrush = accentBrush;
IconLite.Opacity = 1;
break;
}
BtnApply.IsEnabled = kind != PresetKind.None;
}
private void CardStandard_Click(object sender, MouseButtonEventArgs e) => SelectPreset(PresetKind.Standard);
private void CardLite_Click(object sender, MouseButtonEventArgs e) => SelectPreset(PresetKind.Lite);
private void BtnApply_Click(object sender, RoutedEventArgs e)
{
if (SelectedPreset == PresetKind.None) return;
DialogResult = true;
Close();
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
// ── 预设定义 ────────────────────────────────────────────────────────
/// <summary>
/// 课堂标准配置:适合大多数教学场景,启用 PPT 联动、自动保存、手势等。
/// </summary>
public static void ApplyStandard(Settings settings)
{
if (settings == null) return;
// 启动与隐私
settings.Startup.IsFoldAtStartup = true;
settings.Startup.IsAutoUpdate = true;
settings.Startup.CrashAction = 0; // 静默重启
settings.Startup.TelemetryUploadLevel = TelemetryUploadLevel.Basic;
settings.Startup.HasAcceptedTelemetryPrivacy = true;
// 画板与墨迹
settings.Canvas.IsShowCursor = false;
settings.Canvas.DisablePressure = false;
settings.Canvas.HideStrokeWhenSelecting = true;
settings.Canvas.EnablePalmEraser = true;
// 墨迹纠正
settings.InkToShape.IsInkToShapeEnabled = true;
// 手势
settings.Gesture.IsEnableTwoFingerZoom = true;
settings.Gesture.IsEnableTwoFingerTranslate = true;
settings.Gesture.AutoSwitchTwoFingerGesture = true;
// 个性化
settings.Appearance.Theme = 2; // 跟随系统
settings.Appearance.EnableSplashScreen = false;
settings.Appearance.EnableTrayIcon = true;
settings.Appearance.IsShowQuickPanel = true;
settings.Appearance.EnableHotkeysInMouseMode = false;
// PPT 联动
settings.PowerPointSettings.PowerPointSupport = true;
settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint = true;
settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint = true;
settings.PowerPointSettings.EnablePPTTimeCapsule = true;
// 自动化
settings.Automation.IsAutoFoldInPPTSlideShow = false;
settings.Automation.IsEnableAutoSaveStrokes = true;
settings.Automation.IsAutoSaveStrokesAtClear = true;
settings.Automation.IsSaveScreenshotsInDateFolders = true;
if (settings.Automation.FloatingWindowInterceptor != null)
settings.Automation.FloatingWindowInterceptor.IsEnabled = true;
// 随机点名
settings.RandSettings.ShowRandomAndSingleDraw = true;
// 高级
settings.Advanced.IsLogEnabled = true;
}
/// <summary>
/// 简洁轻量配置:最小化后台行为,适合简单批注场景。
/// </summary>
public static void ApplyLite(Settings settings)
{
if (settings == null) return;
// 启动与隐私
settings.Startup.IsFoldAtStartup = true;
settings.Startup.IsAutoUpdate = true;
settings.Startup.CrashAction = 0;
settings.Startup.TelemetryUploadLevel = TelemetryUploadLevel.None;
settings.Startup.HasAcceptedTelemetryPrivacy = true;
// 画板与墨迹
settings.Canvas.IsShowCursor = false;
settings.Canvas.DisablePressure = false;
settings.Canvas.HideStrokeWhenSelecting = true;
settings.Canvas.EnablePalmEraser = false;
// 墨迹纠正
settings.InkToShape.IsInkToShapeEnabled = false;
// 手势
settings.Gesture.IsEnableTwoFingerZoom = false;
settings.Gesture.IsEnableTwoFingerTranslate = false;
settings.Gesture.AutoSwitchTwoFingerGesture = false;
// 个性化
settings.Appearance.Theme = 2; // 跟随系统
settings.Appearance.EnableSplashScreen = false;
settings.Appearance.EnableTrayIcon = true;
settings.Appearance.IsShowQuickPanel = false;
settings.Appearance.EnableHotkeysInMouseMode = false;
// PPT 联动
settings.PowerPointSettings.PowerPointSupport = true;
settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint = true;
settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint = true;
settings.PowerPointSettings.EnablePPTTimeCapsule = false;
// 自动化
settings.Automation.IsAutoFoldInPPTSlideShow = false;
settings.Automation.IsEnableAutoSaveStrokes = true;
settings.Automation.IsAutoSaveStrokesAtClear = true;
settings.Automation.IsSaveScreenshotsInDateFolders = false;
if (settings.Automation.FloatingWindowInterceptor != null)
settings.Automation.FloatingWindowInterceptor.IsEnabled = false;
// 随机点名
settings.RandSettings.ShowRandomAndSingleDraw = true;
// 高级
settings.Advanced.IsLogEnabled = true;
}
}
}
+12 -1
View File
@@ -194,10 +194,21 @@
Style="{DynamicResource AccentButtonStyle}"
Click="BtnStartWelcome_Click">
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="开始" />
<TextBlock Text="开始逐步配置" />
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.ChevronRight}" FontSize="12" />
</ikw:SimpleStackPanel>
</Button>
<Button x:Name="BtnUsePreset"
HorizontalAlignment="Center"
MinWidth="180"
Height="36"
Click="BtnUsePreset_Click">
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="8">
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Repair}" FontSize="12" />
<TextBlock Text="使用预设配置" />
</ikw:SimpleStackPanel>
</Button>
</ikw:SimpleStackPanel>
</Grid>
+22
View File
@@ -303,6 +303,28 @@ namespace Ink_Canvas.Windows
NavigateTo(0, direction: 1);
}
private void BtnUsePreset_Click(object sender, RoutedEventArgs e)
{
var presetWindow = new OobePresetWindow { Owner = this };
bool? result = presetWindow.ShowDialog();
if (result != true) return;
switch (presetWindow.SelectedPreset)
{
case OobePresetWindow.PresetKind.Standard:
OobePresetWindow.ApplyStandard(_settings);
break;
case OobePresetWindow.PresetKind.Lite:
OobePresetWindow.ApplyLite(_settings);
break;
default:
return;
}
DialogResult = true;
Close();
}
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
{
if (_currentStep == FinishIndex)
@@ -157,6 +157,22 @@
OffContent="{DynamicResource Common_Off}"
Toggled="ToggleSwitchHighPrecisionLineStraighten_Toggled" />
</ui:SettingsCard>
<ui:SettingsCard Header="{i18n:I18n Key=InkRecog_PauseStraightenLine}"
Description="{i18n:I18n Key=InkRecog_PauseStraightenHint}">
<ui:ToggleSwitch x:Name="ToggleSwitchPauseStraightenLine"
OnContent="{DynamicResource Common_On}"
OffContent="{DynamicResource Common_Off}"
Toggled="ToggleSwitchPauseStraightenLine_Toggled" />
</ui:SettingsCard>
<ui:SettingsCard Header="{i18n:I18n Key=InkRecog_PauseStraightenDelay}">
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="{Binding Value, ElementName=PauseStraightenDelaySlider, StringFormat={}{0:0} ms}"
VerticalAlignment="Center" FontFamily="Consolas"/>
<Slider x:Name="PauseStraightenDelaySlider" Width="200" Minimum="100" Maximum="1000"
Value="300" TickFrequency="50" IsSnapToTickEnabled="True"
ValueChanged="PauseStraightenDelaySlider_ValueChanged" />
</ikw:SimpleStackPanel>
</ui:SettingsCard>
</ui:SettingsExpander.Items>
</ui:SettingsExpander>
@@ -52,6 +52,8 @@ namespace Ink_Canvas.Windows.SettingsViews.Pages
ToggleSwitchAutoStraightenLine.IsOn = settings.Canvas.AutoStraightenLine;
AutoStraightenLineThresholdSlider.Value = settings.Canvas.AutoStraightenLineThreshold;
ToggleSwitchHighPrecisionLineStraighten.IsOn = settings.Canvas.HighPrecisionLineStraighten;
ToggleSwitchPauseStraightenLine.IsOn = settings.Canvas.PauseStraightenLine;
PauseStraightenDelaySlider.Value = settings.Canvas.PauseStraightenDelay;
ToggleSwitchLineEndpointSnapping.IsOn = settings.Canvas.LineEndpointSnapping;
}
}
@@ -192,6 +194,20 @@ namespace Ink_Canvas.Windows.SettingsViews.Pages
SettingsManager.SaveSettingsToFile();
}
private void ToggleSwitchPauseStraightenLine_Toggled(object sender, RoutedEventArgs e)
{
if (!_isLoaded) return;
SettingsManager.Settings.Canvas.PauseStraightenLine = ToggleSwitchPauseStraightenLine.IsOn;
SettingsManager.SaveSettingsToFile();
}
private void PauseStraightenDelaySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!_isLoaded) return;
SettingsManager.Settings.Canvas.PauseStraightenDelay = (int)PauseStraightenDelaySlider.Value;
SettingsManager.SaveSettingsToFile();
}
private void ToggleSwitchLineEndpointSnapping_Toggled(object sender, RoutedEventArgs e)
{
if (!_isLoaded) return;
@@ -0,0 +1,92 @@
<ui:Page x:Class="Ink_Canvas.Windows.SettingsViews.Pages.ToolbarPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews.Pages"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:dd="urn:gong-wpf-dragdrop"
mc:Ignorable="d"
Title="工具栏">
<Page.Resources>
<Style x:Key="ToolbarItemStyle" TargetType="ListBox">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="dd:DragDrop.IsDragSource" Value="True"/>
<Setter Property="dd:DragDrop.IsDropTarget" Value="True"/>
<Setter Property="dd:DragDrop.UseDefaultEffectDataTemplate" Value="False"/>
<Setter Property="dd:DragDrop.SelectDroppedItems" Value="True"/>
<Setter Property="dd:DragDrop.DropTargetAdornerBrush" Value="#2563eb"/>
<Setter Property="dd:DragDrop.DropHandler" Value="{Binding}"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalOnly"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="dd:DragDrop.EffectMoveAdornerTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="#2563eb" CornerRadius="12" Padding="16,8"
Opacity="0.9">
<TextBlock Text="移动" Foreground="White"
FontSize="13" FontWeight="Medium"
VerticalAlignment="Center"/>
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="ToolbarItemTemplate">
<Grid Height="44" Margin="0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="&#xE76F;"
FontFamily="Segoe MDL2 Assets" FontSize="14"
VerticalAlignment="Center" Margin="0,0,10,0" Opacity="0.45"/>
<TextBlock Grid.Column="1" Text="{Binding DisplayName}"
FontSize="14" VerticalAlignment="Center"/>
<CheckBox Grid.Column="2" IsChecked="{Binding IsVisible, Mode=TwoWay}"
VerticalAlignment="Center" Margin="12,0,0,0"
ToolTip="显示或隐藏此按钮"/>
</Grid>
</DataTemplate>
</Page.Resources>
<ScrollViewer PanningMode="VerticalFirst">
<StackPanel Margin="59,0,59,0" MaxWidth="1000">
<!-- 主工具栏 -->
<TextBlock Text="主工具栏" FontSize="16" FontWeight="Bold" Margin="0,20,0,4"/>
<TextBlock Text="拖动调整顺序,开关控制显示。隐藏的按钮不会出现在浮动工具栏中。"
Opacity="0.65" FontSize="12" Margin="0,0,0,8"/>
<ListBox Name="MainItemsList" Style="{StaticResource ToolbarItemStyle}"
ItemTemplate="{StaticResource ToolbarItemTemplate}"
ItemsSource="{Binding MainItems}" />
<!-- 画布控制 -->
<TextBlock Text="画布控制" FontSize="16" FontWeight="Bold" Margin="0,24,0,4"/>
<TextBlock Text="批注模式下可见的工具按钮排序。"
Opacity="0.65" FontSize="12" Margin="0,0,0,8"/>
<ListBox Name="CanvasItemsList" Style="{StaticResource ToolbarItemStyle}"
ItemTemplate="{StaticResource ToolbarItemTemplate}"
ItemsSource="{Binding CanvasItems}" />
<!-- 尾部按钮 -->
<TextBlock Text="尾部按钮" FontSize="16" FontWeight="Bold" Margin="0,24,0,4"/>
<TextBlock Text="白板、工具、折叠按钮排序。"
Opacity="0.65" FontSize="12" Margin="0,0,0,8"/>
<ListBox Name="EndItemsList" Style="{StaticResource ToolbarItemStyle}"
ItemTemplate="{StaticResource ToolbarItemTemplate}"
ItemsSource="{Binding EndItems}" />
<Button Content="恢复默认布局" Click="ButtonReset_Click"
Padding="20,10" HorizontalAlignment="Left" Margin="0,16,0,0"/>
</StackPanel>
</ScrollViewer>
</ui:Page>
@@ -0,0 +1,232 @@
using GongSolutions.Wpf.DragDrop;
using Ink_Canvas.Controls.Toolbar;
using Ink_Canvas.Helpers;
using Ink_Canvas.Windows.SettingsViews.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Page = iNKORE.UI.WPF.Modern.Controls.Page;
namespace Ink_Canvas.Windows.SettingsViews.Pages
{
public partial class ToolbarPage : Page, IDropTarget
{
public class ToolbarItemViewModel : INotifyPropertyChanged
{
public string Id { get; }
public string DisplayName { get; }
private int _order;
public int Order { get => _order; set { _order = value; OnPropertyChanged(nameof(Order)); } }
private bool _isVisible = true;
public bool IsVisible { get => _isVisible; set { _isVisible = value; OnPropertyChanged(nameof(IsVisible)); } }
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public ToolbarItemViewModel(string id, string displayName, int order, bool isVisible)
{
Id = id; DisplayName = displayName; _order = order; _isVisible = isVisible;
}
}
private static readonly string LogTag = "ToolbarPage";
private bool _isLoaded;
public ObservableCollection<ToolbarItemViewModel> MainItems { get; } = new();
public ObservableCollection<ToolbarItemViewModel> CanvasItems { get; } = new();
public ObservableCollection<ToolbarItemViewModel> EndItems { get; } = new();
public ToolbarPage()
{
InitializeComponent();
DataContext = this;
Loaded += OnPageLoaded;
}
private void OnPageLoaded(object sender, RoutedEventArgs e)
{
try { LoadSettings(); }
catch (Exception ex)
{
LogHelper.WriteLogToFile($"{LogTag}: LoadSettings 异常: {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}", LogHelper.LogType.Error);
}
_isLoaded = true;
}
private void LoadSettings()
{
LogHelper.WriteLogToFile($"{LogTag}: LoadSettings 开始", LogHelper.LogType.Info);
MainItems.Clear(); CanvasItems.Clear(); EndItems.Clear();
var layout = SettingsManager.Settings?.Toolbar ?? new ToolbarLayoutSettings();
IReadOnlyList<IToolbarItem> discoveredItems;
try { discoveredItems = ToolbarRegistry.Discover(); }
catch (Exception ex) { LogHelper.WriteLogToFile($"{LogTag}: Discover 失败: {ex.Message}", LogHelper.LogType.Error); return; }
foreach (var item in discoveredItems)
{
try
{
if (!layout.Items.TryGetValue(item.Id, out var cfg))
{
cfg = new ToolbarItemConfig
{
Visible = item.DefaultVisible,
Order = item.DefaultOrder,
Slot = item.DefaultSlot,
Position = item.DefaultPosition,
AnchorName = item.DefaultAnchorName
};
}
string displayName;
try { displayName = item.DisplayName ?? item.Id; }
catch { displayName = item.Id; }
var vm = new ToolbarItemViewModel(item.Id, displayName, cfg.Order, cfg.Visible);
switch (cfg.Slot)
{
case ToolbarSlot.FloatingBarMain: MainItems.Add(vm); break;
case ToolbarSlot.FloatingBarCanvasControls: CanvasItems.Add(vm); break;
case ToolbarSlot.FloatingBarEnd: EndItems.Add(vm); break;
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"{LogTag}: 处理条目失败 [{item?.Id}]: {ex.Message}", LogHelper.LogType.Warning);
}
}
ReorderCollections();
LogHelper.WriteLogToFile($"{LogTag}: LoadSettings 完成 Main={MainItems.Count} Canvas={CanvasItems.Count} End={EndItems.Count}", LogHelper.LogType.Info);
}
private void ReorderCollections()
{
SortCollection(MainItems);
SortCollection(CanvasItems);
SortCollection(EndItems);
}
private static void SortCollection(ObservableCollection<ToolbarItemViewModel> collection)
{
if (collection == null) return;
var sorted = collection.OrderBy(x => x.Order).ToList();
for (int i = 0; i < sorted.Count; i++)
{
var oldIndex = collection.IndexOf(sorted[i]);
if (oldIndex != -1 && oldIndex != i)
collection.Move(oldIndex, i);
}
}
public new void DragOver(IDropInfo dropInfo)
{
if (dropInfo.Data is not ToolbarItemViewModel) return;
dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
dropInfo.Effects = DragDropEffects.Move;
}
public new void Drop(IDropInfo dropInfo)
{
if (dropInfo.Data is not ToolbarItemViewModel vm) return;
if (dropInfo.TargetCollection is not ObservableCollection<ToolbarItemViewModel> target) return;
var oldIndex = target.IndexOf(vm);
var newIndex = oldIndex < dropInfo.UnfilteredInsertIndex ? dropInfo.UnfilteredInsertIndex - 1 : dropInfo.UnfilteredInsertIndex;
var finalIndex = Math.Min(newIndex >= target.Count ? target.Count - 1 : newIndex, target.Count);
if (!target.Contains(vm))
{
if (dropInfo.DragInfo.SourceCollection is ObservableCollection<ToolbarItemViewModel> source)
source.Remove(vm);
target.Insert(dropInfo.UnfilteredInsertIndex, vm);
}
else if (oldIndex != -1 && oldIndex != finalIndex)
{
target.Move(oldIndex, finalIndex);
}
UpdateOrdersFromCollection(target);
SaveSettings();
}
private static void UpdateOrdersFromCollection(ObservableCollection<ToolbarItemViewModel> collection)
{
for (int i = 0; i < collection.Count; i++)
collection[i].Order = (i + 1) * 10;
}
private void SaveSettings()
{
if (!_isLoaded) return;
try
{
var settings = SettingsManager.Settings;
if (settings == null) return;
if (settings.Toolbar == null) settings.Toolbar = new ToolbarLayoutSettings();
var layout = settings.Toolbar;
foreach (var vm in MainItems.Concat(CanvasItems).Concat(EndItems))
{
if (!layout.Items.TryGetValue(vm.Id, out var cfg))
{
var item = ToolbarRegistry.Discover().FirstOrDefault(i => i.Id == vm.Id);
cfg = new ToolbarItemConfig
{
Visible = item?.DefaultVisible ?? true,
Order = item?.DefaultOrder ?? 0,
Slot = item?.DefaultSlot ?? ToolbarSlot.FloatingBarMain,
Position = item?.DefaultPosition ?? ToolbarInsertPosition.Prepend,
AnchorName = item?.DefaultAnchorName
};
layout.Items[vm.Id] = cfg;
}
cfg.Visible = vm.IsVisible;
cfg.Order = vm.Order;
}
SettingsManager.SaveSettingsToFile();
LogHelper.WriteLogToFile($"{LogTag}: 设置已保存", LogHelper.LogType.Info);
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
var mainWindow = Application.Current.Windows.OfType<MainWindow>().FirstOrDefault();
mainWindow?.RebuildToolbar();
}
catch (Exception ex) { LogHelper.WriteLogToFile($"{LogTag}: RebuildToolbar 异常: {ex.Message}", LogHelper.LogType.Error); }
}));
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"{LogTag}: SaveSettings 异常: {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}", LogHelper.LogType.Error);
}
}
private void ButtonReset_Click(object sender, RoutedEventArgs e)
{
try
{
SettingsManager.Settings?.Toolbar?.Items.Clear();
SettingsManager.SaveSettingsToFile();
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
try { Application.Current.Windows.OfType<MainWindow>().FirstOrDefault()?.RebuildToolbar(); }
catch (Exception ex) { LogHelper.WriteLogToFile($"{LogTag}: Reset Rebuild 异常: {ex.Message}", LogHelper.LogType.Error); }
}));
LoadSettings();
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"{LogTag}: ButtonReset 异常: {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}", LogHelper.LogType.Error);
}
}
}
}
@@ -202,6 +202,15 @@
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.KeyboardStandard}"/>
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem
x:Name="ToolbarPageItem"
Content="工具栏"
Tag="ToolbarPage"
ToolTipService.ToolTip="工具栏按钮排序与可见性">
<ui:NavigationViewItem.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Rename}"/>
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
</ui:NavigationViewItem.MenuItems>
</ui:NavigationViewItem>
@@ -45,6 +45,7 @@ namespace Ink_Canvas.Windows.SettingsViews
{ "WindowPage", typeof(WindowPage) },
{ "AppearancePage", typeof(AppearancePage) },
{ "HotkeyPage", typeof(HotkeyPage) },
{ "ToolbarPage", typeof(ToolbarPage) },
{ "UpdatePage", typeof(UpdatePage) },
{ "ExperimentalPage", typeof(ExperimentalPage) },
{ "AdvancedPage", typeof(AdvancedPage) },
@@ -313,8 +314,10 @@ namespace Ink_Canvas.Windows.SettingsViews
if (!_pages.TryGetValue(pageTag, out var cachedPage))
{
Ink_Canvas.Helpers.LogHelper.WriteLogToFile($"SettingsWindow: 创建页面实例 {pageTag} ({pageType.Name})", Ink_Canvas.Helpers.LogHelper.LogType.Info);
cachedPage = Activator.CreateInstance(pageType);
_pages.Add(pageTag, cachedPage);
Ink_Canvas.Helpers.LogHelper.WriteLogToFile($"SettingsWindow: 页面实例 {pageTag} 创建成功", Ink_Canvas.Helpers.LogHelper.LogType.Info);
}
if (cachedPage is PluginSettingsPage pluginSettingsPage && pluginInfo != null)
@@ -326,6 +329,7 @@ namespace Ink_Canvas.Windows.SettingsViews
}
catch (Exception ex)
{
Ink_Canvas.Helpers.LogHelper.WriteLogToFile($"SettingsWindow: 导航到 {pageTag} 异常: {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}", Ink_Canvas.Helpers.LogHelper.LogType.Error);
MessageBox.Show($"导航到页面时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally