public bool ReorderTracks(List <int> trackIdx, int insertIdx) { int firstIdx = trackIdx[0]; int newInsertIdx = insertIdx; // correct insertIdx by checking how many items locating before it for (int i = 0; i < trackIdx.Count; i++) { if (trackIdx[i] < insertIdx) { newInsertIdx--; } } if (newInsertIdx == firstIdx) { return(false); // no need to reorder tracks } else { trackIdx.Sort((x, y) => - x.CompareTo(y)); // descending sorting List <TrackInfo> tracks = new List <TrackInfo>(trackIdx.Count); for (int i = 0; i < trackIdx.Count; i++) { tracks.Add(Soundtracks[trackIdx[i]]); Soundtracks.RemoveAt(trackIdx[i]); } this.InsertTracks(tracks, newInsertIdx); } return(true); }
public void InsertTracks(List <TrackInfo> tracks, int insertIdx) { foreach (TrackInfo track in tracks) { Soundtracks.Insert(insertIdx, track); } }
public void DeleteTracksByIndices(int[] indices) { Array.Sort <int>(indices, (x, y) => { return(-x.CompareTo(y)); }); foreach (int i in indices) { Soundtracks.RemoveAt(i); } }
public void UpdateSoundtracks(Playlist pl) { Soundtracks.FillContent(pl.Soundtracks); }
public void UpdateSoundtracks(List <TrackInfo> source) { Soundtracks.FillContent(source); }
void IDropTarget.Drop(IDropInfo dropInfo) { DataObject dataObject = dropInfo.Data as DataObject; if (dataObject != null && dataObject.ContainsFileDropList()) { IEnumerable <string> dropList = dataObject.GetFileDropList().Cast <string>(); List <TrackInfo> tlist = new List <TrackInfo>(); foreach (string filePath in dropList) { if (!MPLiteConstant.validFileType.Contains(Path.GetExtension(filePath))) { continue; } try { TrackInfo track = TrackInfo.ParseSource(filePath); tlist.Add(track); Soundtracks.Add(track); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (tlist.Count != 0) { Playlist pl = PlaylistCollection.UpdatePlaylist(tlist, TracklistName); UpdatePlaylistEventArgs e = new UpdatePlaylistEventArgs(pl, PlayingTrack); PlaylistIsUpdatedEvent?.Invoke(e); } } else { // workaround: There is a bug that user can drag item from the gap between two items. // It triggers DragEvent without SelectionChangeEvent. So that `selectedIndices` will be empty. if (selectedIndices.Count == 0) { return; } // Reorder tracks List <TrackInfo> tracks; if ((dropInfo.Data as List <TrackInfo>) == null) { // Single file is dropped tracks = new List <TrackInfo>(); tracks.Add(dropInfo.Data as TrackInfo); } else { // Multiple files is dropped tracks = dropInfo.Data as List <TrackInfo>; } Playlist pl = PlaylistCollection.ReorderTracks(TracklistGUID, SelectedIndices, dropInfo.InsertIndex); if (pl == null) { return; } UpdateSoundtracks(pl.Soundtracks); UpdatePlaylistEventArgs e = new UpdatePlaylistEventArgs(pl, PlayingTrack); PlaylistIsUpdatedEvent?.Invoke(e); // reset PlayStatus if (PlayingTrack != null) { TrackInfo track = soundtracks.FirstOrDefault(x => x.GUID == PlayingTrack.GUID); if (track != null) { track.TrackStatus = PlayingTrack.TrackStatus; } } } }