Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public void InsertTracks(List <TrackInfo> tracks, int insertIdx)
 {
     foreach (TrackInfo track in tracks)
     {
         Soundtracks.Insert(insertIdx, track);
     }
 }
Exemplo n.º 3
0
 public void DeleteTracksByIndices(int[] indices)
 {
     Array.Sort <int>(indices, (x, y) => { return(-x.CompareTo(y)); });
     foreach (int i in indices)
     {
         Soundtracks.RemoveAt(i);
     }
 }
Exemplo n.º 4
0
 public void UpdateSoundtracks(Playlist pl)
 {
     Soundtracks.FillContent(pl.Soundtracks);
 }
Exemplo n.º 5
0
 public void UpdateSoundtracks(List <TrackInfo> source)
 {
     Soundtracks.FillContent(source);
 }
Exemplo n.º 6
0
        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;
                    }
                }
            }
        }