From 536acf39dbbbfe8b5bb12ed91c70ea4de582fb3f Mon Sep 17 00:00:00 2001 From: Benjamin Popp Date: Wed, 10 Feb 2021 14:00:31 -0600 Subject: [PATCH] Add combobox filtering for tuples Also adjust the UI for narrower names and wider content. --- .../Tools/TupleArrayElementViewModel.cs | 38 ++++++++++++++++++- src/HexManiac.WPF/Controls/TabView.xaml | 7 ++-- src/HexManiac.WPF/Controls/TabView.xaml.cs | 10 +++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/HexManiac.Core/ViewModels/Tools/TupleArrayElementViewModel.cs b/src/HexManiac.Core/ViewModels/Tools/TupleArrayElementViewModel.cs index 9e9df866..2dddfba5 100644 --- a/src/HexManiac.Core/ViewModels/Tools/TupleArrayElementViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Tools/TupleArrayElementViewModel.cs @@ -135,7 +135,13 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools { public int Start { get; private set; } public string EnumName => seg.SourceName; - public IReadOnlyList Options => ArrayRunEnumSegment.GetOptions(viewPort.Model, EnumName).ToList(); + public IReadOnlyList Options { + get { + var fullOptions = ArrayRunEnumSegment.GetOptions(viewPort.Model, EnumName).ToList(); + if (!isFiltering) return fullOptions; + return fullOptions.Where(option => option.MatchesPartial(filterText, onlyCheckLettersAndDigits: true)).ToList(); + } + } public int SelectedIndex { get => seg.Read(viewPort.Model, Start, BitOffset); @@ -145,6 +151,36 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools { } } + #region Filtering + + private int recursionCheck; + + private bool isFiltering; + public bool IsFiltering { get => isFiltering; set => Set(ref isFiltering, value); } + + private string filterText; + public string FilterText { + get => filterText; + set => Set(ref filterText, value, FilterTextChanged); + } + + private void FilterTextChanged(string oldValue) { + if (recursionCheck != 0 || !isFiltering) return; + recursionCheck++; + var fullOptions = ArrayRunEnumSegment.GetOptions(viewPort.Model, EnumName).ToList(); + var options = fullOptions.Where(option => option.MatchesPartial(filterText, onlyCheckLettersAndDigits: true)).ToList(); + if (SelectedIndex >= 0 && SelectedIndex < fullOptions.Count && Options.Contains(fullOptions[SelectedIndex])) { + // selected index is already fine + } else if (options.Count > 0) { + // based on typing filter text, we can change the selection + SelectedIndex = fullOptions.IndexOf(options[0]); + } + NotifyPropertyChanged(nameof(Options)); + recursionCheck--; + } + + #endregion + public EnumTupleElementViewModel(ViewPort viewPort, int start, int bitOffset, TupleSegment segment) { (this.viewPort, Start, BitOffset, seg) = (viewPort, start, bitOffset, segment); } diff --git a/src/HexManiac.WPF/Controls/TabView.xaml b/src/HexManiac.WPF/Controls/TabView.xaml index 645bed8e..8811d47f 100644 --- a/src/HexManiac.WPF/Controls/TabView.xaml +++ b/src/HexManiac.WPF/Controls/TabView.xaml @@ -462,17 +462,18 @@ - + - + - +