From 527fce72c47d19021c2232da61138fea334131b6 Mon Sep 17 00:00:00 2001 From: zivmaor Date: Fri, 20 Sep 2024 22:13:24 +0300 Subject: [PATCH 1/9] Implement CodeViewConverter which filters child code entries from the code list on top of the normal filtering done by FilteringViewConverter. --- .../Converters/CodeViewConverter.cs | 22 +++++++++++++++++++ .../Converters/FilteredViewConverter.cs | 15 ++++++++----- UndertaleModTool/MainWindow.xaml | 3 ++- 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 UndertaleModTool/Converters/CodeViewConverter.cs diff --git a/UndertaleModTool/Converters/CodeViewConverter.cs b/UndertaleModTool/Converters/CodeViewConverter.cs new file mode 100644 index 000000000..2920c471f --- /dev/null +++ b/UndertaleModTool/Converters/CodeViewConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.ComponentModel; +using System.Windows.Data; +using UndertaleModLib.Models; + +namespace UndertaleModTool +{ + [ValueConversion(typeof(object), typeof(ICollectionView))] + public class CodeViewConverter : FilteredViewConverter + { + public override Predicate CreateFilter() + { + Predicate baseFilter = base.CreateFilter(); + return (obj) => + { + if (obj is UndertaleCode code && code.ParentEntry != null) + return false; + return baseFilter(obj); + }; + } + } +} diff --git a/UndertaleModTool/Converters/FilteredViewConverter.cs b/UndertaleModTool/Converters/FilteredViewConverter.cs index fa6bed3b0..b38f3b25b 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) + public 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 == 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 @@ - +