Beispiel #1
0
            protected override ITextSnapshot PerformApply()
            {
                CheckActive();

                this.applied = true;

                if ((this.readOnlyRegionsToAdd.Count > 0) || (this.readOnlyRegionsToRemove.Count > 0))
                {
                    if (this.readOnlyRegionsToAdd.Count > 0)
                    {
                        // We leave the read only regions collection on the buffer null
                        // since most buffers will never have a read only region. Since
                        // regions are being added, create it now.
                        if (this.baseBuffer.readOnlyRegions == null)
                        {
                            this.baseBuffer.readOnlyRegions = new FrugalList <IReadOnlyRegion>();
                        }

                        this.baseBuffer.readOnlyRegions.AddRange(this.readOnlyRegionsToAdd);
                    }

                    if (this.readOnlyRegionsToRemove.Count > 0)
                    {
                        // We've already verified that it makes sense to remove these read only
                        // regions, so just proceed without further checks.
                        foreach (IReadOnlyRegion readOnlyRegion in this.readOnlyRegionsToRemove)
                        {
                            this.baseBuffer.readOnlyRegions.Remove(readOnlyRegion);
                        }
                    }

                    // Save off the current state of the read only spans
                    this.baseBuffer.readOnlyRegionSpanCollection = new ReadOnlySpanCollection(this.baseBuffer.CurrentVersion, this.baseBuffer.readOnlyRegions);

                    ReadOnlyRegionsChangedEventRaiser raiser =
                        new ReadOnlyRegionsChangedEventRaiser(new SnapshotSpan(this.baseBuffer.CurrentSnapshot, this.aggregateStart, this.aggregateEnd - this.aggregateStart));
                    this.baseBuffer.group.EnqueueEvents(raiser, this.baseBuffer);
                    // no immediate event for read only regions
                    this.baseBuffer.editInProgress = false;
                }
                else
                {
                    this.baseBuffer.editInProgress = false;
                }

                // no new snapshot
                return(this.originSnapshot);
            }
        internal virtual void OnSourceBufferReadOnlyRegionsChanged(object sender, SnapshotSpanEventArgs e)
        {
            NormalizedSpanCollection mappedAffectedSpans = new NormalizedSpanCollection(this.CurrentBaseSnapshot.MapFromSourceSnapshot(e.Span));

            if (mappedAffectedSpans.Count > 0)
            {
                ITextEventRaiser raiser =
                    new ReadOnlyRegionsChangedEventRaiser(new SnapshotSpan(this.currentSnapshot,
                                                                           Span.FromBounds(mappedAffectedSpans[0].Start,
                                                                                           mappedAffectedSpans[mappedAffectedSpans.Count - 1].End)));

                this.group.BeginEdit();
                this.group.EnqueueEvents(raiser, this);
                this.group.FinishEdit();
            }
        }