Skip to content

Commit

Permalink
Fix crash when trying to edit note in filtered view
Browse files Browse the repository at this point in the history
  • Loading branch information
segabl committed May 6, 2021
1 parent aa5ea2e commit a62e080
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }

Expand Down Expand Up @@ -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<object>(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) {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion PD2SoundBankEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<StartupObject></StartupObject>
<AssemblyName>PD2SoundBankEditor</AssemblyName>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down

0 comments on commit a62e080

Please sign in to comment.