예제 #1
0
        public TagSpan <IOutliningRegionTag> AsOutliningRegionTag()
        {
            SnapshotSpan     span = this.AsSnapshotSpan();
            OutliningOptions opt  = this.Tagger.Options;

            //isImplementation means that block will collapse on "Collapse to definitions" command
            //my stupid parser collapses top-level blocks in document, regions and top-level blocks in each region
            //and also function bodies which it was able to detect
            bool isImplementation =
                RegionSubType == TextRegionSubType.Function ||
                RegionType == TextRegionType.Region ||
                Parent.RegionType == TextRegionType.None ||
                Parent.RegionType == TextRegionType.Region;

            // collapsed when opening a file
            bool collapsed = false;

            if (Tagger.FirstOutlining)
            {
                collapsed = isImplementation && opt.AutoCollapseToDefinitions;
                if (!collapsed)
                {
                    switch (RegionType)
                    {
                    case TextRegionType.Block:
                    case TextRegionType.Array:
                        collapsed = opt.AutoCollapseBraces;
                        break;

                    case TextRegionType.Comment:
                        collapsed = opt.AutoCollapseComments;
                        break;

                    case TextRegionType.Region:
                        collapsed = opt.AutoCollapseRegions;
                        break;
                    }
                }
            }

            return(new TagSpan <IOutliningRegionTag>
                   (
                       span,
                       new OutliningRegionTag
                       (
                           collapsed,
                           isImplementation,
                           GetCollapsedText(),
                           new CollapsedHintFormatter(this).FormatHint()
                       )
                   ));
        }
        protected virtual void Init()
        {
            Options = GetOptions();

            //timer that will trigger outlining update after some period of no buffer changes
            UpdateTimer          = new DispatcherTimer(DispatcherPriority.ApplicationIdle);
            UpdateTimer.Interval = TimeSpan.FromMilliseconds(2500);
            FirstOutlining       = true;
            UpdateTimer.Tick    += (sender, args) => {
                UpdateTimer.Stop();
                Outline();
            };
            //bind to events and start outlining
        }