Example #1
0
        void HexBox_OnWrite(object sender, HexBoxWriteEventArgs e)
        {
            const string key = "HexBoxUndo";
            var hts = (HexTabState)TabState.GetTabState((HexBox)sender);
            var doc = hts.HexBox.Document;
            if (doc == null)
                return;
            if (e.IsBeforeWrite) {
                var info = new UndoInfo();
                info.OriginalData = hts.HexBox.Document.Read(e.StartOffset, e.Size);
                info.OriginalCaretPosition = hts.HexBox.CaretPosition;
                e.Context[key] = info;
            }
            else {
                var info = (UndoInfo)e.Context[key];

                bool updated = TryUpdateOldTextInputCommand(e.Type, hts.HexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData);
                if (!updated) {
                    ClearTextInputCommand();
                    var cmd = new HexBoxUndoCommand(hts.HexBox, info.OriginalCaretPosition, e.StartOffset, info.OriginalData, GetDescription(e));
                    UndoCommandManager.Instance.Add(cmd);
                    if (e.Type == HexWriteType.ByteInput || e.Type == HexWriteType.AsciiInput)
                        SetTextInputCommand(cmd);
                }
            }
        }
Example #2
0
 static string GetDescription(HexBoxWriteEventArgs e)
 {
     switch (e.Type) {
     case HexWriteType.Paste:		return string.Format("Paste {0} bytes @ {1:X8}", e.Size, e.StartOffset);
     case HexWriteType.ByteInput:	return "Insert Bytes";
     case HexWriteType.AsciiInput:	return "Insert ASCII";
     case HexWriteType.Fill:			return string.Format("Fill {0} bytes @ {1:X8}", e.Size, e.StartOffset);
     default:						return null;
     }
 }
Example #3
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;
		}