Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复议题 #128 #144

Merged
merged 8 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 61 additions & 36 deletions Ink Canvas/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,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 @@ -2400,30 +2402,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 @@ -2444,7 +2447,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 @@ -2492,7 +2495,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 @@ -2501,6 +2504,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 @@ -2561,21 +2565,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 @@ -2666,6 +2673,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 @@ -2681,7 +2689,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 @@ -2798,6 +2821,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 @@ -2903,6 +2927,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
Loading