Added in more locking/unlocking logic.
This commit is contained in:
38
Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs
Normal file
38
Harmonia.WinUI/Converters/BooleanToVisibilityConverter.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Harmonia.WinUI.Converters;
|
||||
|
||||
public class BooleanToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public Visibility TrueValue { get; set; }
|
||||
public Visibility FalseValue { get; set; }
|
||||
|
||||
public BooleanToVisibilityConverter()
|
||||
{
|
||||
TrueValue = Visibility.Visible;
|
||||
FalseValue = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object? Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (!(value is bool))
|
||||
return null;
|
||||
|
||||
return (bool)value ? TrueValue : FalseValue;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (Equals(value, TrueValue))
|
||||
return true;
|
||||
|
||||
if (Equals(value, FalseValue))
|
||||
return false;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,13 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
}
|
||||
];
|
||||
|
||||
private bool _isPlaylistLocked;
|
||||
public bool IsPlaylistLocked
|
||||
{
|
||||
get => _isPlaylistLocked;
|
||||
private set => SetProperty(ref _isPlaylistLocked, value);
|
||||
}
|
||||
|
||||
public IAsyncRelayCommand PlaySongCommand { get; }
|
||||
public IAsyncRelayCommand NewPlaylistCommand { get; }
|
||||
public IAsyncRelayCommand AddFilesCommand { get; }
|
||||
@@ -151,7 +158,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
public IRelayCommand RandomizeSelectedCommand { get; }
|
||||
public IRelayCommand ReverseAllCommand { get; }
|
||||
public IRelayCommand ReverseSelectedCommand { get; }
|
||||
public IRelayCommand ToggleLockCommand { get; }
|
||||
public IRelayCommand LockPlaylistCommand { get; }
|
||||
public IRelayCommand UnlockPlaylistCommand { get; }
|
||||
|
||||
public bool IsUserUpdating { get; set; }
|
||||
private bool _isUserInitiatingSongChange;
|
||||
@@ -204,7 +212,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
RandomizeSelectedCommand = new RelayCommand(RandomizeSelectedSongs, AreMultipleSongsSelected);
|
||||
ReverseAllCommand = new RelayCommand(ReverseAllSongs);
|
||||
ReverseSelectedCommand = new RelayCommand(ReverseSelectedSongs, AreMultipleSongsSelected);
|
||||
ToggleLockCommand = new RelayCommand(ToggleLock);
|
||||
LockPlaylistCommand = new RelayCommand(LockPlaylist);
|
||||
UnlockPlaylistCommand = new RelayCommand(UnlockPlaylist);
|
||||
|
||||
FilteredPlaylistSongs.CollectionChanged += OnFilteredPlaylistSongsCollectionChanged;
|
||||
|
||||
@@ -267,6 +276,8 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
Playlist = _playlistManager.CurrentPlaylist;
|
||||
Playlist?.PlaylistUpdated += OnPlaylistUpdated;
|
||||
|
||||
IsPlaylistLocked = Playlist?.IsLocked ?? false;
|
||||
|
||||
UpdateFilteredSongs();
|
||||
}
|
||||
|
||||
@@ -286,6 +297,10 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
case PlaylistUpdateAction.Reset:
|
||||
_dispatcherQueue.TryEnqueue(() => ApplyReorderedSongs(e.Songs));
|
||||
break;
|
||||
case PlaylistUpdateAction.Lock:
|
||||
case PlaylistUpdateAction.Unlock:
|
||||
IsPlaylistLocked = Playlist?.IsLocked ?? false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,19 +752,14 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
RestoreSelectedSongs(selectedPlaylistSongIds);
|
||||
}
|
||||
|
||||
private void ToggleLock()
|
||||
private void LockPlaylist()
|
||||
{
|
||||
if (Playlist == null)
|
||||
return;
|
||||
Playlist?.Lock();
|
||||
}
|
||||
|
||||
if (Playlist.IsLocked)
|
||||
{
|
||||
Playlist.Unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
Playlist.Lock();
|
||||
}
|
||||
private void UnlockPlaylist()
|
||||
{
|
||||
Playlist?.Unlock();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Harmonia.WinUI.Views"
|
||||
xmlns:vm="using:Harmonia.WinUI.ViewModels"
|
||||
xmlns:converter="using:Harmonia.WinUI.Converters"
|
||||
xmlns:playlists="using:Harmonia.Core.Playlists"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -11,6 +12,9 @@
|
||||
d:DataContext="{d:DesignInstance Type=vm:PlaylistDetailViewModel, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<converter:BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
<converter:BooleanToVisibilityConverter x:Key="InverseBoolToVis" TrueValue="Collapsed" FalseValue="Visible"/>
|
||||
|
||||
<!--<SolidColorBrush x:Key="PlaylistBackground" Color="#393a45"/>-->
|
||||
<SolidColorBrush x:Key="PlaylistBackground" Color="#292a35"/>
|
||||
<SolidColorBrush x:Key="PlaylistItemHighlightColor" Color="#494a55"/>
|
||||
@@ -168,9 +172,12 @@
|
||||
<MenuFlyoutItem Text="Remove Missing" Command="{Binding RemoveMissingSongsCommand}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<ToggleMenuFlyoutItem Text="Lock Playlist" IsChecked="{Binding Playlist.IsLocked}">
|
||||
</ToggleMenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutItem Text="Lock Playlist" Command="{Binding LockPlaylistCommand}" Visibility="{Binding IsPlaylistLocked, Converter={StaticResource InverseBoolToVis}}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutItem Text="Unlock Playlist" Command="{Binding UnlockPlaylistCommand}" Visibility="{Binding IsPlaylistLocked, Converter={StaticResource BoolToVis}}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutSeparator></MenuFlyoutSeparator>
|
||||
|
||||
<MenuFlyoutItem Text="Remove Playlist" Foreground="#ff99a4" Command="{Binding DeletePlaylistCommand}">
|
||||
|
||||
Reference in New Issue
Block a user