Example #1
0
            async void OnTagsChanged(object sender, EventArgs e)
            {
                try {
                    var ct = SyncHelper.CancelAndRetainToken(ref _Element._Cancellation);
                    await Task.Run(TagDocument, ct).ConfigureAwait(true);

                    _Regions = TagRegions();
                    if (ct.IsCancellationRequested)
                    {
                        return;
                    }
                }
                catch (ObjectDisposedException) {
                    return;
                }
                catch (OperationCanceledException) {
                    return;
                }
                _Element.InvalidateVisual();
            }
Example #2
0
        async void Update(object sender, EventArgs e)
        {
            HideMenu();
            SyncHelper.CancelAndDispose(ref _cancellationSource, true);
            var cs = _cancellationSource;

            if (cs != null)
            {
                try {
                    await Update(SyncHelper.CancelAndRetainToken(ref _cancellationSource));
                }
                catch (OperationCanceledException) {
                    // ignore
                }
            }
            async Task Update(CancellationToken token)
            {
                var nodes = await UpdateModelAndGetContainingNodesAsync(token);

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var c = Math.Min(Items.Count, nodes.Count);
                int i, i2;

                for (i = 1, i2 = 0; i < c && i2 < c; i2++)
                {
                    var n = nodes[i2];
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    if (Items[i] is NodeItem ni && ni.Node == n)
                    {
                        // keep the NaviItem if node is not updated
                        ++i;
                        continue;
                    }
                    if (n.IsKind(SyntaxKind.NamespaceDeclaration))
                    {
                        continue;
                    }
                    break;
                }
                if ((i == 1 || i2 < nodes.Count && nodes[i2].Kind().IsTypeOrNamespaceDeclaration()) && _RootItem.FilterText.Length == 0)
                {
                    // clear type and namespace menu items if a type is changed
                    _RootItem.ClearSymbolList();
                }
                c = Items.Count;
                // remove nodes out of range
                while (c > i)
                {
                    Items.RemoveAt(--c);
                }
                c = nodes.Count;
                NodeItem memberNode = null;

                while (i2 < c)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    var node = nodes[i2];
                    if (node.IsKind(SyntaxKind.NamespaceDeclaration))
                    {
                        _RootItem.SetText(node.GetDeclarationSignature());
                        ++i2;
                        continue;
                    }
                    var newItem = new NodeItem(this, node);
                    if (memberNode == null && node.Kind().IsMemberDeclaration())
                    {
                        memberNode = newItem;
                        (newItem.Header as TextBlock).FontWeight = FontWeights.Bold;
                        newItem.IsChecked = true;
                        newItem.ReferencedDocs.AddRange(node.FindRelatedTypes(_SemanticContext.SemanticModel, token).Take(5));
                    }
                    Items.Add(newItem);
                    ++i2;
                }
                if (memberNode == null)
                {
                    memberNode = Items.GetFirst <NodeItem>(n => n.HasReferencedDocs);
                }
                if (memberNode != null && memberNode.HasReferencedDocs)
                {
                    foreach (var doc in memberNode.ReferencedDocs)
                    {
                        Items.Add(new DocItem(this, doc));
                    }
                }
            }
        }