public SearchFilter(IVsSearchQuery searchQuery, IWpfTableControl control)
            {
                _searchTokens = SearchUtilities.ExtractSearchTokens(searchQuery);
                if (_searchTokens == null)
                {
                    _searchTokens = Array.Empty <IVsSearchToken>();
                }

                var newVisibleColumns = new List <ITableColumnDefinition>();

                foreach (var c in control.ColumnStates)
                {
                    if (c.IsVisible || ((c as ColumnState2)?.GroupingPriority > 0))
                    {
                        var definition = control.ColumnDefinitionManager.GetColumnDefinition(
                            c.Name
                            );
                        if (definition != null)
                        {
                            newVisibleColumns.Add(definition);
                        }
                    }
                }

                _visibleColumns = newVisibleColumns;
            }
示例#2
0
        public TableSearchFilter(IVsSearchQuery searchQuery, IWpfTableControl control)
        {
            this.tokens  = new List <string>();
            this.columns = new List <ITableColumnDefinition>(control.ColumnStates.Count);

            foreach (IVsSearchToken token in SearchUtilities.ExtractSearchTokens(searchQuery) ?? Array.Empty <IVsSearchToken>())
            {
                if (!string.IsNullOrEmpty(token.ParsedTokenText))
                {
                    this.tokens.Add(token.ParsedTokenText);
                }
            }

            foreach (ColumnState2 columnState in control.ColumnStates.OfType <ColumnState2>())
            {
                if (columnState.IsVisible || columnState.GroupingPriority > 0)
                {
                    ITableColumnDefinition definition = control.ColumnDefinitionManager.GetColumnDefinition(columnState.Name);
                    if (definition != null)
                    {
                        this.columns.Add(definition);
                    }
                }
            }
        }
示例#3
0
        public TableSearchFilter(IVsSearchQuery searchQuery, IWpfTableControl control)
        {
            _searchTokens = SearchUtilities.ExtractSearchTokens(searchQuery) ?? Array.Empty <IVsSearchToken>();

            var newVisibleColumns = control.ColumnStates
                                    .Where(c => c.IsVisible || (c as ColumnState2)?.GroupingPriority > 0)
                                    .Select(c => control.ColumnDefinitionManager.GetColumnDefinition(c.Name))
                                    .Where(definition => definition != null).ToList();

            _visibleColumns = newVisibleColumns;
        }
示例#4
0
            protected override void OnStartSearch()
            {
                // note that this will be run from a background thread. Must context switch to the UI thread to manipulate the tree.
                // use ThreadHelper.Generic.BeginInvoke for that

                TreeView      treeView    = modelExplorer.ObjectModelBrowser;
                List <string> searchTexts = SearchUtilities.ExtractSearchTokens(SearchQuery).Select(token => token.ParsedTokenText).ToList();

                if (!searchTexts.Any())
                {
                    ThreadHelper.Generic.BeginInvoke(() =>
                    {
                        // ReSharper disable once UnusedVariable
                        using (WaitCursor w = new WaitCursor())
                        {
                            treeView.SelectedNode = null;
                            treeView.BeginUpdate();
                            modelExplorer.RefreshBrowserView();
                            treeView.CollapseAll();
                            treeView.EndUpdate();
                        }
                    });
                }
                else
                {
                    ThreadHelper.Generic.BeginInvoke(() =>
                    {
                        // ReSharper disable once UnusedVariable
                        using (WaitCursor w = new WaitCursor())
                        {
                            treeView.SelectedNode = null;
                            treeView.BeginUpdate();
                            modelExplorer.RefreshBrowserView();
                            PerformSearch(treeView);
                            treeView.EndUpdate();
                        }
                    });
                }

                SearchResults = (uint)treeView.GetAllNodes().Count(n => n is ExplorerTreeNode explorerNode && explorerNode.RepresentedElement != null);

                // Call to base will report completion
                base.OnStartSearch();
            }
示例#5
0
            private void PerformSearch(TreeView treeView)
            {
                List <string> searchTexts = SearchUtilities.ExtractSearchTokens(SearchQuery).Select(token => token.ParsedTokenText).ToList();

                // if nothing to search for, everything's a hit
                if (!searchTexts.Any())
                {
                    modelExplorer.ClearSearch();

                    return;
                }

                treeView.BeginUpdate();

                // prune tree to remove non-hits. We don't search the diagram branch. Work is depth-first

                // 1) remove attribute and enum value nodes that aren't matches. This removes attribute group nodes when necessary
                List <ExplorerTreeNode> leafNodes = treeView.GetAllNodes()
                                                    .OfType <ExplorerTreeNode>()
                                                    .Where(n => n.RepresentedElement is ModelAttribute ||
                                                           n.RepresentedElement is ModelEnumValue)
                                                    .ToList();

                foreach (ExplorerTreeNode node in leafNodes.Where(node => searchTexts.All(t => node.Text.IndexOf(t, StringComparison.CurrentCultureIgnoreCase) == -1)))
                {
                    Remove(node);
                }

                // 2) there are cases where a class has no attributes and an enum has no values.
                //    Find those group nodes and remove them, since we couldn't get to them via their child nodes
                List <EFModelRoleGroupTreeNode> emptyChildGroupNodes = treeView.GetAllNodes()
                                                                       .OfType <EFModelRoleGroupTreeNode>()
                                                                       .Where(groupNode => groupNode.Parent is ExplorerTreeNode elementNode &&
                                                                              (elementNode.RepresentedElement is ModelClass ||
                                                                               elementNode.RepresentedElement is ModelEnum) &&
                                                                              groupNode.Nodes.Count == 0)
                                                                       .ToList();

                foreach (EFModelRoleGroupTreeNode emptyChildGroupNode in emptyChildGroupNodes)
                {
                    emptyChildGroupNode.Remove();
                }

                // 3) remove childless class and enum nodes that aren't matches.
                //    Ignore those with children since we can't remove them - their children are matches
                List <ExplorerTreeNode> classNodes = treeView.GetAllNodes()
                                                     .OfType <ExplorerTreeNode>()
                                                     .Where(elementNode => (elementNode.RepresentedElement is ModelClass ||
                                                                            elementNode.RepresentedElement is ModelEnum) &&
                                                            elementNode.Nodes.Count == 0)
                                                     .ToList();

                foreach (ExplorerTreeNode node in classNodes.Where(node => searchTexts.All(t => node.Text.IndexOf(t, StringComparison.CurrentCultureIgnoreCase) == -1)))
                {
                    Remove(node);
                }

                // 4) update the text on all group nodes left in the tree (except for the root)
                List <EFModelRoleGroupTreeNode> groupNodes = treeView.GetAllNodes()
                                                             .OfType <EFModelRoleGroupTreeNode>()
                                                             .Where(n => n != treeView.Nodes[0])
                                                             .ToList();

                foreach (EFModelRoleGroupTreeNode groupNode in groupNodes)
                {
                    groupNode.Text = groupNode.GetNodeText();
                }

                treeView.ExpandAll();

                treeView.EndUpdate();
            }