private int GetActionAffectFirst(HCCustomUndoAction aAction, bool aIsUndo) { int Result = aAction.ItemNo; switch (aAction.Tag) { case UndoActionTag.uatDeleteItem: { if (Result > 0) { Result--; } } break; case UndoActionTag.uatInsertItem: { if (aIsUndo) { if (Result > 0) { Result--; } } else { if (Result > Items.Count - 1) { Result--; } } } break; case UndoActionTag.uatItemProperty: if (aAction.Tag == UndoActionTag.uatItemProperty) { HCItemPropertyUndoAction vPropAction = aAction as HCItemPropertyUndoAction; if (vPropAction.ItemProperty == ItemProperty.uipParaFirst) { if (Result > 0) { Result--; } } } break; default: { if (Result > Items.Count - 1) { Result = Items.Count - 1; } } break; } return(Result); }
private int GetActionAffectFirst(HCCustomUndoAction aAction, bool aIsUndo) { int Result = aAction.ItemNo; switch (aAction.Tag) { case HCAction.actDeleteItem: { if (Result > 0) { Result--; } } break; case HCAction.actInsertItem: { if (aIsUndo) { if (Result > 0) { Result--; } } else { if (Result > Items.Count - 1) { Result--; } } } break; case HCAction.actItemProperty: HCItemPropertyUndoAction vPropAction = aAction as HCItemPropertyUndoAction; if ((vPropAction.ItemProperty == ItemProperty.uipParaFirst) || (vPropAction.ItemProperty == ItemProperty.uipPageBreak) || (vPropAction.ItemProperty == ItemProperty.uipStyleNo) ) { if (Result > 0) { Result--; } } break; } if (Result > Items.Count - 1) { Result = Items.Count - 1; } return(Result); }
private int GetActionAffectLast(HCCustomUndoAction aAction, bool aIsUndo) { int Result = aAction.ItemNo; switch (aAction.Tag) { case UndoActionTag.uatDeleteItem: if (aIsUndo) { if (Result > 0) { Result--; } } else { if (Result < Items.Count - 1) { Result++; } } break; case UndoActionTag.uatInsertItem: if (aIsUndo) { if ((Result < Items.Count - 1) && aAction.ParaFirst) { Result++; } } else { if (Result > Items.Count - 1) { Result--; } } break; default: if (Result > Items.Count - 1) { Result = Items.Count - 1; } break; } return(Result); }
private void UndoRedoItemProperty(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemPropertyUndoAction vAction = aAction as HCItemPropertyUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; HCCustomItem vItem = Items[vAction.ItemNo]; switch (vAction.ItemProperty) { case ItemProperty.uipStyleNo: { if (aIsUndo) { vItem.StyleNo = (vAction as HCItemStyleUndoAction).OldStyleNo; } else { vItem.StyleNo = (vAction as HCItemStyleUndoAction).NewStyleNo; } } break; case ItemProperty.uipParaNo: { if (aIsUndo) { vItem.ParaNo = (vAction as HCItemParaUndoAction).OldParaNo; } else { vItem.ParaNo = (vAction as HCItemParaUndoAction).NewParaNo; } } break; case ItemProperty.uipParaFirst: { if (aIsUndo) { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).OldParaFirst; } else { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).NewParaFirst; } } break; } }
private void UndoRedoItemSelf(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemSelfUndoAction vAction = aAction as HCItemSelfUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; if (aIsUndo) { Items[aCaretItemNo].Undo(vAction); } else { Items[aCaretItemNo].Redo(vAction); } }
private void UndoRedoInsertItem(HCCustomUndo aUndo, HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset, ref int aCaretDrawItemNo) { HCItemUndoAction vAction = aAction as HCItemUndoAction; aCaretItemNo = vAction.ItemNo; if (aIsUndo) { Items.RemoveAt(vAction.ItemNo); FItemAddCount--; if (aCaretItemNo > 0) { aCaretItemNo--; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } } else { aCaretOffset = 0; } } else // 重做 { HCCustomItem vItem = null; LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); Items.Insert(vAction.ItemNo, vItem); FItemAddCount++; aCaretItemNo = vAction.ItemNo; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo + 1; } }
private void UndoRedoSetItemText(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCSetItemTextUndoAction vAction = aAction as HCSetItemTextUndoAction; aCaretItemNo = vAction.ItemNo; if (aIsUndo) { Items[vAction.ItemNo].Text = vAction.Text; aCaretOffset = vAction.Offset; } else { Items[vAction.ItemNo].Text = vAction.NewText; aCaretOffset = vAction.NewText.Length; } }
private void UndoRedoItemMirror(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemUndoAction vAction = aAction as HCItemUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; HCCustomItem vItem = Items[aCaretItemNo]; if (aIsUndo) { LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); } else { LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); } }
public HCCustomUndoAction ActionAppend(HCAction aTag, int aItemNo, int aOffset, bool aParaFirst) { HCCustomUndoAction Result = null; switch (aTag) { case HCAction.actBackDeleteText: case HCAction.actDeleteText: case HCAction.actInsertText: Result = new HCTextUndoAction(); break; case HCAction.actSetItemText: Result = new HCSetItemTextUndoAction(); break; case HCAction.actDeleteItem: case HCAction.actInsertItem: case HCAction.actItemMirror: Result = new HCItemUndoAction(); break; //case HCAction.actItemProperty: // Result = new HCItemParaFirstUndoAction(); // break; case HCAction.actItemSelf: Result = new HCItemSelfUndoAction(); break; default: Result = new HCCustomUndoAction(); break; } Result.Tag = aTag; Result.ItemNo = aItemNo; Result.Offset = aOffset; Result.ParaFirst = aParaFirst; this.Actions.Add(Result); return(Result); }
// 撤销重做相关方法 public override void Undo(HCCustomUndoAction aUndoAction) { if (aUndoAction is HCItemSelfUndoAction) { HCUndoList vUndoList = (aUndoAction as HCItemSelfUndoAction).Object as HCUndoList; if (vUndoList != null) { vUndoList.Undo(); } else { base.Undo(aUndoAction); } } else { base.Undo(aUndoAction); } }
private void UndoRedoDeleteText(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCTextUndoAction vAction = aAction as HCTextUndoAction; aCaretItemNo = vAction.ItemNo; int vLen = vAction.Text.Length; string vText = Items[vAction.ItemNo].Text; if (aIsUndo) { vText = vText.Insert(vAction.Offset - 1, vAction.Text); } else { vText = vText.Remove(vAction.Offset - 1, vLen); } aCaretOffset = vAction.Offset - 1; Items[vAction.ItemNo].Text = vText; }
private void DoUndoRedoAction(HCCustomUndo aUndo, HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset, ref int aCaretDrawItemNo) { switch (aAction.Tag) { case HCAction.actBackDeleteText: UndoRedoDeleteBackText(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actDeleteText: UndoRedoDeleteText(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actInsertText: UndoRedoInsertText(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actSetItemText: UndoRedoSetItemText(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actDeleteItem: UndoRedoDeleteItem(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actInsertItem: UndoRedoInsertItem(aUndo, aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset, ref aCaretDrawItemNo); break; case HCAction.actItemProperty: UndoRedoItemProperty(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actItemSelf: UndoRedoItemSelf(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; case HCAction.actItemMirror: UndoRedoItemMirror(aAction, aIsUndo, ref aCaretItemNo, ref aCaretOffset); break; } }
protected HCUndoList GetSelfUndoList() { HCUndoList Result = null; HCUndoList vMainUndoList = FOnGetMainUndoList(); int vActionCount = vMainUndoList[vMainUndoList.Count - 1].Actions.Count; HCCustomUndoAction vLastAction = vMainUndoList[vMainUndoList.Count - 1].Actions[vActionCount - 1]; if (vLastAction is HCItemSelfUndoAction) { HCItemSelfUndoAction vItemAction = vLastAction as HCItemSelfUndoAction; if (vItemAction.Object == null) { vItemAction.Object = new HCUndoList(); (vItemAction.Object as HCUndoList).OnNewUndo = DoNewUndo; (vItemAction.Object as HCUndoList).OnUndo = DoUndo; (vItemAction.Object as HCUndoList).OnRedo = DoRedo; } Result = vItemAction.Object as HCUndoList; } return(Result); }
public HCCustomUndoAction ActionAppend(UndoActionTag ATag, int AItemNo, int AOffset) { HCCustomUndoAction Result = null; switch (ATag) { case UndoActionTag.uatDeleteText: case UndoActionTag.uatInsertText: Result = new HCTextUndoAction(); break; case UndoActionTag.uatDeleteItem: case UndoActionTag.uatInsertItem: Result = new HCItemUndoAction(); break; case UndoActionTag.uatItemProperty: Result = new HCItemParaFirstUndoAction(); break; case UndoActionTag.uatItemSelf: Result = new HCItemSelfUndoAction(); break; default: Result = new HCCustomUndoAction(); break; } Result.Tag = ATag; Result.ItemNo = AItemNo; Result.Offset = AOffset; this.Actions.Add(Result); return(Result); }
public override void Redo(HCCustomUndoAction aRedoAction) { if (aRedoAction is HCItemSelfUndoAction) { HCUndoList vUndoList = (aRedoAction as HCItemSelfUndoAction).Object as HCUndoList; if (vUndoList != null) { if (vUndoList.Seek < 0) { SelfUndoListInitializate(vUndoList); } vUndoList.Redo(); } else { base.Redo(aRedoAction); } } else { base.Redo(aRedoAction); } }
private void UndoRedoItemProperty(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemPropertyUndoAction vAction = aAction as HCItemPropertyUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; HCCustomItem vItem = Items[vAction.ItemNo]; switch (vAction.ItemProperty) { case ItemProperty.uipStyleNo: { if (aIsUndo) { vItem.StyleNo = (vAction as HCItemStyleUndoAction).OldStyleNo; } else { vItem.StyleNo = (vAction as HCItemStyleUndoAction).NewStyleNo; } } break; case ItemProperty.uipParaNo: { int vParaLastItemNo = GetParaLastItemNo(vAction.ItemNo); if (aIsUndo) { for (int i = vAction.ItemNo; i <= vParaLastItemNo; i++) { Items[i].ParaNo = (vAction as HCItemParaUndoAction).OldParaNo; } } else { for (int i = vAction.ItemNo; i <= vParaLastItemNo; i++) { Items[i].ParaNo = (vAction as HCItemParaUndoAction).NewParaNo; } } } break; case ItemProperty.uipParaFirst: { if (aIsUndo) { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).OldParaFirst; } else { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).NewParaFirst; } } break; case ItemProperty.uipPageBreak: { FForceClearExtra = true; if (aIsUndo) { vItem.PageBreak = (vAction as HCItemPageBreakUndoAction).OldPageBreak; } else { vItem.PageBreak = (vAction as HCItemPageBreakUndoAction).NewPageBreak; } } break; } }
private void UndoRedoInsertItem(HCCustomUndo aUndo, HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset, ref int aCaretDrawItemNo) { HCItemUndoAction vAction = aAction as HCItemUndoAction; aCaretItemNo = vAction.ItemNo; if (aIsUndo) { if (aCaretItemNo < Items.Count - 1) // 不是最后一个 { if (Items[aCaretItemNo].ParaFirst) // 段首删除了,光标为下一个开始 { aCaretOffset = 0; aCaretDrawItemNo = Items[aCaretItemNo + 1].FirstDItemNo; } else // 删除的不是段首 //if (Items[aCaretItemNo + 1].ParaFirst) // 下一个是段首,光标保持在同段最后 { aCaretItemNo--; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo;// - 1; } } else if (aCaretItemNo > 0) // 不是第一个 { aCaretItemNo--; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo - 1; } else { aCaretOffset = 0; } Items.RemoveAt(vAction.ItemNo); FItemAddCount--; } else // 重做 { HCCustomItem vItem = null; LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); Items.Insert(vAction.ItemNo, vItem); FItemAddCount++; aCaretItemNo = vAction.ItemNo; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo + 1; } }
public virtual void Redo(HCCustomUndoAction aRedoAction) { }
// 撤销重做相关方法 public virtual void Undo(HCCustomUndoAction aUndoAction) { }