Skip to content

Commit

Permalink
修复议题 #128 (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
NetheriteBowl authored Aug 31, 2024
1 parent ebd8430 commit 504ca5a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 37 deletions.
97 changes: 61 additions & 36 deletions Ink Canvas/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,8 @@ private void ToggleSwitchSupportWPS_Toggled(object sender, RoutedEventArgs e)

public static bool IsShowingRestoreHiddenSlidesWindow = false;

public static bool IsNotifyPreviousPageWindowShown = false;

private void TimerCheckPPT_Elapsed(object sender, ElapsedEventArgs e)
{
if (IsShowingRestoreHiddenSlidesWindow) return;
Expand Down Expand Up @@ -2420,30 +2422,31 @@ private void TimerCheckPPT_Elapsed(object sender, ElapsedEventArgs e)
// 跳转到上次播放页
if (Settings.PowerPointSettings.IsNotifyPreviousPage)
Application.Current.Dispatcher.BeginInvoke(() =>
{
string defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\Ink Canvas Strokes\Auto Saved\Presentations\";
string folderPath = defaultFolderPath + presentation.Name + "_" + presentation.Slides.Count;
if (File.Exists(folderPath + "/Position"))
{
if (int.TryParse(File.ReadAllText(folderPath + "/Position"), out var page))
string defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\Ink Canvas Strokes\Auto Saved\Presentations\";
string folderPath = defaultFolderPath + presentation.Name + "_" + presentation.Slides.Count;
if (File.Exists(folderPath + "/Position") & !IsNotifyPreviousPageWindowShown) //判断是否已存在NotifyPreviousPage窗口
{
if (page <= 0) return;
new YesOrNoNotificationWindow($"上次播放到了第 {page} 页, 是否立即跳转", () =>
if (int.TryParse(File.ReadAllText(folderPath + "/Position"), out var page))
{
if (pptApplication.SlideShowWindows.Count >= 1)
IsNotifyPreviousPageWindowShown= true;
if (page <= 0) return;
new YesOrNoNotificationWindow($"上次播放到了第 {page} 页, 是否立即跳转", () =>
{
// 如果已经播放了的话, 跳转
presentation.SlideShowWindow.View.GotoSlide(page);
}
else
{
presentation.Windows[1].View.GotoSlide(page);
}
}).ShowDialog();
if (pptApplication.SlideShowWindows.Count >= 1)
{
// 如果已经播放了的话, 跳转
presentation.SlideShowWindow.View.GotoSlide(page);
}
else
{
presentation.Windows[1].View.GotoSlide(page);
}
}).ShowDialog();
}
}
}
}, DispatcherPriority.Normal);
}, DispatcherPriority.Normal);


//检查是否有隐藏幻灯片
Expand All @@ -2464,7 +2467,7 @@ private void TimerCheckPPT_Elapsed(object sender, ElapsedEventArgs e)
if (isHaveHiddenSlide && !IsShowingRestoreHiddenSlidesWindow)
{
IsShowingRestoreHiddenSlidesWindow = true;
new YesOrNoNotificationWindow("检测到此演示文档中包含隐藏的幻灯片,是否取消隐藏?",
new YesOrNoNotificationWindow("检测到此演示文稿包含隐藏的幻灯片,是否取消隐藏?",
() =>
{
foreach (Slide slide in slides)
Expand Down Expand Up @@ -2512,7 +2515,7 @@ private void PptApplication_PresentationClose(Presentation Pres)
timerCheckPPT.Start();
Application.Current.Dispatcher.Invoke(() =>
{
BtnPPTSlideShow.Visibility = Visibility.Collapsed;
//BtnPPTSlideShow.Visibility = Visibility.Collapsed;
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
});
}
Expand All @@ -2521,6 +2524,7 @@ private void PptApplication_PresentationClose(Presentation Pres)


private string pptName = null;
int currentShowPosition = -1;
//bool isButtonBackgroundTransparent = true; //此变量仅用于保存用于幻灯片放映时的优化
private void PptApplication_SlideShowBegin(SlideShowWindow Wn)
{
Expand Down Expand Up @@ -2581,21 +2585,24 @@ private void PptApplication_SlideShowBegin(SlideShowWindow Wn)
int count = 0;
foreach (FileInfo file in files)
{
int i = -1;
try
{
i = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file.Name));
//var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
//MemoryStream ms = new MemoryStream(File.ReadAllBytes(file.FullName));
//new StrokeCollection(fs).Save(ms);
//ms.Position = 0;
memoryStreams[i] = new MemoryStream(File.ReadAllBytes(file.FullName));
memoryStreams[i].Position = 0;
count++;
}
catch (Exception ex)
if (file.Name != "Position")
{
LogHelper.WriteLogToFile(string.Format("Failed to load strokes on Slide {0}\n{1}", i, ex.ToString()), LogHelper.LogType.Error);
int i = -1;
try
{
i = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file.Name));
//var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
//MemoryStream ms = new MemoryStream(File.ReadAllBytes(file.FullName));
//new StrokeCollection(fs).Save(ms);
//ms.Position = 0;
memoryStreams[i] = new MemoryStream(File.ReadAllBytes(file.FullName));
memoryStreams[i].Position = 0;
count++;
}
catch (Exception ex)
{
LogHelper.WriteLogToFile(string.Format("Failed to load strokes on Slide {0}\n{1}", i, ex.ToString()), LogHelper.LogType.Error);
}
}
}
LogHelper.WriteLogToFile(string.Format("Loaded {0} saved strokes", count.ToString()));
Expand Down Expand Up @@ -2686,6 +2693,7 @@ private void PptApplication_SlideShowBegin(SlideShowWindow Wn)
bool isEnteredSlideShowEndEvent = false; //防止重复调用本函数导致墨迹保存失效
private void PptApplication_SlideShowEnd(Presentation Pres)
{
IsNotifyPreviousPageWindowShown = false;
LogHelper.WriteLogToFile(string.Format("PowerPoint Slide Show End"), LogHelper.LogType.Event);
if (isEnteredSlideShowEndEvent)
{
Expand All @@ -2701,7 +2709,22 @@ private void PptApplication_SlideShowEnd(Presentation Pres)
{
Directory.CreateDirectory(folderPath);
}
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
try
{
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
}
catch { }
Application.Current.Dispatcher.Invoke(() =>
{
try
{
MemoryStream ms = new MemoryStream();
inkCanvas.Strokes.Save(ms);
ms.Position = 0;
memoryStreams[currentShowPosition] = ms;
}
catch { }
});
for (int i = 1; i <= Pres.Slides.Count; i++)
{
if (memoryStreams[i] != null)
Expand Down Expand Up @@ -2818,6 +2841,7 @@ private void PptApplication_SlideShowNextSlide(SlideShowWindow Wn)
{
inkCanvas.Strokes.Add(new StrokeCollection(memoryStreams[Wn.View.CurrentShowPosition]));
}
currentShowPosition = Wn.View.CurrentShowPosition;
}
catch
{ }
Expand Down Expand Up @@ -2923,6 +2947,7 @@ private void BtnPPTSlideShowEnd_Click(object sender, RoutedEventArgs e)
ms.Position = 0;
memoryStreams[pptApplication.SlideShowWindows[1].View.CurrentShowPosition] = ms;
timeMachine.ClearStrokeHistory();
IsNotifyPreviousPageWindowShown = false;
}
catch { }
});
Expand Down
2 changes: 1 addition & 1 deletion Ink Canvas/YesOrNoNotificationWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Ink_Canvas" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
mc:Ignorable="d" Topmost="True" WindowStartupLocation="CenterScreen" ui:WindowHelper.UseModernWindowStyle="True"
ResizeMode="NoResize" Closed="Window_Closed" ui:ThemeManager.RequestedTheme="Light"
Title="演示文档设置 - Ink Canvas 画板" Height="160" Width="450" FontFamily="Microsoft YaHei UI">
Title="提示 - Ink Canvas 画板" Height="160" Width="450" FontFamily="Microsoft YaHei UI">
<Grid>
<Grid Margin="10">
<Grid.RowDefinitions>
Expand Down

0 comments on commit 504ca5a

Please sign in to comment.