Added playlist renaming functionality.
This commit is contained in:
@@ -5,4 +5,5 @@ namespace Harmonia.WinUI.Messaging;
|
||||
public interface IMessageService
|
||||
{
|
||||
Task<bool> ConfirmAsync(string title, string message);
|
||||
Task<string> InputTextAsync(string title, string message, string defaultText = "");
|
||||
}
|
||||
@@ -27,4 +27,44 @@ public class WindowsMessageService : IMessageService
|
||||
|
||||
return result == ContentDialogResult.Primary;
|
||||
}
|
||||
|
||||
public async Task<string> InputTextAsync(string title, string message, string defaultText = "")
|
||||
{
|
||||
TextBox inputTextBox = new()
|
||||
{
|
||||
Text = defaultText,
|
||||
Margin = new Thickness(0, 10, 0, 0)
|
||||
};
|
||||
|
||||
inputTextBox.SelectAll();
|
||||
|
||||
ContentDialog dialog = new()
|
||||
{
|
||||
XamlRoot = MainWindow.Content.XamlRoot,
|
||||
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
|
||||
Title = title,
|
||||
Content = new StackPanel
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new TextBlock { Text = message },
|
||||
inputTextBox
|
||||
}
|
||||
},
|
||||
PrimaryButtonText = "OK",
|
||||
CloseButtonText = "Cancel",
|
||||
DefaultButton = ContentDialogButton.Primary
|
||||
};
|
||||
|
||||
ContentDialogResult result = await dialog.ShowAsync();
|
||||
|
||||
if (result == ContentDialogResult.Primary)
|
||||
{
|
||||
return inputTextBox.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,7 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
public IRelayCommand RandomizeSelectedCommand { get; }
|
||||
public IRelayCommand ReverseAllCommand { get; }
|
||||
public IRelayCommand ReverseSelectedCommand { get; }
|
||||
public IAsyncRelayCommand RenamePlaylistCommand { get; }
|
||||
public IRelayCommand LockPlaylistCommand { get; }
|
||||
public IRelayCommand UnlockPlaylistCommand { get; }
|
||||
|
||||
@@ -212,6 +213,7 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
RandomizeSelectedCommand = new RelayCommand(RandomizeSelectedSongs, AreMultipleSongsSelected);
|
||||
ReverseAllCommand = new RelayCommand(ReverseAllSongs);
|
||||
ReverseSelectedCommand = new RelayCommand(ReverseSelectedSongs, AreMultipleSongsSelected);
|
||||
RenamePlaylistCommand = new AsyncRelayCommand(RenamePlaylist);
|
||||
LockPlaylistCommand = new RelayCommand(LockPlaylist);
|
||||
UnlockPlaylistCommand = new RelayCommand(UnlockPlaylist);
|
||||
|
||||
@@ -762,6 +764,22 @@ public partial class PlaylistDetailViewModel : ViewModelBase
|
||||
Playlist?.Unlock();
|
||||
}
|
||||
|
||||
private async Task RenamePlaylist()
|
||||
{
|
||||
if (Playlist == null)
|
||||
return;
|
||||
|
||||
string newName = await _messageService.InputTextAsync(
|
||||
$"Rename Playlist - {Playlist.Name}",
|
||||
"Enter a new name for the playlist:",
|
||||
Playlist.Name ?? string.Empty);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
return;
|
||||
|
||||
Playlist.SetName(newName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,19 @@ public partial class PlaylistItemViewModel : ObservableObject
|
||||
{
|
||||
public Playlist Playlist { get; private set; }
|
||||
|
||||
private string _name = string.Empty;
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _summary = string.Empty;
|
||||
public string Summary
|
||||
{
|
||||
@@ -41,6 +54,8 @@ public partial class PlaylistItemViewModel : ObservableObject
|
||||
|
||||
private void UpdateMetaData()
|
||||
{
|
||||
Name = Playlist.Name ?? "Untitled Playlist";
|
||||
|
||||
TimeSpan total = TimeSpan.FromSeconds(Playlist.Songs.Sum(s => s.Song.Length.TotalSeconds));
|
||||
Summary = $"{Playlist.Songs.Count} songs / {total:h\\:mm\\:ss}";
|
||||
}
|
||||
|
||||
@@ -172,6 +172,9 @@
|
||||
<MenuFlyoutItem Text="Remove Missing" Command="{Binding RemoveMissingSongsCommand}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutItem Text="Rename Playlist" Command="{Binding RenamePlaylistCommand}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
<MenuFlyoutItem Text="Lock Playlist" Command="{Binding LockPlaylistCommand}" Visibility="{Binding IsPlaylistLocked, Converter={StaticResource InverseBoolToVis}}">
|
||||
</MenuFlyoutItem>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<Viewbox Height="24" Width="24">
|
||||
<PathIcon Data="{StaticResource MusicNoteList}" />
|
||||
</Viewbox>
|
||||
<TextBlock Text="{x:Bind Playlist.Name}" FontSize="16" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{x:Bind Name, Mode=OneWay}" FontSize="16" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Spacing="8">
|
||||
<TextBlock Text="{x:Bind Summary, Mode=OneWay}" Style="{StaticResource PlaylistSubtitleTextBlock}" />
|
||||
|
||||
Reference in New Issue
Block a user