mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Filter Block Dump data (#3840)
* Allow the filter results in BlockDump combobox. Write a text in the dropdown
This commit is contained in:
parent
ecbf6c06de
commit
7af65a4683
1 changed files with 44 additions and 5 deletions
|
@ -13,8 +13,10 @@ public partial class SAV_BlockDump8 : Form
|
||||||
{
|
{
|
||||||
private readonly ISCBlockArray SAV;
|
private readonly ISCBlockArray SAV;
|
||||||
private readonly SCBlockMetadata Metadata;
|
private readonly SCBlockMetadata Metadata;
|
||||||
|
private readonly ComboItem[] SortedBlockKeys;
|
||||||
|
|
||||||
private SCBlock CurrentBlock = null!;
|
private SCBlock CurrentBlock = null!;
|
||||||
|
private string Filter = string.Empty;
|
||||||
|
|
||||||
public SAV_BlockDump8(ISCBlockArray sav)
|
public SAV_BlockDump8(ISCBlockArray sav)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +31,8 @@ public partial class SAV_BlockDump8 : Form
|
||||||
Metadata = new SCBlockMetadata(SAV.Accessor, extra, Main.Settings.Advanced.GetExclusionList8());
|
Metadata = new SCBlockMetadata(SAV.Accessor, extra, Main.Settings.Advanced.GetExclusionList8());
|
||||||
|
|
||||||
CB_Key.InitializeBinding();
|
CB_Key.InitializeBinding();
|
||||||
CB_Key.DataSource = Metadata.GetSortedBlockKeyList().ToArray();
|
SortedBlockKeys = Metadata.GetSortedBlockKeyList().ToArray();
|
||||||
|
CB_Key.DataSource = SortedBlockKeys;
|
||||||
|
|
||||||
CB_TypeToggle.InitializeBinding();
|
CB_TypeToggle.InitializeBinding();
|
||||||
CB_TypeToggle.DataSource = new[]
|
CB_TypeToggle.DataSource = new[]
|
||||||
|
@ -38,6 +41,7 @@ public partial class SAV_BlockDump8 : Form
|
||||||
new ComboItem(nameof(SCTypeCode.Bool2), (int)SCTypeCode.Bool2),
|
new ComboItem(nameof(SCTypeCode.Bool2), (int)SCTypeCode.Bool2),
|
||||||
};
|
};
|
||||||
CB_TypeToggle.SelectedIndexChanged += CB_TypeToggle_SelectedIndexChanged;
|
CB_TypeToggle.SelectedIndexChanged += CB_TypeToggle_SelectedIndexChanged;
|
||||||
|
CB_Key.KeyDown += WinFormsUtil.RemoveDropCB;
|
||||||
|
|
||||||
CB_Key.SelectedIndex = 0;
|
CB_Key.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
@ -267,10 +271,45 @@ public partial class SAV_BlockDump8 : Form
|
||||||
if (e.KeyCode != Keys.Enter)
|
if (e.KeyCode != Keys.Enter)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var text = CB_Key.Text;
|
var text = CB_Key.Text.Trim();
|
||||||
if (text.Length != 8)
|
if (text.Length == 8)
|
||||||
return;
|
{
|
||||||
|
var hex = (int)Util.GetHexValue(text);
|
||||||
|
if (hex != 0)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Filter))
|
||||||
|
{
|
||||||
|
// Clear the filter
|
||||||
|
CB_Key.DataSource = SortedBlockKeys;
|
||||||
|
Filter = string.Empty;
|
||||||
|
}
|
||||||
|
// Input is hexadecimal number, select the item
|
||||||
|
CB_Key.SelectedValue = hex;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CB_Key.SelectedValue = (int)Util.GetHexValue(text);
|
if (CB_Key.SelectedItem != null && text.Equals(CB_Key.SelectedText))
|
||||||
|
return; // User press enter on selected item
|
||||||
|
|
||||||
|
if (Filter.Equals(text, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return; // Filter hasn't changed
|
||||||
|
|
||||||
|
Filter = text;
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
// User has cleared the filter. Restore original metadata
|
||||||
|
CB_Key.DataSource = SortedBlockKeys;
|
||||||
|
CB_Key.SelectedIndex = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter combo items that contains input text
|
||||||
|
var filtered = Array.FindAll(SortedBlockKeys, x => x.Text.Contains(text, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
if (filtered.Length == 0)
|
||||||
|
return; // no results
|
||||||
|
|
||||||
|
CB_Key.DataSource = filtered;
|
||||||
|
CB_Key.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue