Esempio n. 1
0
        private bool SelectLesson()
        {
            SelectedLesson               = string.Empty;
            OptionDialog                 = new SelectionDialog();
            OptionDialog.Text            = "Select Lessons";
            OptionDialog.ShowDescription = true;
            OptionDialog.ItemsBackColor  = Color.LightSkyBlue;
            OptionDialog.ItemsForeColor  = Color.DarkBlue;

            if (Directory.Exists(LessonBasePath))
            {
                Debug.WriteLine("Loading lessons from " + LessonBasePath);
                string[] lessonFolders = Directory.GetDirectories(LessonBasePath);
                Dictionary <string, string> lessons = new Dictionary <string, string>();
                foreach (string ptrPath in lessonFolders)
                {
                    //Skip hidden folders
                    DirectoryInfo ptrDir = new DirectoryInfo(ptrPath);
                    if ((ptrDir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                    {
                        continue;
                    }
                    lessons.Add(ptrPath.Replace(LessonBasePath, ""), ptrPath);
                }

                Debug.WriteLine("Found " + lessons.Count.ToString() + " lessons.");
                foreach (string ptrKey in lessons.Keys)
                {
                    Debug.WriteLine("> " + ptrKey.ToString());
                }

                //Select lesson
                SelectionDialogItem ptrMenuItem;
                OptionDialog.ClearItems();
                foreach (string ptrItem in lessons.Keys)
                {
                    ptrMenuItem = OptionDialog.AddItem(ptrItem);
                    if (Directory.GetFiles(LessonBasePath + ptrItem).Length == 0)
                    {
                        OptionDialog.DisableItem(ptrItem);
                    }
                    else
                    {
                        string[] files = Directory.GetFiles(LessonBasePath + ptrItem);
                        foreach (string ptrFile in files)
                        {
                            if (IsImageTypeSupported(ptrFile))
                            {
                                continue;
                            }
                            ptrMenuItem.DescriptionImage = Image.FromFile(ptrFile);
                            break;
                        }
                    }
                }
            }

            //Add additional system menu
            OptionDialog.AllowToCancel    = true;
            OptionDialog.CancelButtonText = "Back to Main Menu";

            SelectedLesson = null;
            if (OptionDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SelectedLesson = OptionDialog.SelectedItem;
                LoadSelectedLesson();
                CaseSensitive = false;
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        public void ShowMenuDialog()
        {
            if (Busy)
            {
                return;
            }
            while (true)
            {
                OnMenuLoad();
                if (string.IsNullOrEmpty(SelectedLesson))
                {
                    //Main Menu
                    OptionDialog.Title           = "Main Menu - Choose An Activity.";
                    OptionDialog.ShowDescription = true;
                    OptionDialog.ClearItems();
                    OptionDialog.ItemsBackColor   = Color.FromArgb(192, 255, 192);
                    OptionDialog.ItemsForeColor   = Color.DarkGreen;
                    OptionDialog.AllowToCancel    = true;
                    OptionDialog.CancelButtonText = "Exit";

                    string[]            modes = Enum.GetNames(typeof(FlashCardMode));
                    SelectionDialogItem ptrMenuItem;
                    string imagePath = RootPath + "\\System\\Art\\ApplicationModes\\";
                    foreach (string ptrMode in modes)
                    {
                        ptrMenuItem = OptionDialog.AddItem(ptrMode);
                        //ptrMenuItem.DescriptionImage = Image.FromFile(imagePath + ptrMode + ".png");
                    }
                    OptionDialog.AddItem("Settings");
                    OptionDialog.AddItem("About");

                    if (OptionDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (Enum.IsDefined(typeof(FlashCardMode), OptionDialog.SelectedItem))
                        {
                            SelectMode((FlashCardMode)Enum.Parse(typeof(FlashCardMode),
                                                                 OptionDialog.SelectedItem), false);
                        }
                        else if (OptionDialog.SelectedItem == "Settings")
                        {
                            Settings Settings = new Settings(this);
                            Settings.ShowDialog();
                            continue;
                        }
                        else if (OptionDialog.SelectedItem == "About")
                        {
                            AboutFlashCard AboutDlg = new AboutFlashCard();
                            AboutDlg.ShowDialog();
                            continue;
                        }
                        else
                        {
                            throw new InvalidOperationException("Unknown menu option : " + OptionDialog.SelectedItem);
                        }
                    }
                    else //Cancel button clicked. Exit Application.
                    {
                        System.Windows.Forms.Application.Exit();
                        return;
                    }
                }
                //Lesson Menu
                if (SelectLesson() == true)
                {
                    return;
                }
            }
        }