Beispiel #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);
                    }
                }
            }
        }
Beispiel #2
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.ReadBytes(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);
				}
			}
		}
Beispiel #3
0
 void SetTextInputCommand(HexBoxUndoCommand cmd)
 {
     prevTextInputCmd.Target = cmd;
 }
Beispiel #4
0
 void SetTextInputCommand(HexBoxUndoCommand cmd) => prevTextInputCmd.Target = cmd;