示例#1
0
        private static void runDelegateMenu()
        {
            const bool v_IsMainMenu = false;
            MethodsForMenusDelegates methodsForMenusDelegates = new MethodsForMenusDelegates();

            MenuDelegates.MainMenu mainMenuDelegates = new MenuDelegates.MainMenu("Delegates Main Menu");

            MenuDelegates.SubMenu subMenuDateAndTimeDelegate      = new MenuDelegates.SubMenu("Show Date/Time", v_IsMainMenu);
            MenuDelegates.SubMenu subMenuVersionAndDigitsDelegate = new MenuDelegates.SubMenu("Version and Digits", v_IsMainMenu);

            MenuDelegates.MenuItemExecutable showDateDelegate = new MenuDelegates.MenuItemExecutable("Show Date");
            showDateDelegate.MenuItemClicked += methodsForMenusDelegates.ShowDate;
            MenuDelegates.MenuItemExecutable showTimeDelegate = new MenuDelegates.MenuItemExecutable("Show Time");
            showTimeDelegate.MenuItemClicked += methodsForMenusDelegates.ShowTime;
            MenuDelegates.MenuItemExecutable countDigitsDelegate = new MenuDelegates.MenuItemExecutable("Count Digits");
            countDigitsDelegate.MenuItemClicked += methodsForMenusDelegates.CountDigits;
            MenuDelegates.MenuItemExecutable showVersionDelegate = new MenuDelegates.MenuItemExecutable("Show Version");
            showVersionDelegate.MenuItemClicked += methodsForMenusDelegates.ShowVersion;

            subMenuDateAndTimeDelegate.AddItemToSubMenu(showDateDelegate);
            subMenuDateAndTimeDelegate.AddItemToSubMenu(showTimeDelegate);
            subMenuVersionAndDigitsDelegate.AddItemToSubMenu(countDigitsDelegate);
            subMenuVersionAndDigitsDelegate.AddItemToSubMenu(showVersionDelegate);

            mainMenuDelegates.AddMenuItemToMainMenu(subMenuDateAndTimeDelegate);
            mainMenuDelegates.AddMenuItemToMainMenu(subMenuVersionAndDigitsDelegate);
            mainMenuDelegates.Show();
        }
示例#2
0
        public void Show()
        {
            int     selection;
            SubMenu currentMenuItem = m_Menu;

            Console.Clear();

            //selection = m_Menu.ShowMenuAndGetSelectionUser(m_Level);
            selection = (int)m_Menu.Select(m_Level, ref currentMenuItem);

            while (true)
            {
                Console.Clear();
                //check for exit selection
                if (m_Level == 1 && selection == 0)
                {
                    break;
                }

                //check for back selection
                if ((m_Level != 1 && selection == 0))
                {
                    m_Level--;
                    currentMenuItem = (SubMenu)currentMenuItem.GetMenuItem(selection);
                }
                else
                {
                    if (currentMenuItem.GetMenuItem(selection) is SubMenu)
                    {
                        currentMenuItem = (SubMenu)currentMenuItem.GetMenuItem(selection);

                        if (selection == 0)
                        {
                            m_Level--;
                        }
                        else
                        {
                            m_Level++;
                        }
                    }
                    else if (currentMenuItem.GetMenuItem(selection) is FunctionItem)
                    {
                        ((FunctionItem)currentMenuItem.GetMenuItem(selection)).Select(m_Level, ref currentMenuItem);
                    }
                }

                selection = (int)((SubMenu)currentMenuItem).Select(m_Level, ref currentMenuItem);
            }

            Console.WriteLine("Bye bye");
            Console.ReadLine();
        }
示例#3
0
        public override void ActionWhenChoose()
        {
            Console.Clear();
            int    indexOfItemInMenu = MenuThatItemBelongsTo.MenuItems.IndexOf(this);
            string SubMenuName       = string.Format("{0}. {1}", indexOfItemInMenu + 1, ItemName);

            SubMenu subMenuToDisplayWhenChoose = new SubMenu(SubMenuName, m_MenuItemsToShow)
            {
                ParentMenu = MenuThatItemBelongsTo
            };

            subMenuToDisplayWhenChoose.Show();
        }
示例#4
0
        public static void Show(SubMenu i_Menu)
        {
            int userChoice = -1;

            while (!userChoice.Equals(k_ExitOrBack))
            {
                userChoice = UserInteraction.printManager(i_Menu);

                if (!userChoice.Equals(k_ExitOrBack))
                {
                    i_Menu.MenuNodes[userChoice - k_MenuOffset].OnClick();
                }
            }
        }
示例#5
0
        private static void printMenu(SubMenu i_Menu)
        {
            int index = 1;

            Console.Clear();
            Console.WriteLine(i_Menu.Title + Environment.NewLine);
            foreach (MenuNode item in i_Menu.MenuNodes)
            {
                Console.WriteLine("{0}. {1}", index, item.Title);
                index++;
            }

            Console.WriteLine("0. {0}", i_Menu.ParentMenu == null ? k_ExitMessage : k_BackMessage);
            Console.WriteLine("Please Choose the appropriate menu option, or 0 to {0}.", i_Menu.ParentMenu == null ? k_ExitMessage : k_BackToPreviousMenuMessage);
        }
示例#6
0
        private static int printManager(SubMenu i_Menu)
        {
            string userInput;
            int    validInput;

            printMenu(i_Menu);
            userInput = Console.ReadLine();
            while (!isValidMenuOption(userInput, i_Menu.MenuNodes.Count, out validInput))
            {
                Console.WriteLine("Invalid Input. Return to menu options.");
                Thread.Sleep(2000);
                printMenu(i_Menu);
                userInput = Console.ReadLine();
            }

            return(validInput);
        }
 public override int?Select(int i_Level, ref SubMenu i_SubMenu)
 {
     i_SubMenu = this;
     return(ShowMenuAndGetSelectionUser(i_Level));
 }
示例#8
0
 public FinalButton(string o_Name, SubMenu o_Parent) : base(o_Name, o_Parent)
 {
 }
示例#9
0
 public MainMenu(string i_MenuTitle)
 {
     m_ListOfMenuNodes = new SubMenu(i_MenuTitle);
 }
示例#10
0
 public SubMenu(string o_Name, SubMenu o_Parent) : base(o_Name, o_Parent)
 {
 }
示例#11
0
 public MainMenu()
 {
     m_Menu = new SubMenu("MainMenu", null);
 }
示例#12
0
 // Constructor for new main menu
 public MainMenu()
 {
     this.m_MainMenuList = new SubMenu("Main Menu");
 }
示例#13
0
 public MainMenu(int i_Level, string i_ItemName, SubMenu i_PreviousMenu, List <MenuItem> i_MenuItems)
     : base(i_Level, i_ItemName, i_PreviousMenu, i_MenuItems)
 {
 }
示例#14
0
        /// <summary>
        /// This method adds a new sub menu to the current menu.
        /// </summary>
        /// <param name="i_menuTitle"> The new sub menu name.</param>
        public void AddMenuItemMenu(string i_menuTitle)
        {
            GeneralMenu newMenuItem = new SubMenu(i_menuTitle, this);

            m_menu.Add(newMenuItem);
        }
示例#15
0
 protected MenuItem(string i_MenuItemName, SubMenu i_ParentItem)
 {
     m_ItemText     = i_MenuItemName;
     m_PreviousMenu = i_ParentItem;
 }
示例#16
0
 public override int?Select(int i_Level, ref SubMenu i_SubMenu)
 {
     m_SelectFunctionDelegate.Invoke();
     return(null);
 }
示例#17
0
文件: SubMenu.cs 项目: omerha/csharp4
 public SubMenu(int i_Level, string i_ItemName, SubMenu i_PreviousMenu, List <MenuItem> i_MenuItems) : base(i_ItemName, i_PreviousMenu)
 {
     MenuItems = i_MenuItems;
     Level     = i_Level;
 }
示例#18
0
 public MenuItemAction(string i_MenuItemName, SubMenu i_ParentItem)
     : base(i_MenuItemName, i_ParentItem)
 {
 }
示例#19
0
 public abstract int?Select(int i_Level, ref SubMenu i_SubMenu);
示例#20
0
 public MainMenu(string i_Titel)
 {
     m_SubMenuItem = new SubMenu(i_Titel);
     m_SubMenuItem.ListOfMenuItems[k_ExitOption].Title = "Exit";
 }
示例#21
0
 public SubMenu(string i_Title, SubMenu i_PreviousMenu)
     : base(i_Title)
 {
     m_MainMenu = new MainMenu(i_Title);
     m_MainMenu.ChangeExitName(eBackType.Back.ToString());
 }