Exemple #1
0
        public MenuNode AddSubNode(string label)
        {
            MenuNode subNode = new MenuNode(label, this);

            SubNodes.Add(subNode);
            return(subNode);
        }
Exemple #2
0
        public bool Select(int selection, bool ignoreInvalid)
        {
            if (selection < 0)
            {
                if (ignoreInvalid)
                {
                    return(true);
                }
                throw new ArgumentOutOfRangeException("selection",
                                                      "The selected menu item index must not be negative");
            }

            if (selection > current.EntryCount)
            {
                if (ignoreInvalid)
                {
                    return(true);
                }
                throw new ArgumentOutOfRangeException("selection",
                                                      "The selected menu item index exceeds the number of entries");
            }

            if (selection == 0 && current.Parent == null)
            {
                if (ignoreInvalid)
                {
                    return(true);
                }
                throw new ArgumentOutOfRangeException("selection",
                                                      "This is node does not have a parent node");
            }

            if (selection == 0)
            {
                current = current.Parent;
            }
            else if (selection <= current.EndNodes.Count)
            {
                current.EndNodes[selection - 1].Function?.Invoke();
                return(false);
            }
            else
            {
                current = current.SubNodes[selection - 1 - current.EndNodes.Count];
            }

            return(true);
        }
Exemple #3
0
 public MenuNode(string label, MenuNode parent)
 {
     Label   = label;
     Parent  = parent;
     current = this;
 }
Exemple #4
0
 public MenuNode(string label)
 {
     Label   = label;
     current = this;
 }