private async Task AdornCode(ITextSnapshot snapshot, string code, IDictionary <int, MethodCall> methods, CancellationToken cancelToken = default(CancellationToken)) { try { if (this.context.LineMap == null) { if ((this.context.LineMap = await LineMap.ConstructAsync(snapshot, code, cancelToken)) == null) { return; } } // TODO: Threads MethodCall container = methods.Values.First(); AdornOperationContainer(container, snapshot, this.context.LineMap, cancelToken); foreach (ViewCache viewCache in this.views.Values) { InstantView[] cleared = viewCache.ClearViews(); for (int i = 0; i < cleared.Length; i++) { this.layer.RemoveAdornment(cleared[i]); } } } catch (OperationCanceledException) { } }
private void AdornOperationContainer (OperationContainer container, ITextSnapshot snapshot, LineMap lineMap, CancellationToken cancelToken) { foreach (Operation operation in container.Operations) { SnapshotSpan span; if (!lineMap.TryGetSpan (this.view.TextSnapshot, operation.Id, out span)) continue; Geometry g = this.view.TextViewLines.GetMarkerGeometry (span); if (g == null) continue; Type opType = operation.GetType(); OperationVisuals vs; if (!Mapping.TryGetValue (opType, out vs)) continue; ViewCache viewCache; if (!views.TryGetValue (opType, out viewCache)) views[opType] = viewCache = new ViewCache (vs); InstantView adorner; bool preexisted = viewCache.TryGetView (out adorner); if (!preexisted) { adorner.FontSize = FontSize - 1; adorner.FontFamily = FontFamily; adorner.BorderBrush = BorderBrush; adorner.Foreground = Foreground; } adorner.Tag = operation.Id; OperationViewModel model = adorner.DataContext as OperationViewModel; if (model == null) adorner.DataContext = model = vs.CreateViewModel(); model.Operation = operation; if (operation is Loop) { var loopModel = (LoopViewModel)model; LoopIteration[] iterations = loopModel.Iterations; if (!preexisted || loopModel.Iteration > iterations.Length) loopModel.Iteration = iterations.Length; if (!preexisted) loopModel.IterationChanged += OnIterationChanged; if (iterations.Length > 0) AdornOperationContainer (iterations[loopModel.Iteration - 1], snapshot, lineMap, cancelToken); } Canvas.SetLeft (adorner, g.Bounds.Right + 10); Canvas.SetTop (adorner, g.Bounds.Top + 1); adorner.Height = g.Bounds.Height - 2; adorner.MaxHeight = g.Bounds.Height - 2; if (!preexisted) this.layer.AddAdornment (AdornmentPositioningBehavior.TextRelative, span, null, adorner, OperationAdornerRemoved); } }
private void AdornOperationContainer(OperationContainer container, ITextSnapshot snapshot, LineMap lineMap, CancellationToken cancelToken) { foreach (Operation operation in container.Operations) { SnapshotSpan span; if (!lineMap.TryGetSpan(this.view.TextSnapshot, operation.Id, out span)) { continue; } Geometry g = this.view.TextViewLines.GetMarkerGeometry(span); if (g == null) { continue; } Type opType = operation.GetType(); OperationVisuals vs; if (!Mapping.TryGetValue(opType, out vs)) { continue; } ViewCache viewCache; if (!views.TryGetValue(opType, out viewCache)) { views[opType] = viewCache = new ViewCache(vs); } InstantView adorner; bool preexisted = viewCache.TryGetView(out adorner); if (!preexisted) { adorner.FontSize = FontSize - 1; adorner.FontFamily = FontFamily; adorner.BorderBrush = BorderBrush; adorner.Foreground = Foreground; } adorner.Tag = operation.Id; OperationViewModel model = adorner.DataContext as OperationViewModel; if (model == null) { adorner.DataContext = model = vs.CreateViewModel(); } model.Operation = operation; if (operation is Loop) { var loopModel = (LoopViewModel)model; LoopIteration[] iterations = loopModel.Iterations; if (!preexisted || loopModel.Iteration > iterations.Length) { loopModel.Iteration = iterations.Length; } if (!preexisted) { loopModel.IterationChanged += OnIterationChanged; } if (iterations.Length > 0) { AdornOperationContainer(iterations[loopModel.Iteration - 1], snapshot, lineMap, cancelToken); } } Canvas.SetLeft(adorner, g.Bounds.Right + 10); Canvas.SetTop(adorner, g.Bounds.Top + 1); adorner.Height = g.Bounds.Height - 2; adorner.MaxHeight = g.Bounds.Height - 2; if (!preexisted) { this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, adorner, OperationAdornerRemoved); } } }