Ejemplo n.º 1
0
        public void ShowMenu()
        {
            IDialog   dialog   = uiFactory.CreateDialog();
            IMenuView menuView = uiFactory.CreateMenuView();
            var       menu     = commands.Keys.ToList();

            menu.Add("UNDO");
            menu.Add("EXIT");

            while (true)
            {
                var result = menuView.ShowMenu(menu);
                int i      = Int32.Parse(result);

                if (i <= commands.Count)
                {
                    if (commands.Values.ToList()[i - 1] is IUndoableCommand)
                    {
                        processor.Execute(((commands.Values.ToList()[i - 1]) as IUndoableCommand).Clone() as IUndoableCommand);
                    }
                    else
                    {
                        processor.Execute(commands.Values.ToList()[i - 1]);
                    }
                }
                else if (i == commands.Count + 1)
                {
                    processor.Undo();
                }
                else if (i == commands.Count + 2)
                {
                    return;
                }
            }
        }
        public void ShowMenu()
        {
            IDialogView dialogView = uiFactory.CreateDialogView();

            dialogView.ShowMessage("MENU");
            IMenuView     menuView  = uiFactory.CreateMenuView();
            List <string> menuItems = commands.Keys.ToList();

            menuItems.Add("Exit");

            while (true)
            {
                string result       = menuView.ShowMenu(menuItems);
                int    parsedResult = -1;
                if (int.TryParse(result, out parsedResult))
                {
                    if (parsedResult <= commands.Count)
                    {
                        commandProcessor.Execute(commands.Values.ToList().ElementAt(parsedResult - 1));
                    }
                    else if (parsedResult == commands.Count + 1)
                    {
                        dialogView.ShowMessage("Exiting");
                        return;
                    }
                    else
                    {
                        dialogView.ShowMessage("No such menu item");
                    }
                }
            }
        }