Пример #1
0
        protected virtual void ShowMenu()
        {
            if (this.Parents <SystemWindow>().FirstOrDefault() == null)
            {
                throw new Exception("You cannot show the menu on a Menu unless it has a parent (has been added to a GuiWidget).");
            }

            var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Name = "_topToBottom",
            };

            foreach (MenuItem menu in MenuItems)
            {
                menu?.ClearRemovedFlag();
                topToBottom.AddChild(menu);
            }

            DropDownContainer = new DropDownContainer(MenuItems, topToBottom, this, MenuDirection, maxHeight, AlignToRightEdge, true)
            {
                BorderWidth     = MenuItemsBorderWidth,
                BorderColor     = this.PopupBorderColor,
                BackgroundColor = MenuItemsBackgroundColor
            };

            DropDownContainer.Closed += DropListItems_Closed;
            DropDownContainer.Focus();
        }
Пример #2
0
        protected virtual void DropListItems_Closed(object sender, EventArgs e)
        {
            var dropListItems = (DropDownContainer)sender;

            dropListItems.Closed -= DropListItems_Closed;
            IsOpen = false;

            DropDownContainer = null;
        }
Пример #3
0
        protected override void ShowMenu()
        {
            base.ShowMenu();

            if (selectedIndex >= 0)
            {
                var selectedMenuItem = MenuItems[selectedIndex];

                // Scroll the selected item into view
                DropDownContainer.ScrollIntoView(selectedMenuItem);

                // Highlight the selected item
                var statesView = selectedMenuItem.Children <MenuItemStatesView>().FirstOrDefault();
                if (statesView != null)
                {
                    statesView.Highlighted = true;
                }
            }
        }
Пример #4
0
        private void ApplyFilter()
        {
            string text = listFilterText.ToString();

            mainControlText.Text = text;

            // Remove existing highlight
            highlightedItem?.ModifyStatesView(showHighlight: false);

            // Find menu items starting with the given filter text
            var firstMatchedItem = MenuItems.Where(m => m.Text.IndexOf(text, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();

            if (firstMatchedItem != null)
            {
                // Highlight our new match
                highlightedItem  = firstMatchedItem;
                highLightedIndex = MenuItems.IndexOf(highlightedItem);
                highlightedItem.ModifyStatesView(showHighlight: true);

                // and scroll into view
                DropDownContainer.ScrollIntoView(highlightedItem);
            }
        }
Пример #5
0
        protected override void ShowMenu()
        {
            if (this.Parent == null)
            {
                return;
            }
            base.ShowMenu();

            if (selectedIndex >= MenuItems.Count - 1)
            {
                selectedIndex = MenuItems.Count - 1;
            }

            // Show and highlight the previously selected or the first item
            if (selectedIndex >= 0)
            {
                var selectedMenuItem = MenuItems[selectedIndex];

                // Scroll the selected item into view
                DropDownContainer.ScrollIntoView(selectedMenuItem);

                // Highlight the selected item
                highlightedItem = selectedMenuItem;
                highlightedItem.ModifyStatesView(showHighlight: true);
            }
            else if (MenuItems.Count > 0)
            {
                highlightedItem = MenuItems[0];
                highlightedItem?.ModifyStatesView(showHighlight: true);
            }

            listFilterText = new StringBuilder();

            DropDownContainer.KeyPressed += (s, e) =>
            {
                listFilterText.Append(e.KeyChar);
                ApplyFilter();
            };

            DropDownContainer.KeyUp += (s, e) =>
            {
                switch (e.KeyCode)
                {
                case Keys.Up:
                    if (highLightedIndex > 0)
                    {
                        highLightedIndex--;
                    }

                    break;

                case Keys.Down:
                    if (highLightedIndex < this.MenuItems.Count - 1)
                    {
                        highLightedIndex++;
                    }

                    break;
                }

                // Remove existing
                highlightedItem?.ModifyStatesView(showHighlight: false);

                highlightedItem = this.MenuItems[highLightedIndex];
                highlightedItem?.ModifyStatesView(showHighlight: true);

                // if (!highlightedItem.Visible) // only scroll if clipped
                {
                    DropDownContainer.ScrollIntoView(highlightedItem);
                }

                this.Invalidate();
            };

            DropDownContainer.KeyDown += (s, keyEvent) =>
            {
                switch (keyEvent.KeyCode)
                {
                case Keys.Escape:
                    listFilterText = new StringBuilder();
                    DropDownContainer.CloseMenu();
                    break;

                case Keys.Enter:

                    if (highlightedItem != null)
                    {
                        SelectedIndex = MenuItems.IndexOf(highlightedItem);
                        DropDownContainer.CloseMenu();
                        listFilterText = null;
                    }

                    break;

                case Keys.Back:
                    if (listFilterText != null && listFilterText.Length > 0)
                    {
                        listFilterText.Length -= 1;
                    }

                    keyEvent.Handled          = true;
                    keyEvent.SuppressKeyPress = true;

                    ApplyFilter();

                    break;
                }
            };

            DropDownContainer.Closed += (s, e) =>
            {
                mainControlText.Text = selectedIndex == -1 ? this.noSelectionString : MenuItems[SelectedIndex].Text;
                this.Focus();
            };
        }