improve:白板翻页性能
This commit is contained in:
@@ -189,6 +189,18 @@ namespace Ink_Canvas
|
||||
});
|
||||
}
|
||||
|
||||
private static HashSet<UIElement> CollectRemovedElementsFromHistory(TimeMachineHistory[] history)
|
||||
{
|
||||
var set = new HashSet<UIElement>();
|
||||
if (history == null) return set;
|
||||
foreach (var h in history)
|
||||
{
|
||||
if (h.CommitType == TimeMachineHistoryType.ElementInsert && h.StrokeHasBeenCleared && h.InsertedElement != null)
|
||||
set.Add(h.InsertedElement);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复指定白板页面的墨迹和元素信息
|
||||
/// </summary>
|
||||
@@ -234,16 +246,15 @@ namespace Ink_Canvas
|
||||
if (isBackupMain)
|
||||
{
|
||||
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[0]);
|
||||
foreach (var item in TimeMachineHistories[0]) ApplyHistoryToCanvas(item);
|
||||
// 恢复多指书写模式状态
|
||||
var removed0 = CollectRemovedElementsFromHistory(TimeMachineHistories[0]);
|
||||
foreach (var item in TimeMachineHistories[0]) ApplyHistoryToCanvas(item, null, removed0);
|
||||
RestoreMultiTouchModeState(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[CurrentWhiteboardIndex]);
|
||||
// 通过时间机器历史恢复所有内容(墨迹和图片)
|
||||
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) ApplyHistoryToCanvas(item);
|
||||
// 恢复多指书写模式状态
|
||||
var removed = CollectRemovedElementsFromHistory(TimeMachineHistories[CurrentWhiteboardIndex]);
|
||||
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) ApplyHistoryToCanvas(item, null, removed);
|
||||
RestoreMultiTouchModeState(CurrentWhiteboardIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,8 @@ namespace Ink_Canvas
|
||||
/// 5. Clear: 处理清除画布操作
|
||||
/// 6. ElementInsert: 处理元素插入操作
|
||||
/// </remarks>
|
||||
private void ApplyHistoryToCanvas(TimeMachineHistory item, InkCanvas applyCanvas = null)
|
||||
/// <param name="elementsRemovedInThisPage"></param>
|
||||
private void ApplyHistoryToCanvas(TimeMachineHistory item, InkCanvas applyCanvas = null, HashSet<UIElement> elementsRemovedInThisPage = null)
|
||||
{
|
||||
_currentCommitType = CommitReason.CodeInput;
|
||||
var canvas = inkCanvas;
|
||||
@@ -227,18 +228,19 @@ namespace Ink_Canvas
|
||||
}
|
||||
else if (item.CommitType == TimeMachineHistoryType.ElementInsert)
|
||||
{
|
||||
// 使用传入的canvas参数,而不是总是使用inkCanvas
|
||||
var targetCanvas = canvas ?? inkCanvas;
|
||||
|
||||
if (item.StrokeHasBeenCleared)
|
||||
{
|
||||
// Undo: 移除元素
|
||||
if (elementsRemovedInThisPage != null)
|
||||
return;
|
||||
if (item.InsertedElement != null && targetCanvas.Children.Contains(item.InsertedElement))
|
||||
targetCanvas.Children.Remove(item.InsertedElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Redo: 添加元素
|
||||
if (elementsRemovedInThisPage != null && item.InsertedElement != null && elementsRemovedInThisPage.Contains(item.InsertedElement))
|
||||
return;
|
||||
if (item.InsertedElement != null && !targetCanvas.Children.Contains(item.InsertedElement))
|
||||
{
|
||||
targetCanvas.Children.Add(item.InsertedElement);
|
||||
|
||||
Reference in New Issue
Block a user