Moved playlist commands to view model.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
xmlns:converter="clr-namespace:Harmonia.UI.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
DataContext="{x:Static vm:ViewModelLocator.PlaylistViewModel}"
|
||||
Loaded="OnLoaded"
|
||||
x:Class="Harmonia.UI.Views.PlaylistView"
|
||||
x:DataType="vm:PlaylistViewModel">
|
||||
<UserControl.Resources>
|
||||
@@ -46,7 +47,12 @@
|
||||
</UserControl.Styles>
|
||||
<Grid Margin="0">
|
||||
<Canvas Background="#99000000"></Canvas> <!-- Was 99 !-->
|
||||
<ListBox ItemsSource="{Binding PlaylistSongs}" DoubleTapped="ListBox_DoubleTapped">
|
||||
<ListBox
|
||||
Name="PlaylistListBox"
|
||||
ItemsSource="{Binding PlaylistSongs}"
|
||||
SelectedItems="{Binding SelectedPlaylistSongs, Mode=OneWay}"
|
||||
DoubleTapped="ListBox_DoubleTapped"
|
||||
SelectionMode="Multiple">
|
||||
<!--<ListBox.Styles>
|
||||
<Style Selector="ListBoxItem:nth-child(odd):not(:pointerover):not(:selected)">
|
||||
<Setter Property="Background" Value="#00000000"/>
|
||||
@@ -87,6 +93,86 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu Name="PlaylistContextMenu" Padding="10" Background="#EE444444">
|
||||
<MenuItem Command="{Binding PlaySongCommand}" HotKey="Enter" InputGesture="Enter">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Play" FontWeight="Bold" Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource SemiIconPlay}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Command="{Binding AddFilesCommand}" HotKey="Insert" InputGesture="Insert">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Add Files..." Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource SemiIconFile}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Command="{Binding AddFolderCommand}" HotKey="Ctrl+Insert" InputGesture="Ctrl+Insert">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Add Folder..." Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource SemiIconFolder}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Command="{Binding RemoveSongsCommand}" HotKey="Delete" InputGesture="Delete">
|
||||
<MenuItem.Styles>
|
||||
<Style Selector="TextBlock">
|
||||
<Setter Property="Foreground" Value="#ff99a4"/>
|
||||
</Style>
|
||||
</MenuItem.Styles>
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Remove" Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource DeleteIcon}" Foreground="#ff99a4"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Command="{Binding CutSongsCommand}" HotKey="Ctrl+X" InputGesture="Ctrl+X">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Cut" Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource CutIcon}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Command="{Binding CopySongsCommand}" HotKey="Ctrl+C" InputGesture="Ctrl+C">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Copy" Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource CopyIcon}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Command="{Binding PasteSongsCommand}" HotKey="Ctrl+V" InputGesture="Ctrl+V">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Paste" Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource PasteIcon}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Command="{Binding OpenFileLocationCommand}" HotKey="Alt+O" InputGesture="Alt+O">
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="Open File Location" Margin="8 0 8 0"></TextBlock>
|
||||
</MenuItem.Header>
|
||||
<MenuItem.Icon>
|
||||
<PathIcon Data="{StaticResource SemiIconFolderOpen}"></PathIcon>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
<ListBox.KeyBindings>
|
||||
<KeyBinding Gesture="Enter" Command="{Binding PlaySongCommand}" />
|
||||
</ListBox.KeyBindings>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using Harmonia.Core.Caching;
|
||||
using Harmonia.Core.Imaging;
|
||||
using Avalonia.VisualTree;
|
||||
using Harmonia.Core.Engine;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Harmonia.UI.ViewModels;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -19,19 +21,29 @@ namespace Harmonia.UI.Views;
|
||||
public partial class PlaylistView : UserControl
|
||||
{
|
||||
private readonly PlaylistViewModel _viewModel;
|
||||
private readonly IAudioEngine _audioEngine;
|
||||
private readonly ConcurrentDictionary<int, CancellationTokenSource> _imageCancellationTokens = [];
|
||||
|
||||
private IStorageProvider? _storageProvider;
|
||||
|
||||
public PlaylistView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = (PlaylistViewModel)DataContext!;
|
||||
|
||||
_audioEngine = App.ServiceProvider.GetRequiredService<IAudioEngine>();
|
||||
}
|
||||
|
||||
private void ListBox_DoubleTapped(object? sender, TappedEventArgs e)
|
||||
private void OnLoaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_storageProvider = TopLevel.GetTopLevel(this)?.StorageProvider;
|
||||
}
|
||||
|
||||
private async void ListBox_DoubleTapped(object? sender, TappedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox && listBox.SelectedItem is PlaylistSong playlistSong)
|
||||
{
|
||||
_viewModel.PlaySong(playlistSong);
|
||||
await _viewModel.PlaySongAsync(playlistSong);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,4 +100,49 @@ public partial class PlaylistView : UserControl
|
||||
_imageCancellationTokens.TryGetValue(hashCode, out CancellationTokenSource? cancellationTokenSource);
|
||||
cancellationTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
//private async void AddFiles_Click(object? sender, RoutedEventArgs e)
|
||||
//{
|
||||
// if (_storageProvider == null)
|
||||
// return;
|
||||
|
||||
// FilePickerOpenOptions openOptions = new()
|
||||
// {
|
||||
// FileTypeFilter = [GetAudioFileTypes()],
|
||||
// AllowMultiple = true
|
||||
// };
|
||||
|
||||
// IReadOnlyList<IStorageFile> result = await _storageProvider.OpenFilePickerAsync(openOptions);
|
||||
// string[] fileNames = [.. result.Select(file => file.TryGetLocalPath() ?? string.Empty)];
|
||||
|
||||
// CancellationToken cancellationToken = default;
|
||||
// await _viewModel.AddFilesAsync(fileNames, cancellationToken);
|
||||
//}
|
||||
|
||||
//private FilePickerFileType GetAudioFileTypes()
|
||||
//{
|
||||
// return new("Audo Files")
|
||||
// {
|
||||
// Patterns = [.. _audioEngine.SupportedFormats]
|
||||
// };
|
||||
//}
|
||||
|
||||
//private async void AddFolder_Click(object? sender, RoutedEventArgs e)
|
||||
//{
|
||||
// if (_storageProvider == null)
|
||||
// return;
|
||||
|
||||
// FolderPickerOpenOptions options = new()
|
||||
// {
|
||||
// AllowMultiple = true
|
||||
// };
|
||||
|
||||
// IReadOnlyList<IStorageFolder> folders = await _storageProvider.OpenFolderPickerAsync(options);
|
||||
|
||||
// if (folders.Count == 0)
|
||||
// return;
|
||||
|
||||
// CancellationToken cancellationToken = default;
|
||||
// await _viewModel.AddFolderAsync(folders[0].TryGetLocalPath() ?? string.Empty, cancellationToken);
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user