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