[BugFix] 修复导入墨迹后无法撤销的Bug

This commit is contained in:
Raspberry-Monster 2023-05-09 17:53:00 +08:00
parent c7f1912d0b
commit 5109da76a8
No known key found for this signature in database
GPG Key ID: 9A0D725BB122D507

View File

@ -7060,17 +7060,30 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile(string.Format("Strokes Insert: Name: {0}", openFileDialog.FileName), LogHelper.LogType.Event);
try
{
var fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read);
inkCanvas.Strokes = new StrokeCollection(fs);
LogHelper.NewLog(string.Format("Strokes Insert: Strokes Count: {0}", inkCanvas.Strokes.Count.ToString()));
if (inkCanvas.Strokes.Count == 0)
var fileStreamHasNoStroke = false;
using (var fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
var strokes = new StrokeCollection(fs);
fileStreamHasNoStroke = strokes.Count == 0;
if (!fileStreamHasNoStroke)
{
fs.Close();
var memoryStream = new MemoryStream(File.ReadAllBytes(openFileDialog.FileName));
memoryStream.Position = 0;
ClearStrokes(true);
inkCanvas.Strokes.Add(new StrokeCollection(memoryStream));
LogHelper.NewLog(string.Format("Strokes Insert (2): Strokes Count: {0}", inkCanvas.Strokes.Count.ToString()));
timeMachine.ClearStrokeHistory();
inkCanvas.Strokes.Add(strokes);
LogHelper.NewLog(string.Format("Strokes Insert: Strokes Count: {0}", inkCanvas.Strokes.Count.ToString()));
}
}
if (fileStreamHasNoStroke)
{
using (var ms = new MemoryStream(File.ReadAllBytes(openFileDialog.FileName)))
{
ms.Seek(0, SeekOrigin.Begin);
var strokes = new StrokeCollection(ms);
ClearStrokes(true);
timeMachine.ClearStrokeHistory();
inkCanvas.Strokes.Add(strokes);
LogHelper.NewLog(string.Format("Strokes Insert (2): Strokes Count: {0}", strokes.Count.ToString()));
}
}
if (inkCanvas.Visibility != Visibility.Visible)