/// <summary> /// Event handler for when the remove button is clicked to remove a directory from the list of cover directories. /// </summary> private void RemoveButton_Click(object sender, RoutedEventArgs e) { //Make sure theeres actually something in the list and that theres at least one selected item if (CoverDirsListBox.Items.Count < 0 || CoverDirsListBox.SelectedIndex == -1 || CoverDirsListBox.SelectedItems.Count < 0) { return; // if not, dont do anything. } List <String> toDelete = new List <String>(); //otherwise make a copy of the ones to delete, then delete them from the main list foreach (String item in CoverDirsListBox.SelectedItems) //have to make a copy first due to the foreach loop as well as the fact that the UI is monitoring th list. { toDelete.Add(item); } foreach (String item in toDelete) { CoverDirs.Remove(item); } }
/// <summary> /// Event handler for when the add button is clicked to add a directory to the list of cover directories. /// </summary> private void AddButton_Click(object sender, RoutedEventArgs e) { WinForms.FolderBrowserDialog fbd = new WinForms.FolderBrowserDialog { Description = Properties.Resources.SelectDirForHBCStr, ShowNewFolderButton = true }; //Show a folder browser and allow the folder to be created or selected. if (fbd.ShowDialog() != WinForms.DialogResult.OK) // Show the folder browser dilaog asking the user for the cover directory they'd like { //If the result is anything but OK, cancel out and return. return; } string dir_path = fbd.SelectedPath.Trim(); if (string.IsNullOrEmpty(dir_path)) //Make sure the selected directory name isn't empty. { MessageBox.Show(this, Properties.Resources.MustSelectExistingFolderStr, Properties.Resources.MustSelectExistingFolderShortStr, MessageBoxButton.OK, MessageBoxImage.Error); return; } CoverDirs.Add(fbd.SelectedPath); //Add it to the list of cover directories proeprty }
/// <summary> /// Event handler for when the clear button is clicked to clear the list of cover directories. /// </summary> private void ClearButton_Click(object sender, RoutedEventArgs e) { CoverDirs.Clear(); }