From a62e0807cc96fe2aa12309b0aaa40c720be7c5ec Mon Sep 17 00:00:00 2001 From: Sebastian Gabl Date: Thu, 6 May 2021 13:11:56 +0200 Subject: [PATCH] Fix crash when trying to edit note in filtered view --- MainWindow.xaml.cs | 14 +++++++++----- PD2SoundBankEditor.csproj | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 0a40359..c8fe858 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -12,6 +12,7 @@ using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Media; using MessageBox = AdonisUI.Controls.MessageBox; using MessageBoxButton = AdonisUI.Controls.MessageBoxButton; @@ -33,6 +34,7 @@ public partial class MainWindow : AdonisWindow { private SoundBank soundBank; private Button playingButton; private bool converterAvailable; + private CollectionViewSource soundBankViewSource = new CollectionViewSource(); public bool UpdateCheckEnabled { get => appSettings.checkForUpdates; set => appSettings.checkForUpdates = value; } @@ -177,15 +179,15 @@ private void OnReplaceButtonClick(object sender, RoutedEventArgs e) { private void OnFilterTextBoxChanged(object sender, RoutedEventArgs e) { var text = (sender as TextBox).Text; + var view = soundBankViewSource.View; if (text.Length > 0) { var rx = new Regex(text, RegexOptions.Compiled); - var filtered = soundBank.StreamInfos.Where(info => rx.Match(info.Note).Success || rx.Match(info.Id.ToString()).Success); - dataGrid.ItemsSource = filtered; - dataGrid.DataContext = filtered; + view.Filter = new Predicate(info => rx.Match((info as StreamInfo).Note).Success || rx.Match((info as StreamInfo).Id.ToString()).Success); } else { - dataGrid.ItemsSource = soundBank.StreamInfos; - dataGrid.DataContext = soundBank.StreamInfos; + view.Filter = null; } + dataGrid.ItemsSource = view; + dataGrid.DataContext = view; } private void OnPlayButtonClick(object sender, RoutedEventArgs e) { @@ -309,6 +311,8 @@ public void OnSoundBankLoaded(object sender, RunWorkerCompletedEventArgs e) { return; } + soundBankViewSource.Source = soundBank.StreamInfos; + if (appSettings.recentlyOpenedFiles.Contains(soundBank.FilePath)) { appSettings.recentlyOpenedFiles.Remove(soundBank.FilePath); } diff --git a/PD2SoundBankEditor.csproj b/PD2SoundBankEditor.csproj index aed39e5..41374da 100644 --- a/PD2SoundBankEditor.csproj +++ b/PD2SoundBankEditor.csproj @@ -6,7 +6,7 @@ true PD2SoundBankEditor - 1.0.0 + 1.0.1 1.0.0.0 1.0.0.0 en