improve:PPT联动

This commit is contained in:
2026-02-12 21:53:37 +08:00
parent 80decf5656
commit f0b31c15a6
+141 -21
View File
@@ -545,9 +545,44 @@ namespace Ink_Canvas
{
try
{
dynamic presObj = pres;
Application.Current.Dispatcher.InvokeAsync(() =>
{
try
{
dynamic activePresentation = null;
try
{
activePresentation = _pptManager?.GetCurrentActivePresentation();
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
LogHelper.WriteLogToFile(
$"处理演示文稿打开事件时访问 PowerPoint 失败: {comEx.Message} (HR: 0x{hr:X8})",
LogHelper.LogType.Warning);
activePresentation = null;
}
catch (InvalidComObjectException invalidEx)
{
LogHelper.WriteLogToFile(
$"处理演示文稿打开事件时演示文稿对象无效: {invalidEx}",
LogHelper.LogType.Warning);
activePresentation = null;
}
catch (Exception exInner)
{
LogHelper.WriteLogToFile(
$"处理演示文稿打开事件时获取 PowerPoint 信息失败: {exInner}",
LogHelper.LogType.Error);
activePresentation = null;
}
if (activePresentation == null)
{
return;
}
// 在初始化墨迹管理器之前,先清理画布上的所有墨迹
ClearStrokes(true);
@@ -557,26 +592,75 @@ namespace Ink_Canvas
TimeMachineHistories[0] = null;
}
_singlePPTInkManager?.InitializePresentation(presObj as Presentation);
try
{
_singlePPTInkManager?.InitializePresentation(activePresentation as Presentation);
}
catch (Exception exInit)
{
LogHelper.WriteLogToFile($"初始化PPT墨迹管理器失败: {exInit}", LogHelper.LogType.Error);
}
// 处理跳转到首页或上次播放页的逻辑
HandlePresentationOpenNavigation(presObj);
try
{
HandlePresentationOpenNavigation(activePresentation);
}
catch (Exception exNav)
{
LogHelper.WriteLogToFile($"处理演示文稿导航失败: {exNav}", LogHelper.LogType.Error);
}
// 检查隐藏幻灯片
if (Settings.PowerPointSettings.IsNotifyHiddenPage)
{
CheckAndNotifyHiddenSlides(presObj);
try
{
CheckAndNotifyHiddenSlides(activePresentation);
}
catch (Exception exHidden)
{
LogHelper.WriteLogToFile($"检查隐藏幻灯片失败: {exHidden}", LogHelper.LogType.Error);
}
}
// 检查自动播放设置
if (Settings.PowerPointSettings.IsNotifyAutoPlayPresentation)
{
CheckAndNotifyAutoPlaySettings(presObj);
try
{
CheckAndNotifyAutoPlaySettings(activePresentation);
}
catch (Exception exAuto)
{
LogHelper.WriteLogToFile($"检查自动播放设置失败: {exAuto}", LogHelper.LogType.Error);
}
}
_pptUIManager?.UpdateConnectionStatus(true);
LogHelper.WriteLogToFile($"已打开新演示文稿: {presObj.Name},墨迹状态已清理", LogHelper.LogType.Event);
try
{
string presName = string.Empty;
try
{
presName = activePresentation.Name;
}
catch
{
presName = "<unknown>";
}
LogHelper.WriteLogToFile($"已打开新演示文稿: {presName},墨迹状态已清理", LogHelper.LogType.Event);
}
catch
{
}
}
catch (Exception exCallback)
{
LogHelper.WriteLogToFile($"处理演示文稿打开事件失败(调度回调): {exCallback}", LogHelper.LogType.Error);
}
});
}
catch (Exception ex)
@@ -658,22 +742,36 @@ namespace Ink_Canvas
int currentSlide = 0;
int totalSlides = 0;
if (wnObj?.View != null && wnObj.Presentation != null)
{
activePresentation = wnObj.Presentation;
currentSlide = wnObj.View.CurrentShowPosition;
totalSlides = activePresentation.Slides.Count;
// 初始化当前播放页码跟踪
_currentSlideShowPosition = currentSlide;
}
else
try
{
activePresentation = _pptManager?.GetCurrentActivePresentation();
currentSlide = _pptManager?.GetCurrentSlideNumber() ?? 0;
totalSlides = _pptManager?.SlidesCount ?? 0;
// 初始化当前播放页码跟踪
_currentSlideShowPosition = currentSlide;
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
LogHelper.WriteLogToFile(
$"处理幻灯片放映开始事件时访问 PowerPoint 失败: {comEx.Message} (HR: 0x{hr:X8})",
LogHelper.LogType.Warning);
activePresentation = null;
currentSlide = 0;
totalSlides = 0;
_currentSlideShowPosition = 0;
}
catch (Exception exInner)
{
LogHelper.WriteLogToFile(
$"处理幻灯片放映开始事件时获取 PowerPoint 信息失败: {exInner}",
LogHelper.LogType.Error);
activePresentation = null;
currentSlide = 0;
totalSlides = 0;
_currentSlideShowPosition = 0;
}
if (activePresentation != null)
{
@@ -814,15 +912,37 @@ namespace Ink_Canvas
dynamic wnObj = wn;
Application.Current.Dispatcher.InvokeAsync(() =>
{
if (wnObj?.View == null || wnObj.Presentation == null)
int currentSlide = 0;
int totalSlides = 0;
try
{
currentSlide = _pptManager?.GetCurrentSlideNumber() ?? 0;
totalSlides = _pptManager?.SlidesCount ?? 0;
}
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
LogHelper.WriteLogToFile(
$"处理幻灯片切换事件时访问 PowerPoint 失败: {comEx.Message} (HR: 0x{hr:X8})",
LogHelper.LogType.Warning);
currentSlide = 0;
totalSlides = 0;
}
catch (Exception exInner)
{
LogHelper.WriteLogToFile(
$"处理幻灯片切换事件时获取 PowerPoint 信息失败: {exInner}",
LogHelper.LogType.Error);
currentSlide = 0;
totalSlides = 0;
}
if (currentSlide <= 0 || totalSlides <= 0)
{
return;
}
var currentSlide = wnObj.View.CurrentShowPosition;
dynamic activePresentation = wnObj.Presentation;
var totalSlides = activePresentation.Slides.Count;
// 更新当前播放页码
_currentSlideShowPosition = currentSlide;