mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-02 12:14:26 -07:00
add selected songs count display
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
</Menu>
|
||||
|
||||
<TabControl>
|
||||
<TabItem Header="selection">
|
||||
<TabItem Name="TabSelection" Header="selection">
|
||||
<UserControl Name="SelectionControl"/>
|
||||
</TabItem>
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Threading;
|
||||
using MercuryConverter.Data;
|
||||
using MercuryConverter.UI.Dialogs;
|
||||
using MercuryConverter.UI.Views;
|
||||
|
||||
@@ -30,6 +32,9 @@ public partial class MainWindow : Window
|
||||
|
||||
// Show dialog on startup
|
||||
Activated += OnActivated;
|
||||
|
||||
Selection.selections.CollectionChanged += OnDbSelChanged;
|
||||
Database.Songs.CollectionChanged += OnDbSelChanged;
|
||||
}
|
||||
|
||||
private void OnActivated(object? sender, EventArgs e)
|
||||
@@ -41,6 +46,14 @@ public partial class MainWindow : Window
|
||||
Dialog.IsOpen = true;
|
||||
}
|
||||
|
||||
private void OnDbSelChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (Database.Songs.Count > 0)
|
||||
{
|
||||
TabSelection.Header = $"selection ({Selection.selections.Count}/{Database.Songs.Count})";
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenDataHandler()
|
||||
{
|
||||
Dialog.IsOpen = true;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace MercuryConverter.UI.Views;
|
||||
|
||||
public partial class Selection : Panel
|
||||
{
|
||||
private List<Song> selections;
|
||||
public static ObservableRangeCollection<Song> selections = new();
|
||||
|
||||
public Selection()
|
||||
{
|
||||
@@ -62,9 +62,19 @@ public partial class Selection : Panel
|
||||
|
||||
private void OnSelectionChange(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count > 0)
|
||||
selections.Clear();
|
||||
List<Song> sels = new();
|
||||
foreach (Song s in ListingTable.SelectedItems)
|
||||
{
|
||||
var song = (Song) e.AddedItems[e.AddedItems.Count-1]!;
|
||||
sels.Add(s);
|
||||
}
|
||||
selections.AddRange(sels);
|
||||
|
||||
if (ListingTable.SelectedItems.Count > 0)
|
||||
{
|
||||
Song song = e.AddedItems.Count > 0 ?
|
||||
(Song) e.AddedItems[e.AddedItems.Count - 1]! :
|
||||
(Song) ListingTable.SelectedItems[ListingTable.SelectedItems.Count - 1]!;
|
||||
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
public class ObservableRangeCollection<T> : ObservableCollection<T>
|
||||
{
|
||||
private bool _suppressNotification = false;
|
||||
|
||||
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
// Only raise the event if notifications are not suppressed
|
||||
if (!_suppressNotification)
|
||||
{
|
||||
base.OnCollectionChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<T> collection)
|
||||
{
|
||||
if (collection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(collection));
|
||||
}
|
||||
|
||||
_suppressNotification = true; // Suppress notifications during bulk add
|
||||
|
||||
foreach (var item in collection)
|
||||
{
|
||||
Items.Add(item); // Add items using the underlying IList<T>
|
||||
}
|
||||
|
||||
_suppressNotification = false; // Re-enable notifications
|
||||
|
||||
// Raise a single Reset event to notify about the bulk change
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user