Example #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);
                    }
                }
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }