예제 #1
0
 public override HexEdit CreateEdit(int?reiteratedVersionNumber, object editTag)
 {
     VerifyAccess();
     if (EditInProgress)
     {
         throw new InvalidOperationException("An edit operation is in progress");
     }
     return(hexEditInProgress = new HexEditImpl(this, reiteratedVersionNumber, editTag));
 }
예제 #2
0
 internal void Cancel(HexEditImpl hexEdit)
 {
     VerifyAccess();
     if (hexEdit != hexEditInProgress)
     {
         throw new InvalidOperationException();
     }
     hexEditInProgress = null;
     PostChanged?.Invoke(this, EventArgs.Empty);
 }
예제 #3
0
        internal void ApplyChanges(HexEditImpl hexEdit, List <HexChange> changes, int?reiteratedVersionNumber, object editTag)
        {
            VerifyAccess();
            if (hexEdit != hexEditInProgress)
            {
                throw new InvalidOperationException();
            }
            hexEditInProgress = null;

            if (RaiseChangingGetIsCanceled(editTag))
            {
                PostChanged?.Invoke(this, EventArgs.Empty);
                return;
            }

            if (changes.Count != 0)
            {
                // We don't support overlapping changes. All offsets are relative to the original buffer
                changes.Sort(ReverseOldPositionSorter.Instance);
                for (int i = 1; i < changes.Count; i++)
                {
                    if (changes[i - 1].OldSpan.OverlapsWith(changes[i].OldSpan))
                    {
                        throw new InvalidOperationException("Two edit operations overlap");
                    }
                }

                var beforeVersion = Version;
                // changes is sorted in reverse order by OldPosition
                foreach (var change in changes)
                {
                    stream.Write(change.OldPosition, change.NewData);
                }
                CreateNewVersion(changes, reiteratedVersionNumber);
                var afterVersion = Version;

                HexContentChangedEventArgs args = null;
                //TODO: The event handlers are allowed to modify the buffer, but the new events must only be
                //		raised after all of these three events have been raised.
                ChangedHighPriority?.Invoke(this, args ?? (args = new HexContentChangedEventArgs(beforeVersion, afterVersion, editTag)));
                Changed?.Invoke(this, args ?? (args = new HexContentChangedEventArgs(beforeVersion, afterVersion, editTag)));
                ChangedLowPriority?.Invoke(this, args ?? (args = new HexContentChangedEventArgs(beforeVersion, afterVersion, editTag)));
            }
            PostChanged?.Invoke(this, EventArgs.Empty);
        }