fix:issue #93
This commit is contained in:
@@ -195,5 +195,18 @@ namespace Ink_Canvas.Helpers
|
||||
_currentIndex = _currentStrokeHistory.Count - 1;
|
||||
NotifyUndoRedoState();
|
||||
}
|
||||
|
||||
public void CommitElementRemoveHistory(UIElement element)
|
||||
{
|
||||
if (_currentIndex + 1 < _currentStrokeHistory.Count)
|
||||
{
|
||||
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex);
|
||||
}
|
||||
var history = new TimeMachineHistory(element, TimeMachineHistoryType.ElementInsert);
|
||||
history.StrokeHasBeenCleared = true; // 标记为已清除
|
||||
_currentStrokeHistory.Add(history);
|
||||
_currentIndex = _currentStrokeHistory.Count - 1;
|
||||
NotifyUndoRedoState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,21 @@ namespace Ink_Canvas {
|
||||
private void ClearStrokes(bool isErasedByCode) {
|
||||
_currentCommitType = CommitReason.ClearingCanvas;
|
||||
if (isErasedByCode) _currentCommitType = CommitReason.CodeInput;
|
||||
|
||||
// 取消任何UI元素的选择,隐藏拉伸控件
|
||||
DeselectUIElement();
|
||||
|
||||
// 记录要清除的图片元素到时间机器历史中
|
||||
var elementsToRemove = new List<UIElement>();
|
||||
foreach (UIElement element in inkCanvas.Children) {
|
||||
elementsToRemove.Add(element);
|
||||
}
|
||||
|
||||
// 为每个图片元素创建清除历史记录
|
||||
foreach (var element in elementsToRemove) {
|
||||
timeMachine.CommitElementRemoveHistory(element);
|
||||
}
|
||||
|
||||
inkCanvas.Strokes.Clear();
|
||||
// 清除所有子元素(包括图片)
|
||||
inkCanvas.Children.Clear();
|
||||
@@ -47,7 +62,13 @@ namespace Ink_Canvas {
|
||||
// 恢复每页白板图片信息
|
||||
private void RestoreStrokes(bool isBackupMain = false) {
|
||||
try {
|
||||
if (TimeMachineHistories[CurrentWhiteboardIndex] == null) return; //防止白板打开后不居中
|
||||
var targetIndex = isBackupMain ? 0 : CurrentWhiteboardIndex;
|
||||
if (TimeMachineHistories[targetIndex] == null) return; //防止白板打开后不居中
|
||||
|
||||
// 先清空当前画布的所有内容(墨迹和图片)
|
||||
inkCanvas.Strokes.Clear();
|
||||
inkCanvas.Children.Clear();
|
||||
|
||||
if (isBackupMain) {
|
||||
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[0]);
|
||||
foreach (var item in TimeMachineHistories[0]) ApplyHistoryToCanvas(item);
|
||||
@@ -95,6 +116,9 @@ namespace Ink_Canvas {
|
||||
private void BtnWhiteBoardSwitchPrevious_Click(object sender, EventArgs e) {
|
||||
if (CurrentWhiteboardIndex <= 1) return;
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes();
|
||||
|
||||
ClearStrokes(true);
|
||||
@@ -116,6 +140,9 @@ namespace Ink_Canvas {
|
||||
return;
|
||||
}
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes();
|
||||
|
||||
ClearStrokes(true);
|
||||
@@ -130,6 +157,10 @@ namespace Ink_Canvas {
|
||||
if (WhiteboardTotalCount >= 99) return;
|
||||
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
|
||||
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
|
||||
@@ -140,6 +171,9 @@ namespace Ink_Canvas {
|
||||
for (var i = WhiteboardTotalCount; i > CurrentWhiteboardIndex; i--)
|
||||
TimeMachineHistories[i] = TimeMachineHistories[i - 1];
|
||||
|
||||
// 确保新页面的历史记录为空
|
||||
TimeMachineHistories[CurrentWhiteboardIndex] = null;
|
||||
|
||||
UpdateIndexInfoDisplay();
|
||||
|
||||
if (WhiteboardTotalCount >= 99) BtnWhiteBoardAdd.IsEnabled = false;
|
||||
|
||||
@@ -1770,6 +1770,9 @@ namespace Ink_Canvas {
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardCenterSide);
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardRightSide);
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes(true);
|
||||
ClearStrokes(true);
|
||||
RestoreStrokes();
|
||||
@@ -1808,6 +1811,9 @@ namespace Ink_Canvas {
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardCenterSide);
|
||||
AnimationsHelper.HideWithSlideAndFade(BlackboardRightSide);
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
RestoreStrokes(true);
|
||||
@@ -1842,6 +1848,9 @@ namespace Ink_Canvas {
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BlackboardCenterSide);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BlackboardRightSide);
|
||||
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes(true);
|
||||
ClearStrokes(true);
|
||||
RestoreStrokes();
|
||||
|
||||
@@ -78,11 +78,18 @@ namespace Ink_Canvas
|
||||
var index = BlackBoardLeftSidePageListView.SelectedIndex;
|
||||
if (item != null)
|
||||
{
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
CurrentWhiteboardIndex= index+1;
|
||||
RestoreStrokes();
|
||||
UpdateIndexInfoDisplay();
|
||||
// 只有当选择的页面与当前页面不同时才进行切换
|
||||
if (index + 1 != CurrentWhiteboardIndex)
|
||||
{
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
CurrentWhiteboardIndex = index + 1;
|
||||
RestoreStrokes();
|
||||
UpdateIndexInfoDisplay();
|
||||
}
|
||||
BlackBoardLeftSidePageListView.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
@@ -95,11 +102,18 @@ namespace Ink_Canvas
|
||||
var index = BlackBoardRightSidePageListView.SelectedIndex;
|
||||
if (item != null)
|
||||
{
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
CurrentWhiteboardIndex = index + 1;
|
||||
RestoreStrokes();
|
||||
UpdateIndexInfoDisplay();
|
||||
// 只有当选择的页面与当前页面不同时才进行切换
|
||||
if (index + 1 != CurrentWhiteboardIndex)
|
||||
{
|
||||
// 取消任何UI元素的选择
|
||||
DeselectUIElement();
|
||||
|
||||
SaveStrokes();
|
||||
ClearStrokes(true);
|
||||
CurrentWhiteboardIndex = index + 1;
|
||||
RestoreStrokes();
|
||||
UpdateIndexInfoDisplay();
|
||||
}
|
||||
BlackBoardRightSidePageListView.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +160,23 @@ namespace Ink_Canvas {
|
||||
return fakeInkCanv.Strokes;
|
||||
}
|
||||
|
||||
// 新增:获取页面的所有图片元素
|
||||
private List<UIElement> GetPageImageElements(TimeMachineHistory[] items) {
|
||||
var imageElements = new List<UIElement>();
|
||||
|
||||
if (items != null && items.Length > 0) {
|
||||
foreach (var timeMachineHistory in items) {
|
||||
if (timeMachineHistory.CommitType == TimeMachineHistoryType.ElementInsert &&
|
||||
timeMachineHistory.InsertedElement != null &&
|
||||
!timeMachineHistory.StrokeHasBeenCleared) {
|
||||
imageElements.Add(timeMachineHistory.InsertedElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageElements;
|
||||
}
|
||||
|
||||
private void TimeMachine_OnUndoStateChanged(bool status) {
|
||||
var result = status ? Visibility.Visible : Visibility.Collapsed;
|
||||
BtnUndo.Visibility = result;
|
||||
|
||||
Reference in New Issue
Block a user