improve:PPT墨迹管理
This commit is contained in:
@@ -97,13 +97,6 @@ namespace Ink_Canvas
|
|||||||
// 当前播放页码跟踪
|
// 当前播放页码跟踪
|
||||||
private int _currentSlideShowPosition = 0;
|
private int _currentSlideShowPosition = 0;
|
||||||
|
|
||||||
// 页面切换防抖机制
|
|
||||||
private DateTime _lastSlideSwitchTime = DateTime.MinValue;
|
|
||||||
private int _pendingSlideIndex = -1;
|
|
||||||
private int _pendingPreviousSlideIndex = -1;
|
|
||||||
private System.Timers.Timer _slideSwitchDebounceTimer;
|
|
||||||
private const int SlideSwitchDebounceMs = 150; // 防抖延迟150毫秒
|
|
||||||
|
|
||||||
private DispatcherTimer _exitPPTModeAfterDisconnectTimer;
|
private DispatcherTimer _exitPPTModeAfterDisconnectTimer;
|
||||||
private const int ExitPPTModeAfterDisconnectDelayMs = 1200;
|
private const int ExitPPTModeAfterDisconnectDelayMs = 1200;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -889,23 +882,32 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.InvokeAsync(() =>
|
if (wn?.View == null || wn.Presentation == null) return;
|
||||||
|
|
||||||
|
int currentSlide = wn.View.CurrentShowPosition;
|
||||||
|
int totalSlides = wn.Presentation.Slides.Count;
|
||||||
|
|
||||||
|
if (currentSlide == _currentSlideShowPosition) return;
|
||||||
|
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
if (wn?.View == null || wn.Presentation == null)
|
int prev = _currentSlideShowPosition;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentSlide = wn.View.CurrentShowPosition;
|
if (inkCanvas.Strokes.Count > 0 && prev > 0 && prev != currentSlide)
|
||||||
var activePresentation = wn.Presentation;
|
_singlePPTInkManager?.SaveCurrentSlideStrokes(prev, inkCanvas.Strokes);
|
||||||
var totalSlides = activePresentation.Slides.Count;
|
|
||||||
|
|
||||||
int previousSlide = _currentSlideShowPosition;
|
ClearStrokes(true);
|
||||||
_currentSlideShowPosition = currentSlide;
|
timeMachine.ClearStrokeHistory();
|
||||||
|
|
||||||
HandleSlideSwitchWithDebounce(previousSlide, currentSlide, totalSlides);
|
StrokeCollection newStrokes = _singlePPTInkManager?.LoadSlideStrokes(currentSlide);
|
||||||
|
if (newStrokes != null && newStrokes.Count > 0)
|
||||||
|
inkCanvas.Strokes.Add(newStrokes);
|
||||||
|
|
||||||
|
_singlePPTInkManager?.LockInkForSlide(currentSlide);
|
||||||
|
_pptUIManager?.UpdateCurrentSlideNumber(currentSlide, totalSlides);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_currentSlideShowPosition = currentSlide;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -1279,9 +1281,6 @@ namespace Ink_Canvas
|
|||||||
// 重置当前播放页码跟踪
|
// 重置当前播放页码跟踪
|
||||||
_currentSlideShowPosition = 0;
|
_currentSlideShowPosition = 0;
|
||||||
|
|
||||||
// 重置页面切换防抖机制
|
|
||||||
_lastSlideSwitchTime = DateTime.MinValue;
|
|
||||||
_pendingSlideIndex = -1;
|
|
||||||
|
|
||||||
LogHelper.WriteLogToFile("PPT状态变量已重置", LogHelper.LogType.Trace);
|
LogHelper.WriteLogToFile("PPT状态变量已重置", LogHelper.LogType.Trace);
|
||||||
}
|
}
|
||||||
@@ -1291,82 +1290,6 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 使用防抖机制处理页面切换
|
|
||||||
/// </summary>
|
|
||||||
private void HandleSlideSwitchWithDebounce(int previousSlideIndex, int newSlideIndex, int totalSlides)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var now = DateTime.Now;
|
|
||||||
|
|
||||||
if (now - _lastSlideSwitchTime < TimeSpan.FromMilliseconds(SlideSwitchDebounceMs))
|
|
||||||
{
|
|
||||||
_pendingSlideIndex = newSlideIndex;
|
|
||||||
_pendingPreviousSlideIndex = previousSlideIndex;
|
|
||||||
|
|
||||||
_slideSwitchDebounceTimer?.Stop();
|
|
||||||
_slideSwitchDebounceTimer = new System.Timers.Timer(SlideSwitchDebounceMs);
|
|
||||||
_slideSwitchDebounceTimer.Elapsed += (sender, e) =>
|
|
||||||
{
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
if (_pendingSlideIndex > 0)
|
|
||||||
{
|
|
||||||
SwitchSlideInk(_pendingPreviousSlideIndex, _pendingSlideIndex);
|
|
||||||
_pptUIManager?.UpdateCurrentSlideNumber(_pendingSlideIndex, totalSlides);
|
|
||||||
_pendingSlideIndex = -1;
|
|
||||||
_pendingPreviousSlideIndex = -1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
_slideSwitchDebounceTimer?.Stop();
|
|
||||||
};
|
|
||||||
_slideSwitchDebounceTimer.Start();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SwitchSlideInk(previousSlideIndex, newSlideIndex);
|
|
||||||
_pptUIManager?.UpdateCurrentSlideNumber(newSlideIndex, totalSlides);
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastSlideSwitchTime = now;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LogHelper.WriteLogToFile($"处理页面切换防抖失败: {ex}", LogHelper.LogType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SwitchSlideInk(int previousSlideIndex, int newSlideIndex)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_pptManager?.IsConnected != true || _pptManager?.IsInSlideShow != true) return;
|
|
||||||
if (newSlideIndex <= 0)
|
|
||||||
{
|
|
||||||
LogHelper.WriteLogToFile($"无效的新页面索引: {newSlideIndex},跳过页面切换", LogHelper.LogType.Warning);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 先保存上一页墨迹
|
|
||||||
if (inkCanvas.Strokes.Count > 0 && previousSlideIndex > 0 && previousSlideIndex != newSlideIndex)
|
|
||||||
{
|
|
||||||
if (_singlePPTInkManager?.CanWriteInk(previousSlideIndex) == true)
|
|
||||||
_singlePPTInkManager?.SaveCurrentSlideStrokes(previousSlideIndex, inkCanvas.Strokes);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClearStrokes(true);
|
|
||||||
timeMachine.ClearStrokeHistory();
|
|
||||||
StrokeCollection newStrokes = _singlePPTInkManager?.SwitchToSlide(newSlideIndex, null);
|
|
||||||
if (newStrokes != null && newStrokes.Count > 0)
|
|
||||||
inkCanvas.Strokes.Add(newStrokes);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LogHelper.WriteLogToFile($"切换页面墨迹失败: {ex}", LogHelper.LogType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetFileHash(string filePath)
|
private string GetFileHash(string filePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user