Exemple #1
0
        private ICollapsible ExpandInternal(ICollapsed collapsed)
        {
            EnsureValid();

            Collapsed internalCollapsed = collapsed as Collapsed;

            if (internalCollapsed == null)
            {
                throw new ArgumentException("The given collapsed region was not created by this outlining manager.",
                                            "collapsed");
            }

            if (!internalCollapsed.IsValid)
            {
                throw new InvalidOperationException("The collapsed region is invalid, meaning it has already been expanded.");
            }

            if (!collapsedRegionTree.RemoveItem(internalCollapsed, internalCollapsed.Extent))
            {
                throw new ApplicationException("Unable to remove the collapsed region from outlining manager, which means there is an internal " +
                                               "consistency issue.");
            }

            // Now that we've expanded the region, invalidate the ICollapsed so it can no longer be used.
            internalCollapsed.Invalidate();

            return(new Collapsible(collapsed.Extent, collapsed.Tag));
        }
Exemple #2
0
        private ICollapsed CollapseInternal(ICollapsible collapsible)
        {
            EnsureValid();

            if (collapsible.IsCollapsed)
            {
                return(null);
            }

            Collapsed newCollapsed = new Collapsed(collapsible.Extent, collapsible.Tag);

            newCollapsed.Node = collapsedRegionTree.TryAddItem(newCollapsed, newCollapsed.Extent);

            if (newCollapsed.Node == null)
            {
                return(null);
            }

            return(newCollapsed);
        }
Exemple #3
0
        private IEnumerable <ICollapsible> MergeRegions(IEnumerable <ICollapsed> currentCollapsed, IEnumerable <ICollapsible> newCollapsibles,
                                                        out IEnumerable <ICollapsed> removedRegions)
        {
            List <ICollapsed> toRemove = new List <ICollapsed>();

            List <ICollapsed>   oldRegions = new List <ICollapsed>(currentCollapsed);
            List <ICollapsible> newRegions = new List <ICollapsible>(newCollapsibles);

            List <ICollapsible> merged = new List <ICollapsible>(oldRegions.Count + newRegions.Count);

            int oldIndex = 0;
            int newIndex = 0;

            CollapsibleSorter sorter = new CollapsibleSorter(this.editBuffer);

            while (oldIndex < oldRegions.Count || newIndex < newRegions.Count)
            {
                if (oldIndex < oldRegions.Count && newIndex < newRegions.Count)
                {
                    Collapsed    oldRegion = oldRegions[oldIndex] as Collapsed;
                    ICollapsible newRegion = newRegions[newIndex];

                    int compareVal = sorter.Compare(oldRegion, newRegion);

                    // Same region
                    if (compareVal == 0)
                    {
                        // might be the same region, but content could be new
                        oldRegion.Tag = newRegion.Tag;
                        merged.Add(oldRegion);

                        oldIndex++;
                        newIndex++;
                    }
                    // old region comes first
                    else if (compareVal < 0)
                    {
                        toRemove.Add(oldRegion);
                        oldIndex++;
                    }
                    // new region comes first
                    else if (compareVal > 0)
                    {
                        merged.Add(newRegion);
                        newIndex++;
                    }
                }
                else if (oldIndex < oldRegions.Count)
                {
                    toRemove.AddRange(oldRegions.GetRange(oldIndex, oldRegions.Count - oldIndex));
                    break;
                }
                else if (newIndex < newRegions.Count)
                {
                    merged.AddRange(newRegions.GetRange(newIndex, newRegions.Count - newIndex));
                    break;
                }
            }

            removedRegions = toRemove;

            return(merged);
        }