Пример #1
0
            void SearchCriteriaChanged(object sender, EventArgs e)
            {
                CancellationHelper.CancelAndDispose(ref _Bar._cancellationSource, true);
                _Menu.ItemsSource = null;
                _Menu.Symbols.Clear();
                var s = _FinderBox.Text;

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

                    case ScopeType.ActiveProject:
                        FindInProject(s);
                        break;
                    }
                    _Menu.RefreshSymbols();
                    _Menu.UpdateLayout();
                }
                catch (OperationCanceledException) {
                    // ignores cancellation
                }
                catch (ObjectDisposedException) { }
            }
Пример #2
0
        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).
                CancellationHelper.CancelAndDispose(ref _Cancellation, false);
                _root = null;                 //Allow the old root to be GC'd
            }
        }
Пример #3
0
 void ViewClosed(object sender, EventArgs e)
 {
     CancellationHelper.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;
 }
Пример #4
0
 async void OnTagsChanged(object sender, EventArgs e)
 {
     try {
         CancellationHelper.CancelAndDispose(ref _Element._Cancellation, true);
         await Task.Run(TagDocument, _Element._Cancellation.GetToken());
     }
     catch (ObjectDisposedException) {
         return;
     }
     catch (OperationCanceledException) {
         return;
     }
     _Element.InvalidateVisual();
 }
Пример #5
0
        async Task ScanBufferAsync(ITextSnapshot snapshot)
        {
            //Stop and blow away the old scan (even if it didn't finish, the results are not interesting anymore).
            CancellationHelper.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);
        }
Пример #6
0
            void SearchCriteriaChanged(object sender, EventArgs e)
            {
                CancellationHelper.CancelAndDispose(ref _Bar._cancellationSource, true);
                ClearItems();
                var s = _FinderBox.Text;

                if (s.Length == 0)
                {
                    AddNamespaceAndTypes();
                    return;
                }
                try {
                    switch (_ScopeBox.Filter)
                    {
                    case ScopeType.ActiveDocument: FindInDocument(s); break;

                    case ScopeType.ActiveProject: FindInProject(s); break;
                    }
                }
                catch (OperationCanceledException) {
                    // ignores cancellation
                }
                catch (ObjectDisposedException) { }
            }
Пример #7
0
        void ViewSelectionChanged(object sender, EventArgs e)
        {
            // suppress event handler if KeepToolBar
            if (DateTime.Now < _LastExecute.AddSeconds(1))
            {
                return;
            }
            if (View.Selection.IsEmpty)
            {
                _ToolBarTray.Visibility       = Visibility.Hidden;
                View.VisualElement.MouseMove -= ViewMouseMove;
                CancellationHelper.CancelAndDispose(ref _Cancellation, true);
                _SelectionStatus = 0;
                return;
            }
            if (Interlocked.CompareExchange(ref _SelectionStatus, Selecting, 0) != 0)
            {
                return;
            }
            CancellationHelper.CancelAndDispose(ref _Cancellation, true);
            CreateToolBar(_Cancellation.Token);
            async void CreateToolBar(CancellationToken token)
            {
                try {
                    await Task.Delay(400, token);

                    if (token.IsCancellationRequested == false)
                    {
                        await CreateToolBarAsync(token);
                    }
                }
                catch (OperationCanceledException) {
                    // ignore
                }
            }
        }
Пример #8
0
            async void HandleClick(object sender, RoutedEventArgs e)
            {
                CancellationHelper.CancelAndDispose(ref _Bar._cancellationSource, true);
                if (_Menu != null && _Bar._SymbolList == _Menu)
                {
                    _Bar.HideMenu();
                    return;
                }
                if (Node.IsTypeDeclaration() == false)
                {
                    var span = Node.FullSpan;
                    if (span.Contains(_Bar._SemanticContext.Position) && Node.SyntaxTree.FilePath == _Bar._SemanticContext.Document.FilePath)
                    {
                        _Bar._View.SelectNode(Node, Keyboard.Modifiers != ModifierKeys.Control);
                    }
                    else
                    {
                        Node.GetIdentifierToken().GetLocation().GoToSource();
                    }
                    return;
                }
                if (_Menu == null)
                {
                    _Menu = new SymbolList {
                        Container = _Bar._SymbolListContainer
                    };
                    _Menu.Header = new WrapPanel {
                        Orientation = Orientation.Horizontal,
                        Children    =
                        {
                            new ThemedButton(new ThemedMenuText(Node.GetDeclarationSignature(),  true)
                                             .SetGlyph(ThemeHelper.GetImage(Node.GetImageId())), null,
                                             () => _Bar._SemanticContext.RelocateDeclarationNode(Node).GetLocation().GoToSource())
                            {
                                BorderThickness = WpfHelper.TinyMargin,
                                Margin          = WpfHelper.SmallHorizontalMargin,
                                Padding         = WpfHelper.SmallHorizontalMargin,
                            },
                            (_FilterBox = new MemberFilterBox(_Menu)),
                        }
                    };
                    _Menu.Footer = new TextBlock {
                        Margin = WpfHelper.MenuItemMargin
                    }
                    .ReferenceProperty(TextBlock.ForegroundProperty, EnvironmentColors.SystemGrayTextBrushKey);
                    _Bar.SetupSymbolListMenu(_Menu);
                    await AddItemsAsync(Node, _Bar._cancellationSource.GetToken());

                    if (_Menu.Symbols.Count > 100)
                    {
                        ScrollViewer.SetCanContentScroll(_Menu, true);
                    }
                }
                else
                {
                    ((TextBlock)_Menu.Footer).Clear();
                    await RefreshItemsAsync(Node, _Bar._cancellationSource.GetToken());
                }
                var footer = (TextBlock)_Menu.Footer;

                if (Config.Instance.NaviBarOptions.MatchFlags(NaviBarOptions.CodeStatistics))
                {
                    if (_PartialCount > 1)
                    {
                        footer.Append(ThemeHelper.GetImage(KnownImageIds.OpenDocumentFromCollection))
                        .Append(_PartialCount);
                    }
                    footer.Append(ThemeHelper.GetImage(KnownImageIds.Code))
                    .Append(_Bar._View.TextSnapshot.GetLineSpan(Node.Span).Length);
                    footer.Visibility = Visibility.Visible;
                }
                else
                {
                    footer.Visibility = Visibility.Collapsed;
                }
                _Menu.ItemsControlMaxHeight = _Bar._View.ViewportHeight / 2;
                _Bar.ShowMenu(this, _Menu);
                _FilterBox?.FocusTextBox();
            }
Пример #9
0
 void ViewClosed(object sender, EventArgs e)
 {
     _View.Selection.SelectionChanged -= Update;
     CancellationHelper.CancelAndDispose(ref _cancellationSource, false);
     _View.Closed -= ViewClosed;
 }
Пример #10
0
        async void Update(object sender, EventArgs e)
        {
            HideMenu();
            CancellationHelper.CancelAndDispose(ref _cancellationSource, true);
            var cs = _cancellationSource;

            if (cs != null)
            {
                try {
                    await Update(cs.Token);
                }
                catch (OperationCanceledException) {
                    // ignore
                }
            }
            async Task Update(CancellationToken token)
            {
                var nodes = await UpdateModelAsync(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;
                    }
                    var n2 = (Items[i] as NodeItem).Node;
                    if (n2 == 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].IsTypeOrNamespaceDeclaration()) && _RootItem.FilterText.Length == 0)
                {
                    // clear type and namespace menu items if a type is changed
                    _RootItem.ClearSymbolList();
                }
                c = Items.Count;
                while (c > i)
                {
                    Items.RemoveAt(--c);
                }
                c = nodes.Count;
                while (i2 < c)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    var node = nodes[i2];
                    if (node.IsKind(SyntaxKind.NamespaceDeclaration))
                    {
                        _RootItem.SetText(node.GetDeclarationSignature());
                        ++i2;
                        continue;
                    }
                    bool highlight = node.IsMemberDeclaration();
                    var  newItem   = new NodeItem(this, node);
                    if (highlight)
                    {
                        newItem.FontWeight = FontWeights.Bold;
                        newItem.IsChecked  = true;
                    }
                    Items.Add(newItem);
                    ++i2;
                }
            }
        }