コード例 #1
0
        private int addItem(int i_ParentHashCode, string i_TitleOfNewNode, Action i_ToInvoke = null)
        {
            int newNodeHashCode = -1;

            if (m_MenuItems.ContainsKey(i_ParentHashCode))
            {
                try
                {
                    MenuItem newNode = null;
                    if (i_ToInvoke == null)
                    {
                        newNode = new InnerItem(i_TitleOfNewNode, m_MenuItems[i_ParentHashCode]);
                    }
                    else
                    {
                        newNode = new LeafItem(i_TitleOfNewNode, m_MenuItems[i_ParentHashCode], i_ToInvoke);
                    }

                    newNodeHashCode = newNode.GetHashCode();
                    (m_MenuItems[i_ParentHashCode] as InnerItem).Add(newNode);
                    m_MenuItems[newNodeHashCode] = newNode;
                }
                catch
                {
                    throw new ArgumentException(string.Format("Error:Could not add new menu under {0} ", i_ParentHashCode));
                }
            }
            else
            {
                throw new ArgumentException(string.Format("Error:Could not found {0} ", i_ParentHashCode));
            }

            return(newNodeHashCode);
        }
コード例 #2
0
        private void handleChoice(int i_Choice)
        {
            Console.Clear();
            InnerItem currInnerItem = m_CurrentItem as InnerItem;

            if (i_Choice == k_ExitBackSerialNumber)
            {
                if (m_CurrentItem.Level == 0)
                {
                    m_ExitProgram = true;
                }
                else
                {
                    m_CurrentItem = m_CurrentItem.Parent;
                }
            }
            else
            {
                if (currInnerItem.Children[i_Choice] is InnerItem)
                {
                    m_CurrentItem = currInnerItem.Children[i_Choice];
                }
                else
                {
                    (currInnerItem.Children[i_Choice] as LeafItem).Clicked();
                }
            }
        }