diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index aede2b85..17bd2740 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -911,6 +911,28 @@ FontSize="12" Margin="12,0,0,0" VerticalAlignment="Center" /> + + + + + + + + + + + + diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 4df53c84..3f36ab65 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -200,6 +200,10 @@ namespace Ink_Canvas inkCanvas.PreviewMouseDown += inkCanvas_PreviewMouseDown; inkCanvas.StylusDown += inkCanvas_StylusDown; inkCanvas.MouseRightButtonUp += InkCanvas_MouseRightButtonUp; + + // 注册橡皮擦操作结束事件(StylusUp 用于自动切换回批注;MouseUp 在 MW_ShapeDrawing.cs 的 inkCanvas_MouseUp 中会调用 HandleEraserOperationEnded) + inkCanvas.StylusUp += inkCanvas_StylusUp; + inkCanvas.MouseUp += inkCanvas_MouseUp; // 初始化第一页Canvas var firstCanvas = new System.Windows.Controls.Canvas(); @@ -1334,9 +1338,19 @@ namespace Ink_Canvas // 初始化UIA置顶开关 ToggleSwitchUIAccessTopMost.IsOn = Settings.Advanced.EnableUIAccessTopMost; UpdateUIAccessTopMostVisibility(); - + App.IsUIAccessTopMostEnabled = Settings.Advanced.EnableUIAccessTopMost; + // 初始化橡皮擦自动切换回批注模式开关 + if (ToggleSwitchEnableEraserAutoSwitchBack != null) + { + ToggleSwitchEnableEraserAutoSwitchBack.IsOn = Settings.Canvas.EnableEraserAutoSwitchBack; + } + if (EraserAutoSwitchBackDelaySlider != null) + { + EraserAutoSwitchBackDelaySlider.Value = Settings.Canvas.EraserAutoSwitchBackDelaySeconds; + } + // 初始化剪贴板监控 InitializeClipboardMonitoring(); @@ -2166,6 +2180,43 @@ namespace Ink_Canvas SetCursorBasedOnEditingMode(sender as InkCanvas); } + // 手写笔抬起事件(用于橡皮擦自动切换) + private void inkCanvas_StylusUp(object sender, StylusEventArgs e) + { + HandleEraserOperationEnded(); + } + + /// + /// 处理橡皮擦操作结束事件 + /// + private void HandleEraserOperationEnded() + { + try + { + // 检查是否在橡皮擦模式且启用了自动切换功能 + if ((inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint || + inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke) && + Settings.Canvas.EnableEraserAutoSwitchBack) + { + // 启动或重启计时器 + StartEraserAutoSwitchBackTimer(); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"处理橡皮擦操作结束事件失败: {ex.Message}", LogHelper.LogType.Error); + } + } + + /// + /// 注册橡皮擦操作监听器(在切换到橡皮擦模式时调用) + /// + private void RegisterEraserOperationListeners() + { + // 事件已经在构造函数中注册,这里只需要确保计时器在操作结束时启动 + // 实际的启动逻辑在HandleEraserOperationEnded中处理 + } + // 触摸结束,恢复光标 #endregion Definations and Loading @@ -3425,6 +3476,56 @@ namespace Ink_Canvas } } + /// + /// 橡皮擦自动切换回批注模式开关切换事件处理 + /// + private void ToggleSwitchEnableEraserAutoSwitchBack_Toggled(object sender, RoutedEventArgs e) + { + try + { + if (!isLoaded) return; + Settings.Canvas.EnableEraserAutoSwitchBack = ToggleSwitchEnableEraserAutoSwitchBack.IsOn; + SaveSettingsToFile(); + + // 如果禁用,停止计时器 + if (!Settings.Canvas.EnableEraserAutoSwitchBack) + { + StopEraserAutoSwitchBackTimer(); + } + + LogHelper.WriteLogToFile($"橡皮擦自动切换回批注模式已{(Settings.Canvas.EnableEraserAutoSwitchBack ? "启用" : "禁用")}", LogHelper.LogType.Event); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"切换橡皮擦自动切换回批注模式时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + + /// + /// 橡皮擦自动切换延迟时间滑块值改变事件处理 + /// + private void EraserAutoSwitchBackDelaySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + try + { + if (!isLoaded) return; + Settings.Canvas.EraserAutoSwitchBackDelaySeconds = (int)e.NewValue; + SaveSettingsToFile(); + + // 如果计时器正在运行,重新启动以应用新的延迟时间 + if (_eraserAutoSwitchBackTimer != null && _eraserAutoSwitchBackTimer.IsEnabled) + { + StartEraserAutoSwitchBackTimer(); + } + + LogHelper.WriteLogToFile($"橡皮擦自动切换延迟时间已更新为 {Settings.Canvas.EraserAutoSwitchBackDelaySeconds} 秒", LogHelper.LogType.Event); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"更新橡皮擦自动切换延迟时间时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + /// /// 根据开关状态启用或禁用画笔自动恢复:更新设置并保存,启用时初始化并安排恢复定时器,禁用时停止计时器。 /// diff --git a/Ink Canvas/MainWindow_cs/MW_BoardControls.cs b/Ink Canvas/MainWindow_cs/MW_BoardControls.cs index 0ea50a57..f37f4333 100644 --- a/Ink Canvas/MainWindow_cs/MW_BoardControls.cs +++ b/Ink Canvas/MainWindow_cs/MW_BoardControls.cs @@ -383,7 +383,6 @@ namespace Ink_Canvas /// 事件参数。 private void BtnWhiteBoardSwitchNext_Click(object sender, EventArgs e) { - Trace.WriteLine("113223234"); if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true); diff --git a/Ink Canvas/MainWindow_cs/MW_Eraser.cs b/Ink Canvas/MainWindow_cs/MW_Eraser.cs index 154729a0..0b1e203c 100644 --- a/Ink Canvas/MainWindow_cs/MW_Eraser.cs +++ b/Ink Canvas/MainWindow_cs/MW_Eraser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Linq; using System.Windows; @@ -174,6 +174,9 @@ namespace Ink_Canvas AddedStroke = null; ReplacedStroke = null; } + + // 橡皮擦自动切换回批注 + HandleEraserOperationEnded(); } /// diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index 90bb9f13..83447063 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -2267,6 +2267,9 @@ namespace Ink_Canvas // 禁用高级橡皮擦系统 DisableEraserOverlay(); + // 停止橡皮擦自动切换计时器(如果正在运行) + StopEraserAutoSwitchBackTimer(); + SetFloatingBarHighlightPosition("pen"); // 记录当前是否已经是批注模式且是否为高光显示模式 @@ -2526,6 +2529,12 @@ namespace Ink_Canvas HideSubPanels("eraser"); // 高亮橡皮按钮 Trace.WriteLine($"Eraser: Eraser button clicked, current size: {eraserWidth}, circle: {isEraserCircleShape}"); + // 如果启用了橡皮擦自动切换功能,停止之前的计时器(如果正在运行) + if (Settings.Canvas.EnableEraserAutoSwitchBack) + { + StopEraserAutoSwitchBackTimer(); + } + if (isAlreadyEraser) { // 已是橡皮状态,再次点击才弹出/收起面板 @@ -2570,6 +2579,12 @@ namespace Ink_Canvas SetCursorBasedOnEditingMode(inkCanvas); HideSubPanels("eraser"); // 高亮橡皮按钮 + // 如果启用了橡皮擦自动切换功能,停止之前的计时器(如果正在运行) + if (Settings.Canvas.EnableEraserAutoSwitchBack) + { + StopEraserAutoSwitchBackTimer(); + } + if (isAlreadyEraser) { // 已是橡皮状态,再次点击才弹出/收起面板 diff --git a/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs b/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs index 09376174..dd0617b6 100644 --- a/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs +++ b/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs @@ -2564,6 +2564,7 @@ namespace Ink_Canvas /// private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e) { + HandleEraserOperationEnded(); // 橡皮擦自动切换回批注模式:松手后启动/重置计时 inkCanvas.ReleaseMouseCapture(); ViewboxFloatingBar.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true; diff --git a/Ink Canvas/MainWindow_cs/MW_Timer.cs b/Ink Canvas/MainWindow_cs/MW_Timer.cs index 6852bcdf..59a6099d 100644 --- a/Ink Canvas/MainWindow_cs/MW_Timer.cs +++ b/Ink Canvas/MainWindow_cs/MW_Timer.cs @@ -123,7 +123,6 @@ namespace Ink_Canvas /// NTP时间同步定时器 /// private Timer timerNtpSync = new Timer(); - /// /// 时间视图模型实例 /// @@ -156,7 +155,10 @@ namespace Ink_Canvas /// 防止重复NTP同步的标志 /// private bool isNtpSyncing = false; - + /// + /// 橡皮擦自动切换回批注模式的计时器 + /// + private DispatcherTimer _eraserAutoSwitchBackTimer; /// /// 异步获取网络时间 /// @@ -248,6 +250,9 @@ namespace Ink_Canvas // 初始化定时保存墨迹定时器 InitAutoSaveStrokesTimer(); + + // 初始化橡皮擦自动切换回批注模式计时器 + InitEraserAutoSwitchBackTimer(); } /// @@ -1381,5 +1386,101 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"AutoUpdate | Error resetting retry state: {ex.Message}", LogHelper.LogType.Error); } } + + /// + /// 初始化橡皮擦自动切换回批注模式计时器 + /// + private void InitEraserAutoSwitchBackTimer() + { + if (_eraserAutoSwitchBackTimer == null) + { + _eraserAutoSwitchBackTimer = new DispatcherTimer(); + _eraserAutoSwitchBackTimer.Tick += EraserAutoSwitchBackTimer_Tick; + } + } + + /// + /// 启动橡皮擦自动切换回批注模式计时器 + /// + public void StartEraserAutoSwitchBackTimer() + { + try + { + if (!Settings.Canvas.EnableEraserAutoSwitchBack) return; + if (_eraserAutoSwitchBackTimer == null) InitEraserAutoSwitchBackTimer(); + + // 停止之前的计时器 + _eraserAutoSwitchBackTimer.Stop(); + + // 设置计时器间隔 + int delaySeconds = Settings.Canvas.EraserAutoSwitchBackDelaySeconds; + if (delaySeconds < 1) delaySeconds = 10; // 最小1秒 + _eraserAutoSwitchBackTimer.Interval = TimeSpan.FromSeconds(delaySeconds); + + // 启动计时器 + _eraserAutoSwitchBackTimer.Start(); + + LogHelper.WriteLogToFile($"橡皮擦自动切换计时器已启动,延迟 {delaySeconds} 秒", LogHelper.LogType.Trace); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"启动橡皮擦自动切换计时器失败: {ex.Message}", LogHelper.LogType.Error); + } + } + + /// + /// 停止橡皮擦自动切换回批注模式计时器 + /// + public void StopEraserAutoSwitchBackTimer() + { + try + { + if (_eraserAutoSwitchBackTimer != null) + { + _eraserAutoSwitchBackTimer.Stop(); + LogHelper.WriteLogToFile("橡皮擦自动切换计时器已停止", LogHelper.LogType.Trace); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"停止橡皮擦自动切换计时器失败: {ex.Message}", LogHelper.LogType.Error); + } + } + + /// + /// 橡皮擦自动切换回批注模式计时器事件处理 + /// + private void EraserAutoSwitchBackTimer_Tick(object sender, EventArgs e) + { + try + { + // 检查是否仍然在橡皮擦模式 + if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint && + inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke) + { + StopEraserAutoSwitchBackTimer(); + return; + } + + // 检查设置是否仍然启用 + if (!Settings.Canvas.EnableEraserAutoSwitchBack) + { + StopEraserAutoSwitchBackTimer(); + return; + } + + // 切换到批注模式 + Dispatcher.Invoke(() => + { + PenIcon_Click(null, null); + StopEraserAutoSwitchBackTimer(); + LogHelper.WriteLogToFile("橡皮擦自动切换回批注模式", LogHelper.LogType.Event); + }); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"橡皮擦自动切换计时器事件处理失败: {ex.Message}", LogHelper.LogType.Error); + } + } } } \ No newline at end of file diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index dec27069..5dd07a71 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -140,6 +140,10 @@ namespace Ink_Canvas public double BrushAutoRestoreWidth { get; set; } =5; [JsonProperty("brushAutoRestoreAlpha")] public int BrushAutoRestoreAlpha { get; set; } = 255; + [JsonProperty("enableEraserAutoSwitchBack")] + public bool EnableEraserAutoSwitchBack { get; set; } = false; + [JsonProperty("eraserAutoSwitchBackDelaySeconds")] + public int EraserAutoSwitchBackDelaySeconds { get; set; } = 10; // 默认10秒 }