Exemplo n.º 1
0
        public void RemoveTracks()
        {
            PlaylistCollection.DeleteTracksByIndices(selectedIndices.ToArray(), TracklistGUID);
            for (int i = selectedIndices.Count - 1; i >= 0; i--)
            {
                soundtracks.RemoveAt(selectedIndices[i]);
            }

            Playlist pl = PlaylistCollection.GetPlaylist(TracklistGUID);
            UpdatePlaylistEventArgs e = new UpdatePlaylistEventArgs(pl, PlayingTrack);

            PlaylistIsUpdatedEvent?.Invoke(e);
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }