Added randomize/reverse songs logic. Added initial UI-side locking logic.
This commit is contained in:
@@ -167,9 +167,9 @@
|
||||
|
||||
<MenuFlyoutItem Text="Remove Missing" Command="{Binding RemoveMissingSongsCommand}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutItem Text="Lock Playlist">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<ToggleMenuFlyoutItem Text="Lock Playlist" IsChecked="{Binding Playlist.IsLocked}">
|
||||
</ToggleMenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
|
||||
@@ -179,6 +179,11 @@
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
|
||||
<MenuFlyoutSubItem x:Name="SortByMenuFlyoutSubItem" Text="Sort By...">
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
<MenuFlyoutItem Text="Randomize" Command="{Binding RandomizeAllCommand}">
|
||||
</MenuFlyoutItem>
|
||||
<MenuFlyoutItem Text="Reverse" Command="{Binding ReverseAllCommand}">
|
||||
</MenuFlyoutItem>
|
||||
</MenuFlyoutSubItem>
|
||||
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
@@ -238,6 +243,11 @@
|
||||
<MenuFlyoutSubItem.Icon>
|
||||
<PathIcon Data="{StaticResource SortIcon}"></PathIcon>
|
||||
</MenuFlyoutSubItem.Icon>
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
<MenuFlyoutItem Text="Randomize" Command="{Binding RandomizeSelectedCommand}">
|
||||
</MenuFlyoutItem>
|
||||
<MenuFlyoutItem Text="Reverse" Command="{Binding ReverseSelectedCommand}">
|
||||
</MenuFlyoutItem>
|
||||
</MenuFlyoutSubItem>
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
<MenuFlyoutItem Text="Cut" Command="{Binding CutSongsCommand}">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using CommunityToolkit.WinUI;
|
||||
using Harmonia.Core.Imaging;
|
||||
using Harmonia.Core.Playlists;
|
||||
using Harmonia.WinUI.ViewModels;
|
||||
using Microsoft.UI.Dispatching;
|
||||
@@ -7,14 +6,10 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Popups;
|
||||
|
||||
namespace Harmonia.WinUI.Views;
|
||||
|
||||
@@ -33,24 +28,28 @@ public sealed partial class PlaylistDetailView : UserControl
|
||||
|
||||
foreach (MenuFlyoutItemBase item in PlaylistListViewMenuFlyout.Items)
|
||||
{
|
||||
item.DataContextChanged += Item_DataContextChanged;
|
||||
HookDataContextChanged(item);
|
||||
}
|
||||
|
||||
int currentSortItemIndex = 0;
|
||||
|
||||
foreach (SortItem sortItem in _viewModel.SortItems)
|
||||
{
|
||||
SortByMenuFlyoutSubItem.Items.Add(new MenuFlyoutItem
|
||||
SortByMenuFlyoutSubItem.Items.Insert(currentSortItemIndex, new MenuFlyoutItem
|
||||
{
|
||||
Text = sortItem.Name,
|
||||
Command = _viewModel.SortAllCommand,
|
||||
CommandParameter = sortItem
|
||||
});
|
||||
|
||||
SortSelectedByMenuFlyoutSubItem.Items.Add(new MenuFlyoutItem
|
||||
SortSelectedByMenuFlyoutSubItem.Items.Insert(currentSortItemIndex, new MenuFlyoutItem
|
||||
{
|
||||
Text = sortItem.Name,
|
||||
Command = _viewModel.SortSelectedCommand,
|
||||
CommandParameter = sortItem
|
||||
});
|
||||
|
||||
currentSortItemIndex++;
|
||||
}
|
||||
|
||||
_viewModel.SortSelectedCommand.CanExecuteChanged += (_, _) =>
|
||||
@@ -74,15 +73,44 @@ public sealed partial class PlaylistDetailView : UserControl
|
||||
|
||||
private void OnViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(_viewModel.PlayingSong))
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
ListViewItem listViewItem = (ListViewItem)PlaylistListView.ContainerFromItem(_viewModel.PlayingSong);
|
||||
|
||||
UpdateListViewItemStyle(listViewItem, true);
|
||||
case nameof(_viewModel.PlayingSong):
|
||||
ListViewItem listViewItem = (ListViewItem)PlaylistListView.ContainerFromItem(_viewModel.PlayingSong);
|
||||
UpdateListViewItemStyle(listViewItem, true);
|
||||
break;
|
||||
case nameof(_viewModel.Playlist):
|
||||
ScrollToTop();
|
||||
break;
|
||||
case nameof(_viewModel.SelectedPlaylistSongs):
|
||||
SyncListViewSelection();
|
||||
break;
|
||||
}
|
||||
else if (e.PropertyName == nameof(_viewModel.Playlist))
|
||||
}
|
||||
|
||||
private bool _isSyncingSelection;
|
||||
|
||||
private void SyncListViewSelection()
|
||||
{
|
||||
_isSyncingSelection = true;
|
||||
|
||||
try
|
||||
{
|
||||
ScrollToTop();
|
||||
PlaylistListView.DeselectAll();
|
||||
|
||||
foreach (PlaylistSong playlistSong in _viewModel.SelectedPlaylistSongs)
|
||||
{
|
||||
int index = PlaylistListView.Items.IndexOf(playlistSong);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
PlaylistListView.SelectRange(new ItemIndexRange(index, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSyncingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +198,19 @@ public sealed partial class PlaylistDetailView : UserControl
|
||||
}
|
||||
}
|
||||
|
||||
private void HookDataContextChanged(MenuFlyoutItemBase item)
|
||||
{
|
||||
item.DataContextChanged += Item_DataContextChanged;
|
||||
|
||||
if (item is MenuFlyoutSubItem subItem)
|
||||
{
|
||||
foreach (MenuFlyoutItemBase childItem in subItem.Items)
|
||||
{
|
||||
HookDataContextChanged(childItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Item_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
|
||||
{
|
||||
if (sender is not MenuFlyoutItemBase item)
|
||||
@@ -268,6 +309,9 @@ public sealed partial class PlaylistDetailView : UserControl
|
||||
|
||||
private void PlaylistListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (_isSyncingSelection)
|
||||
return;
|
||||
|
||||
if (sender is not ListView listView)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user