Esempio n. 1
0
 public Menu(MenuBar host, int x, int y, MenuBarItem barItems) : base(MakeFrame(x, y, barItems.Children))
 {
     this.barItems = barItems;
     this.host     = host;
     ColorScheme   = Colors.Menu;
     CanFocus      = true;
 }
Esempio n. 2
0
 /// <summary>
 /// Initialize a context menu with menu items.
 /// </summary>
 /// <param name="x">The left position.</param>
 /// <param name="y">The top position.</param>
 /// <param name="menuItems">The menu items.</param>
 public ContextMenu(int x, int y, MenuBarItem menuItems)
 {
     if (IsShow)
     {
         Hide();
     }
     MenuItems = menuItems;
     Position  = new Point(x, y);
 }
Esempio n. 3
0
        internal void OpenMenu(int index, int sIndex = -1, MenuBarItem subMenu = null)
        {
            isMenuOpening = true;
            OnOpenMenu?.Invoke(this, null);
            int pos = 0;

            switch (subMenu)
            {
            case null:
                lastFocused = lastFocused ?? SuperView.MostFocused;
                if (openSubMenu != null)
                {
                    CloseMenu(false, true);
                }
                if (openMenu != null)
                {
                    SuperView.Remove(openMenu);
                }

                for (int i = 0; i < index; i++)
                {
                    pos += Menus [i].Title.Length + 2;
                }
                openMenu        = new Menu(this, pos, 1, Menus [index]);
                openCurrentMenu = openMenu;
                openCurrentMenu.previousSubFocused = openMenu;
                SuperView.Add(openMenu);
                SuperView.SetFocus(openMenu);
                break;

            default:
                if (openSubMenu == null)
                {
                    openSubMenu = new List <Menu> ();
                }
                if (sIndex > -1)
                {
                    RemoveSubMenu(sIndex);
                }
                else
                {
                    var last = openSubMenu.Count > 0 ? openSubMenu.Last() : openMenu;
                    openCurrentMenu = new Menu(this, last.Frame.Left + last.Frame.Width, last.Frame.Top + 1 + last.current, subMenu);
                    openCurrentMenu.previousSubFocused = last.previousSubFocused;
                    openSubMenu.Add(openCurrentMenu);
                    SuperView.Add(openCurrentMenu);
                }
                selectedSub = openSubMenu.Count - 1;
                SuperView?.SetFocus(openCurrentMenu);
                break;
            }
            isMenuOpening = false;
            isMenuClosed  = false;
        }
Esempio n. 4
0
        // Activates the menu, handles either first focus, or activating an entry when it was already active
        // For mouse events.
        internal void Activate(int idx, int sIdx = -1, MenuBarItem subMenu = null)
        {
            selected    = idx;
            selectedSub = sIdx;
            if (openMenu == null)
            {
                previousFocused = SuperView.Focused;
            }

            OpenMenu(idx, sIdx, subMenu);
            SetNeedsDisplay();
        }
Esempio n. 5
0
 public Menu(MenuBar host, int x, int y, MenuBarItem barItems) : base(MakeFrame(x, y, barItems.Children))
 {
     this.barItems = barItems;
     this.host     = host;
     current       = -1;
     for (int i = 0; i < barItems.Children.Length; i++)
     {
         if (barItems.Children[i] != null)
         {
             current = i;
             break;
         }
     }
     ColorScheme = Colors.Menu;
     CanFocus    = true;
 }
Esempio n. 6
0
        int GetSubMenuIndex(MenuBarItem subMenu)
        {
            int pos = -1;

            if (this != null && Subviews.Count > 0)
            {
                Menu v = null;
                foreach (var menu in Subviews)
                {
                    if (((Menu)menu).barItems == subMenu)
                    {
                        v = (Menu)menu;
                    }
                }
                if (v != null)
                {
                    pos = Subviews.IndexOf(v);
                }
            }

            return(pos);
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new <see cref="T:Terminal.Gui.MenuItem"/>.
 /// </summary>
 /// <param name="title">Title for the menu item.</param>
 /// <param name="subMenu">The menu sub-menu.</param>
 public MenuItem(ustring title, MenuBarItem subMenu) : this(title, "", null)
 {
     SubMenu       = subMenu;
     IsFromSubMenu = true;
 }
Esempio n. 8
0
 /// <summary>
 /// Initialize a context menu with menu items from a host <see cref="View"/>.
 /// </summary>
 /// <param name="host">The host view.</param>
 /// <param name="menuItems">The menu items.</param>
 public ContextMenu(View host, MenuBarItem menuItems) :
     this(host.Frame.X, host.Frame.Y, menuItems)
 {
     Host = host;
 }