Exemplo n.º 1
0
		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));
					undoCommandManager.Add(cmd);
					if (e.Type == HexWriteType.ByteInput || e.Type == HexWriteType.AsciiInput)
						SetTextInputCommand(cmd);
				}
			}
		}
Exemplo n.º 2
0
 Dictionary<object, object> NotifyWrite(HexWriteType type, ulong offs, int count, bool isBeforeWrite, Dictionary<object, object> context)
 {
     var ea = new HexBoxWriteEventArgs(type, offs, count, isBeforeWrite, context);
     if (OnWrite != null)
         OnWrite(this, ea);
     return ea.Context;
 }
Exemplo n.º 3
0
		static string GetDescription(HexBoxWriteEventArgs e) {
			switch (e.Type) {
			case HexWriteType.Paste:		return string.Format(dnSpy_AsmEditor_Resources.Hex_Undo_Message_PasteBytesAtAddress, e.Size, e.StartOffset);
			case HexWriteType.ByteInput:	return dnSpy_AsmEditor_Resources.Hex_Undo_Message_InsertBytes;
			case HexWriteType.AsciiInput:	return dnSpy_AsmEditor_Resources.Hex_Undo_Message_InsertASCII;
			case HexWriteType.Fill:			return string.Format(dnSpy_AsmEditor_Resources.Hex_Undo_Message_FillBytesAtAddress, e.Size, e.StartOffset);
			default:						return null;
			}
		}