Пример #1
0
        private void InitializePlaylistContent()
        {
            TracksViewModel     tracksVM     = new TracksViewModel(PlaylistCollection.GetPlaylist(Properties.Settings.Default.LastSelectedPlaylistGUID));
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                throw new Exception("Failed to cast object");
            }

            lv_Playlist.DataContext = tracksVM;
            if (trackListsVM.CurrentPlaylist != null)
            {
                lv_Playlist.ItemsSource = trackListsVM.CurrentPlaylist.Soundtracks as IEnumerable <TrackInfo>;
                tracksVM.UpdateSoundtracks(trackListsVM.CurrentPlaylist);
            }
            else
            {
                lv_Playlist.ItemsSource = null;
            }

            // Bind event for updating content of view-model of lb_PlaylistMenu
            tracksVM.PlaylistIsUpdatedEvent += (lb_PlaylistMenu.DataContext as TrackListsViewModel).UpdateTrackList;
            // Update trackQueue
            tracksVM.PlaylistIsUpdatedEvent += OnPlaylistIsUpdated;
        }
Пример #2
0
        private void lb_PlaylistMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Playlist pl = lb_PlaylistMenu.SelectedItem as Playlist;

            if (pl == null)
            {
                return;
            }
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                return;
            }
            if (trackListsVM.CurrentPlaylist != null && pl.GUID == trackListsVM.CurrentPlaylist.GUID)
            {
                return;
            }

            trackListsVM.CurrentPlaylist = pl;

            RefreshPlaylistContent();

            if (lv_Playlist.Visibility == Visibility.Hidden)
            {
                lv_Playlist.Visibility = Visibility.Visible;
            }
        }
Пример #3
0
        private void RefreshPlaylist()
        {
            PlaylistCollection plc = PlaylistCollection.GetDatabase();

            if (plc == null)
            {
                return;
            }

            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                return;
            }

            Playlist pl = null;

            trackListsVM.UpdateTrackLists(plc.TrackLists);
            if (trackListsVM.CurrentPlaylist != null)
            {
                pl = trackListsVM.TrackLists.FirstOrDefault(x => x.GUID == trackListsVM.CurrentPlaylist.GUID);
            }
            lb_PlaylistMenu.SelectedItem = pl;
        }
Пример #4
0
        private void InitializePlaylistMenu()
        {
            TrackListsViewModel trackListsVM = new TrackListsViewModel();

            trackListsVM.CurrentPlaylist = PlaylistCollection.GetPlaylist(Properties.Settings.Default.LastSelectedPlaylistGUID);
            lb_PlaylistMenu.DataContext  = trackListsVM;
            lb_PlaylistMenu.ItemsSource  = trackListsVM.TrackLists;
        }
Пример #5
0
        private void miDelete_Click(object sender, RoutedEventArgs e)
        {
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;
            Playlist            pl           = lb_PlaylistMenu.SelectedItem as Playlist;

            if (pl == null)
            {
                throw new Exception("Failed to cast selected item to Playlist");
            }

            trackListsVM.RemovePlaylist(pl.GUID);
            lb_PlaylistMenu.SelectedIndex = trackListsVM.TrackLists.Count - 1;

            RefreshPlaylistContent();
        }
Пример #6
0
        private void txtEditBox_LostFocus(object sender, RoutedEventArgs e)
        {
            ListBoxItem lbi    = ((TextBox)sender).TemplatedParent as ListBoxItem;
            string      result = SwitchEditingMode(lbi, false);

            Guid targetGUID = (lb_PlaylistMenu.SelectedItem as Playlist).GUID;

            if (result != oriPlaylistName)
            {
                TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;
                trackListsVM.UpdatePlaylistName(targetGUID, result);
                TracksViewModel tracksVM = lv_Playlist.DataContext as TracksViewModel;
                tracksVM.UpdatePlaylistInfo(targetGUID, result);
                lb_PlaylistMenu.UpdateLayout();
            }

            oriPlaylistName = "";   // Reset
        }
Пример #7
0
        private void lb_PlaylistMenu_KeyDown(object sender, KeyEventArgs e)
        {
            // Remove this functionality to avoid user deleting playlist by pressing delete key directly
#if false
            if (e.Key == Key.Delete && lb_PlaylistMenu.SelectedItems.Count == 1)
            {
                TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;
                Playlist            pl           = lb_PlaylistMenu.SelectedItem as Playlist;
                if (pl == null)
                {
                    throw new Exception("Failed to cast selected item to Playlist");
                }

                trackListsVM.RemovePlaylist(pl.GUID);
                lb_PlaylistMenu.SelectedIndex = trackListsVM.TrackLists.Count - 1;
                RefreshPlaylistContent();
            }
#endif
        }
Пример #8
0
        private void btnAddPlaylist_Click(object sender, RoutedEventArgs e)
        {
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                throw new Exception("Empty content of lb_PlaylistMenu");
            }

            Playlist pl = trackListsVM.CreatePlaylist();

            lb_PlaylistMenu.SelectedItem = pl;
            RefreshPlaylistContent();

            if (lv_Playlist.Visibility == Visibility.Hidden)
            {
                lv_Playlist.Visibility = Visibility.Visible;
            }
        }
Пример #9
0
        public void SetTrackStatus(TrackStatusEventArgs e)
        {
            // Check
            if (e == null || e.Index == -1)
            {
                return;
            }

            TracksViewModel     tracksVM     = lv_Playlist.DataContext as TracksViewModel;
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            // TODO: try to rewrite this
            Playlist pl = trackListsVM.TrackLists.First(x => x.GUID == e.OwnerListGUID);

            pl.Soundtracks.Find(x => x.GUID == e.Track.GUID).TrackStatus = e.Track.TrackStatus;

            if (pl.GUID == e.OwnerListGUID)
            {
                tracksVM.UpdateTrackStatus(e);
            }
        }
Пример #10
0
        private void RefreshPlaylistContent()
        {
            TracksViewModel tracksVM = lv_Playlist.DataContext as TracksViewModel;

            if (tracksVM == null)
            {
                return;
            }
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            if (trackListsVM == null)
            {
                return;
            }

            Playlist pl = trackListsVM.CurrentPlaylist;

            if (pl == null)
            {
                lv_Playlist.Visibility = Visibility.Hidden;
                return;
            }

            tracksVM.UpdatePlaylistInfo(pl);
            tracksVM.UpdateSoundtracks(pl);
            lv_Playlist.ItemsSource = tracksVM.Soundtracks as IEnumerable <TrackInfo>;

            // Update info
            Properties.Settings.Default.LastSelectedPlaylistGUID = pl.GUID;
            Properties.Settings.Default.Save();

            // Show playing track
            if (lb_PlaylistMenu.SelectedItem != null && ListContentIsRefreshedEvent != null)
            {
                if (Properties.Settings.Default.TaskPlaylistGUID == pl.GUID)
                {
                    tracksVM.UpdateTrackStatus(ListContentIsRefreshedEvent());
                }
            }
        }