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
		public static void AddAndExecute(IUndoCommandManager undoCommandManager, HexDocument doc, ulong offset, byte[] data, string descr = null) {
			if (doc == null)
				throw new ArgumentNullException();
			if (data == null || data.Length == 0)
				return;
			undoCommandManager.Add(new WriteHexUndoCommand(doc, offset, data, descr));
		}
Exemplo n.º 3
0
 public static void AddAndExecute(IUndoCommandManager undoCommandManager, HexDocument doc, ulong offset, byte[] data, string descr = null)
 {
     if (doc == null)
     {
         throw new ArgumentNullException(nameof(doc));
     }
     if (data == null || data.Length == 0)
     {
         return;
     }
     undoCommandManager.Add(new WriteHexUndoCommand(doc, offset, data, descr));
 }