//moving songs from playlist to playlist private void AddToPlaylistButton_Click(object sender, RoutedEventArgs e) { List <SongViewModel> selectedSongs; switch (songListTabControl.SelectedIndex) { case 1: //tab 1, search tab selectedSongs = searchListbox.SelectedItems.Cast <SongViewModel>().ToList(); break; default: //tab 0, song list selectedSongs = songListBox.SelectedItems.Cast <SongViewModel>().ToList(); break; } if (selectedSongs.Count <= 0) { MessageBox.Show("No songs are selected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (((PlaylistItemViewModel)targetPlaylistComboBox.SelectedItem).Name.Equals(currentPlaylist.Name)) { MessageBox.Show("The source and destination playlist cannot be the same", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } PlaylistItemViewModel item = PlaylistItems[targetPlaylistComboBox.SelectedIndex]; PlaylistViewModel targetPlaylist = serializer.DeserializePlaylist(item.Path); MessageBoxResult result = MessageBox.Show(string.Format("Would you like to copy {0} songs from {1} to {2}", selectedSongs.Count, currentPlaylist.Name, targetPlaylist.Name), "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { int largestInd = 0; for (int i = 0; i < targetPlaylist.Songs.Count; i++) { if (targetPlaylist.Songs[i].Order > largestInd) { largestInd = targetPlaylist.Songs[i].Order; } } for (int i = 0; i < selectedSongs.Count; i++) { SongViewModel song = new SongViewModel(selectedSongs[i]); song.Order = largestInd + i + 1; targetPlaylist.Songs.Add(song); } serializer.Serialize(targetPlaylist); Console.WriteLine("moved " + selectedSongs.Count + " to " + targetPlaylist.Name); } }
private void PlaylistListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ReserializeCurrentPlaylist(); //checks for changes, and reserialize it if ((bool)ctrlShuffleCheckBox.IsChecked) { shuffleController.ClearPastValues(); } int index = playlistListBox.SelectedIndex; if (index >= 0 && index < PlaylistItems.Count) { PlaylistItemViewModel item = PlaylistItems[index]; PlaylistViewModel playlist = serializer.DeserializePlaylist(item.Path); if (playlist != null) { currentPlaylist.UpdateProperties(playlist); } if (currentPlaylist.Songs.Count > 0) { songListBox.SelectedIndex = 0; } } }