Ejemplo n.º 1
0
 private void OnTreeUpdateCompleted(object sender, TreeUpdatedEventArgs e)
 {
     if (IsEnabled && (e.UpdateType != TreeUpdateType.PositionsOnly || (_sections != null && _sections.Changed)))
     {
         BackgroundTask.DoTaskOnIdle();
     }
 }
Ejemplo n.º 2
0
        public override bool BuildRegions(OutlineRegionCollection newRegions)
        {
            lock (_threadLock) {
                if (IsDisposed || !EditorTree.IsReady)
                {
                    return(false);
                }

                AstRoot rootNode = null;
                try {
                    // We are in a background thread so in order to walk the tree
                    // we must obtain the read lock first.
                    rootNode = EditorTree.AcquireReadLock(_treeUserId);
                    if (rootNode != null)
                    {
                        OutliningContext context = new OutliningContext();
                        context.Regions = newRegions;
                        // Walk the tree and construct new regions
                        rootNode.Accept(this, context);
                        OutlineSections(rootNode, context);
                    }
                } catch (Exception) { } finally {
                    if (rootNode != null)
                    {
                        EditorTree.ReleaseReadLock(_treeUserId);
                    }
                    else
                    {
                        // Tree was busy. Will try again later.
                        GuardedOperations.DispatchInvoke(() => BackgroundTask.DoTaskOnIdle(), DispatcherPriority.Normal);
                    }
                }
                return(true);
            }
        }
Ejemplo n.º 3
0
 private void OnTreeUpdateCompleted(object sender, TreeUpdatedEventArgs e)
 {
     if (e.UpdateType != TreeUpdateType.PositionsOnly)
     {
         BackgroundTask.DoTaskOnIdle();
     }
 }
Ejemplo n.º 4
0
 protected override void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
 {
     if (IsEnabled && e.Before.LineCount != e.After.LineCount)
     {
         BackgroundTask.DoTaskOnIdle();
     }
     base.OnTextBufferChanged(sender, e);
 }
Ejemplo n.º 5
0
 protected override void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
 {
     if (e.Before.LineCount != e.After.LineCount || (_sections != null && _sections.Changed(e.After)))
     {
         BackgroundTask.DoTaskOnIdle();
     }
     base.OnTextBufferChanged(sender, e);
 }
Ejemplo n.º 6
0
        public override bool BuildRegions(OutlineRegionCollection newRegions)
        {
            lock (_threadLock)
            {
                if (IsDisposed || !EditorTree.IsReady)
                {
                    return(false);
                }

                AstRoot rootNode = null;

                try
                {
                    rootNode = EditorTree.AcquireReadLock(_treeUserId);
                    if (rootNode != null)
                    {
                        OutliningContext context = new OutliningContext();
                        context.Regions = newRegions;

                        rootNode.Accept(this, context);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Exception in outliner: {0}", ex.Message));
                }
                finally
                {
                    if (rootNode != null)
                    {
                        EditorTree.ReleaseReadLock(_treeUserId);
                    }
                    else
                    {
                        // Tree was busy. Will try again later.
                        GuardedOperations.DispatchInvoke(() => BackgroundTask.DoTaskOnIdle(), DispatcherPriority.Normal);
                    }
                }

                return(true);
            }
        }
Ejemplo n.º 7
0
        protected virtual void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
        {
            // In order to provide nicer experience when user presser and holds
            // ENTER or DELETE or just types really fast, we are going to track
            // regions optimistically and report changes without going through
            // async or idle processing. Idle/async is still going to hit later.

            if (e.Changes.Count > 0)
            {
                int start, oldLength, newLength;
                TextUtility.CombineChanges(e, out start, out oldLength, out newLength);

                int changeStart = Int32.MaxValue;
                int changeEnd   = 0;

                lock (_regionsLock) {
                    // Remove affected regions and shift the remaining ones. Outlining
                    // regions are not sorted and can overlap. Hence linear search.

                    for (int i = 0; i < CurrentRegions.Count; i++)
                    {
                        var region = CurrentRegions[i];

                        if (region.End <= start)
                        {
                            continue;
                        }

                        if (region.Contains(start) && region.Contains(start + oldLength))
                        {
                            region.Expand(0, newLength - oldLength);
                        }
                        else if (region.Start >= start + oldLength)
                        {
                            region.Shift(newLength - oldLength);
                        }
                        else
                        {
                            changeStart = Math.Min(changeStart, region.Start);
                            changeEnd   = Math.Max(changeEnd, region.End);

                            CurrentRegions.RemoveAt(i);
                            i--;

                            if (e.Changes.Count > 0)
                            {
                                // If we merged changes, this might be an overaggressive delete. Ensure
                                //   that we'll do a full recalculation later.
                                BackgroundTask.DoTaskOnIdle();
                            }
                        }
                    }
                }

                // If there were previously any regions, make sure we notify our listeners of the changes
                if ((CurrentRegions.Count > 0) || (changeStart < Int32.MaxValue))
                {
                    CurrentRegions.TextBufferVersion = TextBuffer.CurrentSnapshot.Version.VersionNumber;
                    if (RegionsChanged != null)
                    {
                        changeEnd = (changeStart == Int32.MaxValue ? changeStart : changeEnd);
                        RegionsChanged(this, new OutlineRegionsChangedEventArgs(CurrentRegions, TextRange.FromBounds(changeStart, changeEnd)));
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
        {
            base.OnTextBufferChanged(sender, e);

            BackgroundTask.DoTaskOnIdle();
        }
Ejemplo n.º 9
0
 public IndentBasedOutlineRegionBuilder(ITextBuffer textBuffer)
     : base(textBuffer)
 {
     BackgroundTask.DoTaskOnIdle();
 }