void HexBox_OnWrite(object sender, HexBoxWriteEventArgs e) { var hexBox = (HexBox)sender; var doc = hexBox.Document; if (doc == null) { return; } if (e.IsBeforeWrite) { var info = new UndoInfo(); info.OriginalData = hexBox.Document.ReadBytes(e.StartOffset, e.Size); info.OriginalCaretPosition = hexBox.CaretPosition; e.Context[contextKey] = info; } else { var info = (UndoInfo)e.Context[contextKey]; bool updated = TryUpdateOldTextInputCommand(e.Type, hexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData); if (!updated) { ClearTextInputCommand(); var cmd = new HexBoxUndoCommand(hexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData, GetDescription(e)); undoCommandService.Add(cmd); if (e.Type == HexWriteType.ByteInput || e.Type == HexWriteType.AsciiInput) { SetTextInputCommand(cmd); } } } }
void Buffer_Changed(object sender, HexContentChangedEventArgs e) { if (e.EditTag == HexBufferUndoRedo.UndoRedoObject) { return; } var buffer = (HexBuffer)sender; var desc = dnSpy_AsmEditor_Resources.Hex_Undo_Message_InsertBytes; var cmd = new HexBufferUndoCommand(buffer, e.Changes, e.BeforeVersion.ReiteratedVersionNumber, e.AfterVersion.ReiteratedVersionNumber, desc); undoCommandService.Add(cmd); }
public static void AddAndExecute(IUndoCommandService undoCommandService, HexDocument doc, ulong offset, byte[] data, string descr = null) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (data == null || data.Length == 0) { return; } undoCommandService.Add(new WriteHexUndoCommand(doc, offset, data, descr)); }