コード例 #1
0
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            CompletionListControl = new CompletionListControl(this);

            this.FindControl <ScrollViewer>("ItemsScrollViewer").Content = CompletionListControl;
        }
コード例 #2
0
        public async Task SetSelectedIndex(int index)
        {
            CompletionListControl.SelectedIndex = index;
            CompletionListControl.InvalidateVisual();

            if (!UpdatingItems && CompletionListControl.SelectedIndex >= 0)
            {
                if (!CompletionListControl.Hidden[CompletionListControl.SelectedIndex])
                {
                    CompletionItem item = CompletionListControl.Items[CompletionListControl.SelectedIndex].item;
                    await GetSymbolComments(item);
                }
                else
                {
                    this.FindControl <Border>("DocumentationBorder").IsVisible = false;
                    await UpdateScrollViewer();
                }
            }
        }
コード例 #3
0
        private async Task UpdateFilter()
        {
            bool[] filters = new bool[FilterButtons.Count];

            for (int i = 0; i < FilterButtons.Count; i++)
            {
                filters[i] = FilterButtons[i].IsVisible && FilterButtons[i].IsChecked == true;
            }

            bool[] foundFilters            = new bool[FilterButtons.Count];
            bool[] foundButFilteredFilters = new bool[FilterButtons.Count];

            CompletionListControl.Filter = FilterText;

            string filter = FilterText?.Trim();

            int index             = 0;
            int firstVisibleIndex = -1;
            int visibleCount      = 0;
            int firstExactMatch   = -1;

            if (!filters.Any(a => a))
            {
                for (int i = 0; i < filters.Length; i++)
                {
                    filters[i] = true;
                }
            }

            for (int i = 0; i < CompletionListControl.Items.Count; i++)
            {
                CompletionItem item = CompletionListControl.Items[i].item;

                int foundIndex = -1;

                if (item.Properties.ContainsKey("SymbolKind"))
                {
                    switch ((SymbolKind)(int.Parse(item.Properties["SymbolKind"])))
                    {
                    case SymbolKind.Property:
                        CompletionListControl.Hidden[i] = !filters[8];
                        foundIndex = 8;
                        break;

                    case SymbolKind.Event:
                        CompletionListControl.Hidden[i] = !filters[7];
                        foundIndex = 7;
                        break;

                    case SymbolKind.Field:
                        CompletionListControl.Hidden[i] = !filters[6];
                        foundIndex = 6;
                        break;

                    case SymbolKind.Method:
                        CompletionListControl.Hidden[i] = !filters[9];
                        foundIndex = 9;
                        break;

                    case SymbolKind.NamedType:
                    case SymbolKind.DynamicType:
                    case SymbolKind.ArrayType:
                    case SymbolKind.PointerType:
                        if (item.Tags.Contains(WellKnownTags.Class))
                        {
                            CompletionListControl.Hidden[i] = !filters[1];
                            foundIndex = 1;
                        }
                        else if (item.Tags.Contains(WellKnownTags.Delegate))
                        {
                            CompletionListControl.Hidden[i] = !filters[5];
                            foundIndex = 5;
                        }
                        else if (item.Tags.Contains(WellKnownTags.Enum))
                        {
                            CompletionListControl.Hidden[i] = !filters[4];
                            foundIndex = 4;
                        }
                        else if (item.Tags.Contains(WellKnownTags.Structure))
                        {
                            CompletionListControl.Hidden[i] = !filters[2];
                            foundIndex = 2;
                        }
                        else if (item.Tags.Contains(WellKnownTags.Interface))
                        {
                            CompletionListControl.Hidden[i] = !filters[3];
                            foundIndex = 3;
                        }
                        else
                        {
                            CompletionListControl.Hidden[i] = !filters[12];
                            foundIndex = 12;
                        }
                        break;

                    case SymbolKind.Namespace:
                        CompletionListControl.Hidden[i] = !filters[0];
                        foundIndex = 0;
                        break;

                    case SymbolKind.Local:
                    case SymbolKind.Parameter:
                        CompletionListControl.Hidden[i] = !filters[10];
                        foundIndex = 10;
                        break;

                    default:
                        CompletionListControl.Hidden[i] = !filters[12];
                        foundIndex = 12;
                        break;
                    }
                }
                else if (item.Tags.Contains(WellKnownTags.Keyword))
                {
                    CompletionListControl.Hidden[i] = !filters[11];
                    foundIndex = 11;
                }
                else if (item.Tags.Contains(WellKnownTags.Local) || item.Tags.Contains(WellKnownTags.Parameter))
                {
                    CompletionListControl.Hidden[i] = !filters[10];
                    foundIndex = 10;
                }
                else if (item.Tags.Contains(WellKnownTags.Class))
                {
                    CompletionListControl.Hidden[i] = !filters[1];
                    foundIndex = 1;
                }
                else if (item.Tags.Contains(WellKnownTags.Enum))
                {
                    CompletionListControl.Hidden[i] = !filters[4];
                    foundIndex = 4;
                }
                else
                {
                    CompletionListControl.Hidden[i] = !filters[12];
                    foundIndex = 12;
                }

                if (string.IsNullOrEmpty(filter))
                {
                    foundButFilteredFilters[foundIndex] = true;
                    //CompletionListControl.Hidden[i] |= false;
                }
                else if (item.FilterText.StartsWith(filter, StringComparison.OrdinalIgnoreCase))
                {
                    foundButFilteredFilters[foundIndex] = true;
                    //CompletionListControl.Hidden[i] |= false;
                }
                else
                {
                    CompletionListControl.Hidden[i] = true;
                }

                if (!CompletionListControl.Hidden[i])
                {
                    foundFilters[foundIndex] = true;
                }


                if (firstVisibleIndex < 0 && !CompletionListControl.Hidden[i])
                {
                    firstVisibleIndex = index;
                }

                if (!CompletionListControl.Hidden[i])
                {
                    visibleCount++;

                    if (!string.IsNullOrEmpty(filter) && item.FilterText.StartsWith(filter) && firstExactMatch < 0)
                    {
                        firstExactMatch = index;
                    }
                }

                index++;
            }

            for (int i = 0; i < foundFilters.Length; i++)
            {
                ((Control)this.FindControl <StackPanel>("FilterContainer").Children[i]).IsEnabled = foundFilters[i] || foundButFilteredFilters[i];

                if (((Control)this.FindControl <StackPanel>("FilterContainer").Children[i]).IsEnabled)
                {
                    ((Control)this.FindControl <StackPanel>("FilterContainer").Children[i]).Opacity = 1;
                }
                else
                {
                    ((Control)this.FindControl <StackPanel>("FilterContainer").Children[i]).Opacity = 0.25;
                }
            }


            if ((SelectedIndex < 0 || (filter != null && !CompletionListControl.Items[CompletionListControl.SelectedIndex].item.FilterText.StartsWith(filter))) && firstExactMatch > 0)
            {
                await SetSelectedIndex(firstExactMatch);
            }
            else if ((SelectedIndex < 0 || CompletionListControl.Hidden[CompletionListControl.SelectedIndex]) && firstVisibleIndex >= 0)
            {
                await SetSelectedIndex(firstVisibleIndex);
            }

            if (!AnchorOnTop)
            {
                this.Height = Math.Min(this.MaxWindowHeight, visibleCount * 20 + 33);
            }
            else
            {
                this.Height = Math.Min(this.MaxWindowHeight, visibleCount * 20 + 33);
                double prevX = ((TranslateTransform)this.RenderTransform).X;

                this.RenderTransform = new TranslateTransform(prevX, this.TopAnchor - this.Height);
            }

            VisibleItems = visibleCount;

            await UpdateScrollViewer();

            if (visibleCount == 0)
            {
                this.IsVisible = false;
            }

            CompletionListControl.InvalidateMeasure();

            await SetSelectedIndex(SelectedIndex);
        }