Exemple #1
0
            void SearchCriteriaChanged(object sender, EventArgs e)
            {
                SyncHelper.CancelAndDispose(ref _Bar._cancellationSource, true);
                _Menu.ItemsSource = null;
                _Menu.Clear();
                var s = _FinderBox.Text;

                if (s.Length == 0)
                {
                    _Menu.ContainerType = SymbolListType.NodeList;
                    ShowNamespaceAndTypeMenu();
                    return;
                }
                _Menu.ContainerType = SymbolListType.None;
                try {
                    switch (_ScopeBox.Filter)
                    {
                    case ScopeType.ActiveDocument:
                        FindInDocument(s);
                        break;

                    case ScopeType.ActiveProject:
                        FindInProject(s);
                        break;
                    }
                    _Menu.RefreshItemsSource();
                    _Menu.UpdateLayout();
                }
                catch (OperationCanceledException) {
                    // ignores cancellation
                }
                catch (ObjectDisposedException) { }
            }
Exemple #2
0
 void ViewClosed(object sender, EventArgs e)
 {
     _View.Selection.SelectionChanged -= Update;
     _View.TextBuffer.Changed         -= TextBuffer_Changed;
     SyncHelper.CancelAndDispose(ref _cancellationSource, false);
     _View.Closed -= ViewClosed;
 }
Exemple #3
0
 public void Dispose()
 {
     IsVisibleChanged -= _MemberMarker.OnIsVisibleChanged;
     Config.Updated   -= Config_Updated;
     _MemberMarker.Dispose();
     _SymbolReferenceMarker.Dispose();
     SyncHelper.CancelAndDispose(ref _Cancellation, false);
 }
        public void Release()
        {
            if (--_refCount == 0)
            {
                _buffer.Changed -= OnChanged;

                //Stop and blow away the old scan (even if it didn't finish, the results are not interesting anymore).
                SyncHelper.CancelAndDispose(ref _Cancellation, false);
                _root = null;                 //Allow the old root to be GC'd
            }
        }
Exemple #5
0
 void ViewClosed(object sender, EventArgs e)
 {
     SyncHelper.CancelAndDispose(ref _Cancellation, false);
     _ToolBarTray.ToolBars.Clear();
     _ToolBarTray.MouseEnter         -= ToolBarMouseEnter;
     _ToolBarTray.MouseLeave         -= ToolBarMouseLeave;
     View.Selection.SelectionChanged -= ViewSelectionChanged;
     View.VisualElement.MouseMove    -= ViewMouseMove;
     View.VisualElement.PreviewKeyUp -= ViewKeyUp;
     //View.LayoutChanged -= ViewLayoutChanged;
     View.Closed    -= ViewClosed;
     Config.Updated -= ConfigUpdated;
 }
        async Task ScanBufferAsync(ITextSnapshot snapshot)
        {
            //Stop and blow away the old scan (even if it didn't finish, the results are not interesting anymore).
            SyncHelper.CancelAndDispose(ref _Cancellation, true);
            var cancellationToken = _Cancellation.GetToken();

            //The underlying buffer could be very large, meaning that doing the scan for all matches on the UI thread
            //is a bad idea. Do the scan on the background thread and use a callback to raise the changed event when
            //the entire scan has completed.
            _root = await ParseAsync(snapshot, cancellationToken);

            //This delegate is executed on a background thread.
            await Task.Run(() => TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length))), cancellationToken);
        }
Exemple #7
0
            async void HandleClick(object sender, RoutedEventArgs e)
            {
                SyncHelper.CancelAndDispose(ref _Bar._cancellationSource, true);
                if (_Menu != null && _Bar._SymbolList == _Menu)
                {
                    _Bar.HideMenu();
                    return;
                }
                if (Node.Kind().IsTypeDeclaration() == false)
                {
                    var span = Node.FullSpan;
                    if (span.Contains(_Bar._SemanticContext.Position) && Node.SyntaxTree.FilePath == _Bar._SemanticContext.Document.FilePath ||
                        Node.IsKind(SyntaxKind.RegionDirectiveTrivia))
                    {
                        _Bar._View.SelectNode(Node, Keyboard.Modifiers != ModifierKeys.Control);
                    }
                    else
                    {
                        Node.GetIdentifierToken().GetLocation().GoToSource();
                    }
                    return;
                }

                var ct = _Bar._cancellationSource.GetToken();

                await CreateMenuForTypeSymbolNodeAsync(ct);

                _FilterBox.UpdateNumbers((await _Bar._SemanticContext.GetSymbolAsync(Node, ct) as ITypeSymbol)?.GetMembers());
                var footer = (TextBlock)_Menu.Footer;

                if (_PartialCount > 1)
                {
                    footer.Append(ThemeHelper.GetImage(KnownImageIds.OpenDocumentFromCollection))
                    .Append(_PartialCount);
                }
                footer.Append(ThemeHelper.GetImage(KnownImageIds.Code))
                .Append(Node.GetLineSpan().Length + 1);
                _Bar.ShowMenu(this, _Menu);
                _FilterBox?.FocusTextBox();
            }
Exemple #8
0
 void ViewSelectionChanged(object sender, EventArgs e)
 {
     // suppress event handler if KeepToolBar
     if (DateTime.Now < _LastExecute.AddSeconds(1) && _ToolBarTray.Visibility == Visibility.Visible)
     {
         return;
     }
     if (View.Selection.IsEmpty)
     {
         _ToolBarTray.Visibility       = Visibility.Hidden;
         View.VisualElement.MouseMove -= ViewMouseMove;
         SyncHelper.CancelAndDispose(ref _Cancellation, true);
         _SelectionStatus = 0;
         return;
     }
     if (Interlocked.CompareExchange(ref _SelectionStatus, Selecting, 0) != 0)
     {
         return;
     }
     SyncHelper.CancelAndDispose(ref _Cancellation, true);
     CreateToolBar(_Cancellation.Token);
     async void CreateToolBar(CancellationToken token)
     {
         try {
             if (_ToolBarTray.Visibility != Visibility.Visible)
             {
                 await Task.Delay(400, token);
             }
             if (token.IsCancellationRequested == false)
             {
                 await CreateToolBarAsync(token);
             }
         }
         catch (OperationCanceledException) {
             // ignore
         }
     }
 }
Exemple #9
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));
                    }
                }
            }
        }