diff --git a/UndertaleModTool/Converters/CodeViewConverter.cs b/UndertaleModTool/Converters/CodeViewConverter.cs new file mode 100644 index 000000000..359453e69 --- /dev/null +++ b/UndertaleModTool/Converters/CodeViewConverter.cs @@ -0,0 +1,24 @@ +using System; +using System.ComponentModel; +using System.Windows.Data; +using UndertaleModLib.Models; + +namespace UndertaleModTool +{ + [ValueConversion(typeof(object), typeof(ICollectionView))] + public class CodeViewConverter : FilteredViewConverter + { + protected override Predicate CreateFilter() + { + Predicate baseFilter = base.CreateFilter(); + return (obj) => + { + if (obj is UndertaleCode code && + code.ParentEntry is not null && + SettingsWindow.HideChildCodeEntries) + return false; + return baseFilter(obj); + }; + } + } +} diff --git a/UndertaleModTool/Converters/FilteredViewConverter.cs b/UndertaleModTool/Converters/FilteredViewConverter.cs index fa6bed3b0..465217f14 100644 --- a/UndertaleModTool/Converters/FilteredViewConverter.cs +++ b/UndertaleModTool/Converters/FilteredViewConverter.cs @@ -26,12 +26,9 @@ public string Filter set { SetValue(FilterProperty, value); } } - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + protected virtual Predicate CreateFilter() { - if (value == null) - return null; - ICollectionView filteredView = CollectionViewSource.GetDefaultView(value); - filteredView.Filter = (obj) => + return (obj) => { if (String.IsNullOrEmpty(Filter)) return true; @@ -44,6 +41,14 @@ public object Convert(object value, Type targetType, object parameter, CultureIn .Any(x => (x?.IndexOf(Filter, StringComparison.OrdinalIgnoreCase) ?? -1) >= 0); return true; }; + } + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is null) + return null; + ICollectionView filteredView = CollectionViewSource.GetDefaultView(value); + filteredView.Filter = CreateFilter(); return filteredView; } diff --git a/UndertaleModTool/MainWindow.xaml b/UndertaleModTool/MainWindow.xaml index 2ff7ef5d6..3ecf42f55 100644 --- a/UndertaleModTool/MainWindow.xaml +++ b/UndertaleModTool/MainWindow.xaml @@ -23,6 +23,7 @@ + @@ -388,7 +389,7 @@ - +