public void Execute(SongViewModel svm)
 {
     if(svm != null) {
         Action?.Invoke(svm);
     } else {
         throw new ArgumentNullException(nameof(svm));
     }
 }
 private void SongCard_PreviewMouseDown(object sender, MouseEventArgs e)
 {
     var nrOfItems = Lb_Playlist.SelectedItems.Count;
     ItemsToDrag = new SongViewModel[nrOfItems];
     Lb_Playlist.SelectedItems.CopyTo(ItemsToDrag, 0);
 }
 private void SetupSongMenuItems()
 {
     SongMenuItems = new SongMenuItemViewModel[] {
         new SongMenuItemViewModel() {
             Title = "Play",
             Action = svm => {
                 if(PlaySongCommand.CanExecute(svm.Song)) {
                     PlaySongCommand.Execute(svm.Song);
                 }
             }
         },
         new SongMenuItemViewModel() {
             Title = "Remove",
             Action = svm => {
                 var svmIEnum = new SongViewModel[] { svm };
                 if(RemoveSongsCommand.CanExecute(svmIEnum)) {
                     RemoveSongsCommand.Execute(svmIEnum);
                 }
             }
         },
         new SongMenuItemViewModel() {
             Title = "Open file location",
             Action = svm => {
                 if(File.Exists(svm.Path)) {
                     System.Diagnostics.Process.Start("explorer.exe", $"/select, {svm.Path}");
                 }
             }
         },
         new SongMenuItemViewModel() {
             Title = "Add/Remove from startup songs",
             Action = svm => {
                 var found = Settings.StartupFolders.FirstOrDefault(path => svm.Path.StartsWith(path));
                 if(found != null) { //Was in StartupFolders, remove it
                     Action<string, string> addAllExcept = null;
                     addAllExcept = (add, except) => {
                         if(File.Exists(add)) {
                             if(add != except)
                                 Settings.AddStartupFolder(add);
                         }else {
                             var di = new DirectoryInfo(add);
                             foreach(var addFile in di.GetFiles("*", SearchOption.TopDirectoryOnly).Where(fi => fi.FullName != svm.Path)) {
                                 Settings.AddStartupFolder(addFile.FullName);
                             }
                             foreach(var addFolder in di.GetDirectories("*", SearchOption.TopDirectoryOnly)) {
                                 if(!except.StartsWith(addFolder.FullName)) {
                                     Settings.AddStartupFolder(addFolder.FullName);
                                 }else {
                                     addAllExcept(addFolder.FullName, except);
                                 }
                             }
                         }
                     };
                     Settings.RemoveStartupFolder(found);
                     addAllExcept(found, svm.Path);
                 }else { //Wsa not in StartupFolders, add it
                     Settings.AddStartupFolder(svm.Path);
                 }
                 SettingsViewModel.InitLoadPaths();
             }
         }
     };
 }
        private void FillPlaylist(string filter = null)
        {
            if(PlaylistItems == null) {
                PlaylistItems = new ObservableCollection<SongViewModel>();
            }
            PlaylistItems.Clear();

            Regex query;
            try {
                query = string.IsNullOrEmpty(filter) ? null : new Regex(filter, RegexOptions.IgnoreCase);
            } catch(ArgumentException) {
                query = null;
            }

            foreach(var addSong in Playlist) {
                var svm = new SongViewModel(addSong, this) {
                    Playing = addSong == SongPlayer.CurrentSong
                };
                if(query == null) {
                    PlaylistItems.Add(svm);
                } else {
                    if(query.IsMatch(svm.Title) || query.IsMatch(svm.SubTitle)) {
                        PlaylistItems.Add(svm);
                    }
                }
            }

            DisplayedSongsChanged?.Invoke(this, new EventArgs());
        }