-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Feature] 新增多步撤回功能 (Project Name: TimeMachine) #62
Merged
Merged
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5d4f0d4
[TimeMachine] 引入TimeMachine(多步撤回工具)
Raspberry-Monster 28a957e
[feat] 新增橡皮和清屏的撤销
kengwang 27b75ca
[fix] 修复 Redo 时的清屏无效
kengwang 349eaf6
[fix] 修复了可能导致崩溃的问题
kengwang d4cb88a
[chore] 支持撤销删除选中墨迹
kengwang 500fd28
[WIP] 添加对切换页面保存记录的支持
Raspberry-Monster a74ac6e
Merge branch 'feat/TimeMachine' of https://github.com/WXRIW/Ink-Canva…
Raspberry-Monster c0b3314
[Typo/TimeMachine] 修改部分变量命名,支持撤回擦除行为
Raspberry-Monster 5ccf315
[Clean UP/TimeMachine][WIP] 支持撤回EraseByPoint(此版本切换页面无法保留记录)
Raspberry-Monster eda13ff
[BugFix] 修复切换页面时无法保存墨迹的Bug
Raspberry-Monster 043423d
[PPT] 支持PPT页面撤销
Raspberry-Monster 2baa23f
Merge branch 'master' of https://github.com/WXRIW/Ink-Canvas into fea…
Raspberry-Monster f2f106a
[Bug Fix] 尝试修复在使用墨迹识别/图形绘制时撤销不正确的bug
Raspberry-Monster c570534
Merge branch 'master' of https://github.com/WXRIW/Ink-Canvas into fea…
Raspberry-Monster 6012448
[Typo] 修正合并冲突
Raspberry-Monster 99fd549
Merge branch 'master' of https://github.com/WXRIW/Ink-Canvas into fea…
Raspberry-Monster 4d55584
[Merge/Exception Handle] 添加UnhandledException处理,解决合并冲突
Raspberry-Monster 04beedc
[LogHelper] Save Unhandled Exception Info To File
Raspberry-Monster 6d0e379
Use snackbar instead of messagebox for unhandled exception
WXRIW 7b4041a
[Bug Fix/TimeMachine] 修复在部分情况下无法保存笔画记录,支持撤销完整正方体
Raspberry-Monster 080b849
[EraseByPoint] 修改添加和移除Stroke的顺序以保证在Stroke复杂时的撤销/重做行为正常
Raspberry-Monster 6d054cf
[Rotate] 支持撤回旋转操作
Raspberry-Monster 72bf678
[Undo/Redo] 在Undo/Redo时取消选择
Raspberry-Monster 89d438f
Fix UI
WXRIW 2f617e2
Code cleanup
WXRIW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System.Collections.Generic; | ||
using System.Windows.Ink; | ||
|
||
namespace Ink_Canvas.Helpers | ||
{ | ||
public class TimeMachine | ||
{ | ||
private readonly List<TimeMachineHistory> _currentStrokeHistory = new List<TimeMachineHistory>(); | ||
|
||
private int _currentIndex = -1; | ||
|
||
public delegate void OnUndoStateChange(bool status); | ||
|
||
public event OnUndoStateChange OnUndoStateChanged; | ||
|
||
public delegate void OnRedoStateChange(bool status); | ||
|
||
public event OnRedoStateChange OnRedoStateChanged; | ||
|
||
public void CommitStrokeUserInputHistory(StrokeCollection stroke) | ||
{ | ||
if (_currentIndex + 1 < _currentStrokeHistory.Count) | ||
{ | ||
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex); | ||
} | ||
_currentStrokeHistory.Add(new TimeMachineHistory(stroke, TimeMachineHistoryType.UserInput, false)); | ||
_currentIndex = _currentStrokeHistory.Count - 1; | ||
NotifyUndoRedoState(); | ||
} | ||
|
||
public void CommitStrokeShapeHistory(StrokeCollection strokeToBeReplaced, StrokeCollection generatedStroke) | ||
{ | ||
if (_currentIndex + 1 < _currentStrokeHistory.Count) | ||
{ | ||
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex); | ||
} | ||
_currentStrokeHistory.Add(new TimeMachineHistory(generatedStroke, | ||
TimeMachineHistoryType.ShapeRecognition, | ||
false, | ||
strokeToBeReplaced)); | ||
_currentIndex = _currentStrokeHistory.Count - 1; | ||
NotifyUndoRedoState(); | ||
} | ||
|
||
public void CommitStrokeEraseHistory(StrokeCollection stroke, StrokeCollection sourceStroke = null) | ||
{ | ||
if (_currentIndex + 1 < _currentStrokeHistory.Count) | ||
{ | ||
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex); | ||
} | ||
_currentStrokeHistory.Add(new TimeMachineHistory(stroke, TimeMachineHistoryType.Clear, true, sourceStroke)); | ||
_currentIndex = _currentStrokeHistory.Count - 1; | ||
NotifyUndoRedoState(); | ||
} | ||
|
||
public void ClearStrokeHistory() | ||
{ | ||
_currentStrokeHistory.Clear(); | ||
_currentIndex = -1; | ||
NotifyUndoRedoState(); | ||
} | ||
public TimeMachineHistory Undo() | ||
{ | ||
var item = _currentStrokeHistory[_currentIndex]; | ||
item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared; | ||
_currentIndex--; | ||
OnUndoStateChanged?.Invoke(_currentIndex > -1); | ||
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0); | ||
return item; | ||
} | ||
|
||
public TimeMachineHistory Redo() | ||
{ | ||
var item = _currentStrokeHistory[++_currentIndex]; | ||
item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared; | ||
NotifyUndoRedoState(); | ||
return item; | ||
} | ||
public TimeMachineHistory[] ExportTimeMachineHistory() | ||
{ | ||
if (_currentIndex + 1 < _currentStrokeHistory.Count) | ||
{ | ||
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex); | ||
} | ||
return _currentStrokeHistory.ToArray(); | ||
} | ||
|
||
public bool ImportTimeMachineHistory(TimeMachineHistory[] sourceHistory) | ||
{ | ||
_currentStrokeHistory.Clear(); | ||
_currentStrokeHistory.AddRange(sourceHistory); | ||
_currentIndex = _currentStrokeHistory.Count - 1; | ||
NotifyUndoRedoState(); | ||
return true; | ||
} | ||
private void NotifyUndoRedoState() | ||
{ | ||
OnUndoStateChanged?.Invoke(_currentIndex > -1); | ||
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0); | ||
} | ||
} | ||
|
||
public class TimeMachineHistory | ||
{ | ||
public TimeMachineHistoryType CommitType; | ||
public bool StrokeHasBeenCleared; | ||
public StrokeCollection CurrentStroke; | ||
public StrokeCollection ReplacedStroke; | ||
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared) | ||
{ | ||
CommitType = commitType; | ||
CurrentStroke = currentStroke; | ||
StrokeHasBeenCleared = strokeHasBeenCleared; | ||
ReplacedStroke = null; | ||
} | ||
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared, StrokeCollection replacedStroke) | ||
{ | ||
CommitType = commitType; | ||
CurrentStroke = currentStroke; | ||
StrokeHasBeenCleared = strokeHasBeenCleared; | ||
ReplacedStroke = replacedStroke; | ||
} | ||
} | ||
|
||
public enum TimeMachineHistoryType | ||
{ | ||
UserInput, | ||
ShapeRecognition, | ||
Clear | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用修改,在
master
里我已经进行了相关优化,换行看起来有点突兀