private void OnIterationChanged(object sender, IterationChangedEventArgs args) { LoopIteration iteration = args.PreviousIteration; if (iteration != null) { HashSet <int> removes = new HashSet <int>(); foreach (Operation op in iteration.Operations) { if (removes.Contains(op.Id)) { continue; } ViewCache cache = this.views[op.GetType()]; InstantView opAdorner = cache.GetView(op.Id); if (opAdorner != null) { this.layer.RemoveAdornment(opAdorner); } } } AdornCode(this.view.TextSnapshot, GetCancelSource(current: true).Token); //ITextSnapshot s = this.view.TextSnapshot; //var map = this.context.LineMap ?? await LineMap.ConstructAsync (this.view.TextSnapshot, this.context.Span.GetText (s), GetCancelSource (current: true).Token); //AdornOperationContainer (args.NewIteration, s, map, GetCancelSource (current: true).Token); }
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); } } }