Esempio n. 1
0
        private async Task RemoveFilterEntriesAsync(Regex regex, ProgressDialogController controller)
        {
            var removeMessage = "Removing entry...";

            await Task.Run(() =>
            {
                var toRemove = DisplayedSongs
                               .Where(x => !regex.IsMatch(x.Name))
                               .ToList();

                controller.Minimum = 0;
                controller.Maximum = toRemove.Count;

                for (int i = 0; i < toRemove.Count; i++)
                {
                    var currentItemNumber = i + 1;

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        DisplayedSongs.Remove(toRemove[i]);
                    });

                    controller.SetProgress(currentItemNumber);
                    controller.SetMessage(String.Format("{0} ({1}/{2})", removeMessage, currentItemNumber, toRemove.Count));
                }
            });
        }
Esempio n. 2
0
        public void Drop(IDropInfo dropInfo)
        {
            var files = (dropInfo.Data as DataObject)?.GetFileDropList().Cast <string>();

            dropInfo.Effects = DragDropEffects.None;

            if (files != null)
            {
                var mp3s = files.Where(x => Path.GetExtension(x).Equals(".mp3"));

                if (mp3s.Any())
                {
                    var songViewModels = this.GenerateSongViewModels(mp3s);

                    // Do not overwrite any existing / already loaded instances.
                    if (songViewModels.Any() && DisplayedSongs == null)
                    {
                        DisplayedSongs = new ObservableCollection <SongViewModel>();
                    }

                    // Convert the file paths into view models like the "normal"
                    // loading does as well.
                    foreach (var song in songViewModels)
                    {
                        DisplayedSongs.Add(song);
                        this.songs.Add(song);
                    }
                    this.UpdateSongIndices();

                    dropInfo.Effects = DragDropEffects.Copy;
                }
            }
        }
Esempio n. 3
0
        private void GroupCategoriesCollectionChanged(object sender,
                                                      NotifyCollectionChangedEventArgs e)
        {
            if (DisplayedSongs == null)
            {
                return;
            }
            Logger.Debug("Updating group descriptions");
            lock (_displayedSongs)
                if (DisplayedSongs.GroupDescriptions == null)
                {
                    return;
                }
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                if (e.NewItems == null)
                {
                    return;
                }
                AddGroupDescriptions(e.NewStartingIndex, e.NewItems.Cast <Category>());
                break;

            case NotifyCollectionChangedAction.Move:
                if (e.OldItems == null)
                {
                    return;
                }
                lock (_displayedSongs)
                    DisplayedSongs.GroupDescriptions.
                    Move(e.OldStartingIndex, e.NewStartingIndex);
                break;

            case NotifyCollectionChangedAction.Remove:
                if (e.OldItems == null)
                {
                    return;
                }
                lock (_displayedSongs)
                {
                    foreach (Category cat in e.OldItems)
                    {
                        DisplayedSongs.GroupDescriptions
                        .Remove(_groupDescriptionDictionary[cat]);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                lock (_displayedSongs)
                    DisplayedSongs.GroupDescriptions.Clear();
                if (e.NewItems == null)
                {
                    return;
                }
                AddGroupDescriptions(e.NewStartingIndex, e.NewItems.Cast <Category>());
                break;
            }
            lock (_displayedSongs) DisplayedSongs.Refresh();
        }
Esempio n. 4
0
        // ---------- EventAggregator
        private void RemoveSongFromSongList(int index)
        {
            var toRemove = DisplayedSongs.ElementAt(index);

            DisplayedSongs.Remove(toRemove);
            this.songs.Remove(toRemove);
            this.UpdateSongIndices();

            // Reset view.
            if (!DisplayedSongs.Any())
            {
                DisplayedSongs = null;
            }
        }
Esempio n. 5
0
        private async Task <bool> LoadSongsAsync(OpenFileDialog dialogSettings)
        {
            var success = dialogSettings.ShowDialog() ?? false;

            if (success)
            {
                var message        = "Loading songs...";
                var files          = dialogSettings.FileNames;
                var fileCount      = files.Count();
                var songViewModels = this.GenerateSongViewModels(files);
                var enumerator     = songViewModels.GetEnumerator();
                var uiDispatcher   = Dispatcher.CurrentDispatcher;

                var controller = await this.dialogCoordinator.ShowProgressAsync(this, "Load Songs", message, false);

                controller.Maximum = fileCount;
                controller.Minimum = 0;

                // Do not overwrite any existing / already loaded instances.
                if (songViewModels.Any() && DisplayedSongs == null)
                {
                    DisplayedSongs = new ObservableCollection <SongViewModel>();
                }

                // A separate Task is needed in order for the progress bar content
                // to be drawn. Otherwise only a blank, grey overlay is shown.
                await Task.Run(() =>
                {
                    for (int i = 0; i < fileCount; i++)
                    {
                        enumerator.MoveNext();
                        var viewModel    = enumerator.Current;
                        var currentCount = i + 1;

                        uiDispatcher.Invoke(() => { DisplayedSongs.Add(viewModel); });
                        this.songs.Add(viewModel);

                        controller.SetProgress(currentCount);
                        controller.SetMessage(String.Format("{0} ({1}/{2})", message, currentCount, fileCount));
                    }
                });

                await controller.CloseAsync();
            }

            return(success);
        }
Esempio n. 6
0
        private async Task AddFilteredEntriesAsync(Regex regex, ProgressDialogController controller)
        {
            var addMessage = "Adding entry...";

            await Task.Run(() =>
            {
                var toAdd = this.songs
                            .Except(DisplayedSongs)
                            .Where(x => regex.IsMatch(x.Name))
                            .ToList();

                controller.SetMessage(String.Format("{0} ({1})", addMessage, toAdd.Count));
                controller.Minimum = 0;
                controller.Maximum = 1;

                Application.Current.Dispatcher.Invoke(() =>
                {
                    DisplayedSongs.AddRange(toAdd);
                });

                controller.SetProgress(1);
            });
        }