mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-05-22 21:40:31 -05:00
Add combobox filtering for tuples
Also adjust the UI for narrower names and wider content.
This commit is contained in:
parent
ce4f4d0206
commit
536acf39db
|
|
@ -135,7 +135,13 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
|
|||
public int Start { get; private set; }
|
||||
public string EnumName => seg.SourceName;
|
||||
|
||||
public IReadOnlyList<string> Options => ArrayRunEnumSegment.GetOptions(viewPort.Model, EnumName).ToList();
|
||||
public IReadOnlyList<string> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -462,17 +462,18 @@
|
|||
<Grid HorizontalAlignment="Stretch" Margin="2" Width="120" Visibility="{Binding Visible, Converter={StaticResource BoolToVisibility}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Name}" Margin="5,0" Grid.Column="0"/>
|
||||
<ComboBox ItemsSource="{Binding Options}" SelectedIndex="{Binding SelectedIndex}" Grid.Column="1"/>
|
||||
<ComboBox ItemsSource="{Binding Options}" SelectedIndex="{Binding SelectedIndex}" Grid.Column="1"
|
||||
IsEditable="True" Text="{Binding FilterText}" IsTextSearchEnabled="False" PreviewTextInput="ComboBoxTupleElementTextInput"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type hsg3hvmtr:NumericTupleElementViewModel}">
|
||||
<Grid HorizontalAlignment="Stretch" Margin="2" Width="120" Visibility="{Binding Visible, Converter={StaticResource BoolToVisibility}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Name}" Margin="5,0" Grid.Column="0"/>
|
||||
<UserControl Margin="5,0" Grid.Column="1" IsTabStop="True" Focusable="True"
|
||||
|
|
|
|||
|
|
@ -445,6 +445,16 @@ namespace HavenSoft.HexManiac.WPF.Controls {
|
|||
viewModel.IsFiltering = filter;
|
||||
}
|
||||
|
||||
private void ComboBoxTupleElementTextInput(object sender, TextCompositionEventArgs e) {
|
||||
var element = (FrameworkElement)sender;
|
||||
var viewModel = (EnumTupleElementViewModel)element.DataContext;
|
||||
var keyString = e.Text;
|
||||
var filter = false;
|
||||
if (keyString.Length == 1 && char.IsLetterOrDigit(keyString[0])) filter = true;
|
||||
else if (keyString.Length == 1 && keyString[0].IsAny(" '?\"-_".ToCharArray())) filter = true;
|
||||
viewModel.IsFiltering = filter;
|
||||
}
|
||||
|
||||
private void ComboBoxArrayElementViewKeyDown(object sender, KeyEventArgs e) {
|
||||
var element = (FrameworkElement)sender;
|
||||
var viewModel = (ComboBoxArrayElementViewModel)element.DataContext;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user