mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-02 20:24:26 -07:00
add search function
This commit is contained in:
+22
-4
@@ -2,11 +2,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Avalonia.Threading;
|
||||
using FFMpegCore.Arguments;
|
||||
using MercuryConverter.Utility;
|
||||
using SaturnData.Notation.Core;
|
||||
using Tmds.DBus.Protocol;
|
||||
using UAssetAPI;
|
||||
using UAssetAPI.ExportTypes;
|
||||
using UAssetAPI.PropertyTypes.Objects;
|
||||
@@ -118,13 +117,32 @@ public static class Database
|
||||
song.Levels[(int)diff] = (lvl, data[Consts.DIFF_DESIGNER_KEY[diff]].ToString()!);
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(() => Songs.Add(song));
|
||||
Dispatcher.UIThread.Invoke(() => Songs.Add(song));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Couldn't construct a song!\n{e}");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Data setup finished.");
|
||||
Console.WriteLine($"Data setup finished with {Songs.Count} songs.");
|
||||
|
||||
// SEARCH TEST
|
||||
var camellia = Search("camellia").ToList();
|
||||
camellia.ForEach(Console.WriteLine);
|
||||
}
|
||||
|
||||
public static IEnumerable<Song> Search(string substr)
|
||||
{
|
||||
var sanitized = substr.ToLower().Trim();
|
||||
|
||||
if (sanitized == "")
|
||||
return Songs;
|
||||
|
||||
return Songs.Where(s =>
|
||||
{
|
||||
return
|
||||
s.Artist.ToLower().Contains(sanitized) ||
|
||||
s.Name.ToLower().Contains(sanitized);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -104,4 +104,9 @@ public class Song
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{Id}] {Artist} - {Name}";
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@
|
||||
<!-- Song Listing Table -->
|
||||
<DockPanel>
|
||||
<DockPanel Margin="0 4 0 8" DockPanel.Dock="Top">
|
||||
<TextBox Watermark="Search for title, artist, designer..."/>
|
||||
<TextBox Watermark="Search for song title or artist..." TextChanged="OnSearchTextChange"/>
|
||||
</DockPanel>
|
||||
<UserControl Background="{DynamicResource DataGridContentBackground}">
|
||||
<DataGrid Name="ListingTable" IsReadOnly="True" SelectionMode="Extended" ItemsSource="{x:Static data:Database.Songs}"
|
||||
|
||||
@@ -104,4 +104,17 @@ public partial class Selection : Panel
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSearchTextChange(object? _, TextChangedEventArgs args)
|
||||
{
|
||||
var src = (TextBox)args.Source!;
|
||||
if (string.IsNullOrEmpty(src.Text))
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => ListingTable.ItemsSource = Database.Songs);
|
||||
return;
|
||||
}
|
||||
|
||||
var searchResults = Database.Search(src.Text.ToLower());
|
||||
Dispatcher.UIThread.Post(() => ListingTable.ItemsSource = searchResults);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user