From 8b2bc2f064120936a43eae455e390e511fcaad0c Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sat, 13 Dec 2025 17:38:35 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E9=80=80=E5=87=BA=E6=94=BE=E6=98=A0?= =?UTF-8?q?=E6=97=B6=E6=94=B6=E7=BA=B3=E5=8F=8APPT=E8=AE=B0=E5=BF=86?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E6=92=AD=E6=94=BE=E9=A1=B5=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/PPTInkManager.cs | 18 +- Ink Canvas/MainWindow.xaml | 4 +- .../MainWindow_cs/MW_FloatingBarIcons.cs | 4 +- Ink Canvas/MainWindow_cs/MW_PPT.cs | 163 ++++++------------ 4 files changed, 72 insertions(+), 117 deletions(-) diff --git a/Ink Canvas/Helpers/PPTInkManager.cs b/Ink Canvas/Helpers/PPTInkManager.cs index b450aae8..5249d39e 100644 --- a/Ink Canvas/Helpers/PPTInkManager.cs +++ b/Ink Canvas/Helpers/PPTInkManager.cs @@ -273,7 +273,9 @@ namespace Ink_Canvas.Helpers /// /// 保存所有墨迹到文件 /// - public void SaveAllStrokesToFile(Presentation presentation) + /// 演示文稿对象 + /// 当前播放的页码,如果提供则使用此值保存位置,否则使用_lockedSlideIndex + public void SaveAllStrokesToFile(Presentation presentation, int currentSlideIndex = -1) { if (!IsAutoSaveEnabled || string.IsNullOrEmpty(AutoSaveLocation) || presentation == null) return; @@ -290,7 +292,19 @@ namespace Ink_Canvas.Helpers // 保存位置信息 try { - File.WriteAllText(Path.Combine(folderPath, "Position"), _lockedSlideIndex.ToString()); + // 优先使用传入的当前页码,否则使用锁定的页码 + int positionToSave = currentSlideIndex > 0 ? currentSlideIndex : _lockedSlideIndex; + // 如果都没有有效值,尝试使用最后切换的页码 + if (positionToSave <= 0 && _lastSwitchSlideIndex > 0) + { + positionToSave = _lastSwitchSlideIndex; + } + + if (positionToSave > 0) + { + File.WriteAllText(Path.Combine(folderPath, "Position"), positionToSave.ToString()); + LogHelper.WriteLogToFile($"已保存PPT播放位置: {positionToSave}", LogHelper.LogType.Trace); + } } catch (Exception ex) { diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index cf26ee0d..0dfdea6a 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -3220,14 +3220,14 @@ - - + diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index 57adf0dd..59058272 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -2996,10 +2996,10 @@ namespace Ink_Canvas ClearStrokes(true); RestoreStrokes(true); - // 新增:在屏幕模式下恢复基础浮动栏的显示 + // 在屏幕模式下恢复基础浮动栏的显示 ViewboxFloatingBar.Visibility = Visibility.Visible; - // 新增:退出白板时自动收纳功能 - 等待浮动栏完全展开后再收纳 + // 退出白板时自动收纳功能 - 等待浮动栏完全展开后再收纳 if (Settings.Automation.IsAutoFoldWhenExitWhiteboard && !isFloatingBarFolded) { // 使用异步延迟,等待浮动栏展开动画完成后再收纳 diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index 2906d5b1..4e5d1c8d 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -77,7 +77,6 @@ namespace Ink_Canvas #endregion #region PPT State Management - private bool wasFloatingBarFoldedWhenEnterSlideShow; private bool isEnteredSlideShowEndEvent; private bool isPresentationHaveBlackSpace; @@ -94,6 +93,9 @@ namespace Ink_Canvas // 上次播放位置相关字段 private int _lastPlaybackPage = 0; private bool _shouldNavigateToLastPage = false; + + // 当前播放页码跟踪 + private int _currentSlideShowPosition = 0; // 页面切换防抖机制 private DateTime _lastSlideSwitchTime = DateTime.MinValue; @@ -612,9 +614,6 @@ namespace Ink_Canvas { try { - // 始终记录进入放映时浮动栏收纳状态,用于退出时恢复 - wasFloatingBarFoldedWhenEnterSlideShow = isFloatingBarFolded; - if (Settings.Automation.IsAutoFoldInPPTSlideShow) { if (!isFloatingBarFolded) @@ -641,12 +640,16 @@ namespace Ink_Canvas activePresentation = wn.Presentation; currentSlide = wn.View.CurrentShowPosition; totalSlides = activePresentation.Slides.Count; + // 初始化当前播放页码跟踪 + _currentSlideShowPosition = currentSlide; } else { activePresentation = _pptManager?.GetCurrentActivePresentation(); currentSlide = _pptManager?.GetCurrentSlideNumber() ?? 0; totalSlides = _pptManager?.SlidesCount ?? 0; + // 初始化当前播放页码跟踪 + _currentSlideShowPosition = currentSlide; } if (activePresentation != null) @@ -796,6 +799,9 @@ namespace Ink_Canvas var activePresentation = wn.Presentation; var totalSlides = activePresentation.Slides.Count; + // 更新当前播放页码 + _currentSlideShowPosition = currentSlide; + // 使用防抖机制处理页面切换 HandleSlideSwitchWithDebounce(currentSlide, totalSlides); @@ -811,39 +817,39 @@ namespace Ink_Canvas { try { - if (Settings.Automation.IsAutoFoldAfterPPTSlideShow) + // PPT退出时自动收纳浮动栏 + if (!isFloatingBarFolded) { - if (wasFloatingBarFoldedWhenEnterSlideShow) - { - if (!isFloatingBarFolded) FoldFloatingBar_MouseUp(new object(), null); - } - else - { - if (isFloatingBarFolded) await UnFoldFloatingBar(new object()); - } - } - else - { - if (Settings.Automation.IsAutoFoldInPPTSlideShow) - { - if (isFloatingBarFolded) - { - await UnFoldFloatingBar(new object()); - } - } - else - { - if (isFloatingBarFolded) - { - await UnFoldFloatingBar(new object()); - } - } + FoldFloatingBar_MouseUp(new object(), null); } if (isEnteredSlideShowEndEvent) return; isEnteredSlideShowEndEvent = true; - _singlePPTInkManager?.SaveAllStrokesToFile(pres); + // 获取当前播放页码,优先使用跟踪的页码,否则尝试从PPT管理器获取 + int currentPage = _currentSlideShowPosition; + if (currentPage <= 0) + { + try + { + currentPage = _pptManager?.GetCurrentSlideNumber() ?? 0; + } + catch + { + // 如果无法获取,尝试从演示文稿的SlideShowWindow获取 + try + { + if (pres.SlideShowWindow != null && pres.SlideShowWindow.View != null) + { + currentPage = pres.SlideShowWindow.View.CurrentShowPosition; + } + } + catch { } + } + } + + // 保存墨迹和位置信息 + _singlePPTInkManager?.SaveAllStrokesToFile(pres, currentPage); await Application.Current.Dispatcher.InvokeAsync(() => { @@ -917,7 +923,7 @@ namespace Ink_Canvas await Application.Current.Dispatcher.InvokeAsync(() => { PureViewboxFloatingBarMarginAnimationInDesktopMode(); - ViewboxFloatingBarMarginAnimation(100, true); + ViewboxFloatingBarMarginAnimation(-60); }); } catch (Exception ex) @@ -1140,9 +1146,6 @@ namespace Ink_Canvas { try { - // 重置进入PPT时的浮动栏收纳状态记录 - wasFloatingBarFoldedWhenEnterSlideShow = false; - // 重置PPT放映结束事件标志 isEnteredSlideShowEndEvent = false; @@ -1152,6 +1155,9 @@ namespace Ink_Canvas // 重置上次播放位置相关字段 _lastPlaybackPage = 0; _shouldNavigateToLastPage = false; + + // 重置当前播放页码跟踪 + _currentSlideShowPosition = 0; // 重置页面切换防抖机制 _lastSlideSwitchTime = DateTime.MinValue; @@ -1609,7 +1615,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile("手动更新放映结束UI状态", LogHelper.LogType.Trace); }); - // 手动处理收纳状态恢复,因为OnPPTSlideShowEnd事件可能未触发 + // 手动处理自动收纳,因为OnPPTSlideShowEnd事件可能未触发 await HandleManualSlideShowEnd(); } @@ -1617,28 +1623,8 @@ namespace Ink_Canvas SetCurrentToolMode(InkCanvasEditingMode.None); await Task.Delay(150); - if (Settings.Automation.IsAutoFoldAfterPPTSlideShow) - { - if (wasFloatingBarFoldedWhenEnterSlideShow) - { - ViewboxFloatingBarMarginAnimation(-60); - } - else - { - ViewboxFloatingBarMarginAnimation(100, true); - } - } - else - { - if (isFloatingBarFolded) - { - ViewboxFloatingBarMarginAnimation(-60); - } - else - { - ViewboxFloatingBarMarginAnimation(100, true); - } - } + // PPT退出时自动收纳,使用收纳状态的边距动画 + ViewboxFloatingBarMarginAnimation(-60); } catch (Exception ex) { @@ -1651,76 +1637,31 @@ namespace Ink_Canvas _pptUIManager?.UpdateSidebarExitButtons(false); }); - // 异常情况下也手动处理收纳状态恢复 + // 异常情况下也手动处理自动收纳 await HandleManualSlideShowEnd(); - // 异常情况下也要根据设置决定浮动栏边距 + // 异常情况下也要自动收纳,使用收纳状态的边距动画 await Task.Delay(150); - if (Settings.Automation.IsAutoFoldAfterPPTSlideShow) - { - if (wasFloatingBarFoldedWhenEnterSlideShow) - { - ViewboxFloatingBarMarginAnimation(-60); - } - else - { - ViewboxFloatingBarMarginAnimation(100, true); - } - } - else - { - if (isFloatingBarFolded) - { - ViewboxFloatingBarMarginAnimation(-60); - } - else - { - ViewboxFloatingBarMarginAnimation(100, true); - } - } + ViewboxFloatingBarMarginAnimation(-60); } } /// - /// 手动处理PPT放映结束时的收纳状态恢复 + /// 手动处理PPT放映结束时的自动收纳 /// private async Task HandleManualSlideShowEnd() { try { - if (Settings.Automation.IsAutoFoldAfterPPTSlideShow) + // PPT退出时自动收纳浮动栏 + if (!isFloatingBarFolded) { - if (wasFloatingBarFoldedWhenEnterSlideShow) - { - if (!isFloatingBarFolded) FoldFloatingBar_MouseUp(new object(), null); - } - else - { - if (isFloatingBarFolded) await UnFoldFloatingBar(new object()); - } - } - else - { - if (Settings.Automation.IsAutoFoldInPPTSlideShow) - { - if (isFloatingBarFolded) - { - await UnFoldFloatingBar(new object()); - } - } - else - { - // 如果两个功能都关闭,确保浮动栏展开 - if (isFloatingBarFolded) - { - await UnFoldFloatingBar(new object()); - } - } + FoldFloatingBar_MouseUp(new object(), null); } } catch (Exception ex) { - LogHelper.WriteLogToFile($"手动处理PPT放映结束收纳状态恢复失败: {ex}", LogHelper.LogType.Error); + LogHelper.WriteLogToFile($"手动处理PPT放映结束自动收纳失败: {ex}", LogHelper.LogType.Error); } }