Compare commits

..

4 Commits

Author SHA1 Message Date
emoose
75e729298d Form: add collapsible group headers
Collapsed groups will be saved into HiddenGroups.ini next to NVPI exe

.NET ListView sadly doesn't support collapsing for some reason, but
since it's based on Win32 ListView which does support them, it could
be extended to make use of it

(still had to add extra code to receive the undocumented notify when
user collapses/expands groups though, ugh)

With this the settings refresh is a little slower, added something so
that search filtering only applies 250ms after user finishes typing,
seems to help with that.

(if slower machines have issues with this we can always revert or make
optional)
2025-07-28 00:08:40 +01:00
emoose
5ac60d82ca Form: redirect keypresses from listview to filter textbox 2025-07-27 21:38:55 +01:00
emoose
b2306bb310 Form: update filter textbox font style 2025-07-27 21:09:15 +01:00
emoose
f4e2a2fe69 Form: fix values combobox mispositioning 2025-07-27 20:34:07 +01:00
3 changed files with 612 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
@@ -16,6 +17,8 @@ namespace nspector
public event DropFilesNativeHandler OnDropFilesNative;
public event EventHandler<GroupStateChangedEventArgs> GroupStateChanged;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wPar, IntPtr lPar);
@@ -85,8 +88,14 @@ namespace nspector
if (SubItem >= order.Length)
throw new IndexOutOfRangeException("SubItem "+SubItem+" out of range");
Rectangle lviBounds = Item.GetBounds(ItemBoundsPortion.Entire);
int subItemX = lviBounds.Left;
Rectangle lviBounds;
try
{
lviBounds = Item.GetBounds(ItemBoundsPortion.Entire);
}
catch { return subItemRect; }
int subItemX = lviBounds.Left;
ColumnHeader col;
int i;
@@ -178,6 +187,12 @@ namespace nspector
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONUP)
{
base.DefWndProc(ref m); // Fix for collapsible buttons
return;
}
switch (m.Msg)
{
case WM_PAINT:
@@ -276,6 +291,46 @@ namespace nspector
base.WndProc(ref m);
break;
case WM_NOTIFY:
case WM_REFLECT_NOTIFY:
var nmhdr = (NMHDR)Marshal.PtrToStructure(m.LParam, typeof(NMHDR));
// Check if this is an (undocumented) listview group notification
// https://www.zabkat.com/blog/05Feb12-collapsible-listview.htm
if (nmhdr.code == LVN_GROUPINFO && !_isUpdatingGroups)
{
// Group state has changed - get the group info
var lvGroupInfo = (NMLVGROUP)Marshal.PtrToStructure(m.LParam, typeof(NMLVGROUP));
// Find the corresponding ListViewGroup
ListViewGroup changedGroup = null;
foreach (ListViewGroup group in this.Groups)
{
int? groupId = GetGroupID(group);
if (groupId.HasValue && groupId.Value == lvGroupInfo.iGroupId)
{
changedGroup = group;
break;
}
}
if (changedGroup != null)
{
// Determine if collapsed or expanded based on state
bool isCollapsed = (lvGroupInfo.uNewState & (int)ListViewGroupState.Collapsed) != 0;
// Fire the event
GroupStateChanged?.Invoke(this, new GroupStateChangedEventArgs
{
Group = changedGroup,
IsCollapsed = isCollapsed,
NewState = (ListViewGroupState)lvGroupInfo.uNewState
});
}
}
break;
}
base.WndProc(ref m);
}
@@ -291,5 +346,401 @@ namespace nspector
}
}
}
// Collapsible groups - https://www.codeproject.com/Articles/451742/Extending-Csharp-ListView-with-Collapsible-Groups
private bool _isUpdatingGroups = false;
private const int WM_NOTIFY = 0x004E;
private const int WM_REFLECT_NOTIFY = 0x204E;
private const int LVN_FIRST = -100;
private const int LVN_GROUPINFO = (LVN_FIRST - 88);
private const int LVM_SETGROUPINFO = (LVM_FIRST + 147); // ListView messages Setinfo on Group
private const int WM_LBUTTONUP = 0x0202; // Windows message left button
private delegate void CallBackSetGroupState(ListViewGroup lstvwgrp, ListViewGroupState state);
private delegate void CallbackSetGroupString(ListViewGroup lstvwgrp, string value);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, LVGROUP lParam);
private static int? GetGroupID(ListViewGroup lstvwgrp)
{
int? rtnval = null;
Type GrpTp = lstvwgrp.GetType();
if (GrpTp != null)
{
PropertyInfo pi = GrpTp.GetProperty("ID", BindingFlags.NonPublic | BindingFlags.Instance);
if (pi != null)
{
object tmprtnval = pi.GetValue(lstvwgrp, null);
if (tmprtnval != null)
{
rtnval = tmprtnval as int?;
}
}
}
return rtnval;
}
private static void setGrpState(ListViewGroup lstvwgrp, ListViewGroupState state)
{
if (Environment.OSVersion.Version.Major < 6) //Only Vista and forward allows collaps of ListViewGroups
return;
if (lstvwgrp == null || lstvwgrp.ListView == null)
return;
if (lstvwgrp.ListView.InvokeRequired)
lstvwgrp.ListView.Invoke(new CallBackSetGroupState(setGrpState), lstvwgrp, state);
else
{
int? GrpId = GetGroupID(lstvwgrp);
int gIndex = lstvwgrp.ListView.Groups.IndexOf(lstvwgrp);
LVGROUP group = new LVGROUP();
group.CbSize = Marshal.SizeOf(group);
group.State = state;
group.Mask = ListViewGroupMask.State;
if (GrpId != null)
{
group.IGroupId = GrpId.Value;
SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, GrpId.Value, group);
SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, GrpId.Value, group);
}
else
{
group.IGroupId = gIndex;
SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, gIndex, group);
SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, gIndex, group);
}
lstvwgrp.ListView.Refresh();
}
}
private static void setGrpFooter(ListViewGroup lstvwgrp, string footer)
{
if (Environment.OSVersion.Version.Major < 6) //Only Vista and forward allows footer on ListViewGroups
return;
if (lstvwgrp == null || lstvwgrp.ListView == null)
return;
if (lstvwgrp.ListView.InvokeRequired)
lstvwgrp.ListView.Invoke(new CallbackSetGroupString(setGrpFooter), lstvwgrp, footer);
else
{
int? GrpId = GetGroupID(lstvwgrp);
int gIndex = lstvwgrp.ListView.Groups.IndexOf(lstvwgrp);
LVGROUP group = new LVGROUP();
group.CbSize = Marshal.SizeOf(group);
group.PszFooter = footer;
group.Mask = ListViewGroupMask.Footer;
if (GrpId != null)
{
group.IGroupId = GrpId.Value;
SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, GrpId.Value, group);
}
else
{
group.IGroupId = gIndex;
SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, gIndex, group);
}
}
}
public void SetGroupState(ListViewGroupState state)
{
_isUpdatingGroups = true;
foreach (ListViewGroup lvg in this.Groups)
setGrpState(lvg, state);
_isUpdatingGroups = false;
}
public void SetGroupState(ListViewGroup group, ListViewGroupState state)
{
_isUpdatingGroups = true;
setGrpState(group, state);
_isUpdatingGroups = false;
}
public void SetGroupFooter(ListViewGroup lvg, string footerText)
{
setGrpFooter(lvg, footerText);
}
}
/// <summary>
/// LVGROUP StructureUsed to set and retrieve groups.
/// </summary>
/// <example>
/// LVGROUP myLVGROUP = new LVGROUP();
/// myLVGROUP.CbSize // is of managed type uint
/// myLVGROUP.Mask // is of managed type uint
/// myLVGROUP.PszHeader // is of managed type string
/// myLVGROUP.CchHeader // is of managed type int
/// myLVGROUP.PszFooter // is of managed type string
/// myLVGROUP.CchFooter // is of managed type int
/// myLVGROUP.IGroupId // is of managed type int
/// myLVGROUP.StateMask // is of managed type uint
/// myLVGROUP.State // is of managed type uint
/// myLVGROUP.UAlign // is of managed type uint
/// myLVGROUP.PszSubtitle // is of managed type IntPtr
/// myLVGROUP.CchSubtitle // is of managed type uint
/// myLVGROUP.PszTask // is of managed type string
/// myLVGROUP.CchTask // is of managed type uint
/// myLVGROUP.PszDescriptionTop // is of managed type string
/// myLVGROUP.CchDescriptionTop // is of managed type uint
/// myLVGROUP.PszDescriptionBottom // is of managed type string
/// myLVGROUP.CchDescriptionBottom // is of managed type uint
/// myLVGROUP.ITitleImage // is of managed type int
/// myLVGROUP.IExtendedImage // is of managed type int
/// myLVGROUP.IFirstItem // is of managed type int
/// myLVGROUP.CItems // is of managed type IntPtr
/// myLVGROUP.PszSubsetTitle // is of managed type IntPtr
/// myLVGROUP.CchSubsetTitle // is of managed type IntPtr
/// </example>
/// <remarks>
/// The LVGROUP structure was created by Paw Jershauge
/// Created: Jan. 2008.
/// The LVGROUP structure code is based on information from Microsoft's MSDN2 website.
/// The structure is generated via an automated converter and is as is.
/// The structure may or may not hold errors inside the code, so use at own risk.
/// Reference url: http://msdn.microsoft.com/en-us/library/bb774769(VS.85).aspx
/// </remarks>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode), Description("LVGROUP StructureUsed to set and retrieve groups.")]
public struct LVGROUP
{
/// <summary>
/// Size of this structure, in bytes.
/// </summary>
[Description("Size of this structure, in bytes.")]
public int CbSize;
/// <summary>
/// Mask that specifies which members of the structure are valid input. One or more of the following values:LVGF_NONENo other items are valid.
/// </summary>
[Description("Mask that specifies which members of the structure are valid input. One or more of the following values:LVGF_NONE No other items are valid.")]
public ListViewGroupMask Mask;
/// <summary>
/// Pointer to a null-terminated string that contains the header text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the header text.
/// </summary>
[Description("Pointer to a null-terminated string that contains the header text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the header text.")]
[MarshalAs(UnmanagedType.LPWStr)]
public string PszHeader;
/// <summary>
/// Size in TCHARs of the buffer pointed to by the pszHeader member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Size in TCHARs of the buffer pointed to by the pszHeader member. If the structure is not receiving information about a group, this member is ignored.")]
public int CchHeader;
/// <summary>
/// Pointer to a null-terminated string that contains the footer text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the footer text.
/// </summary>
[Description("Pointer to a null-terminated string that contains the footer text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the footer text.")]
[MarshalAs(UnmanagedType.LPWStr)]
public string PszFooter;
/// <summary>
/// Size in TCHARs of the buffer pointed to by the pszFooter member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Size in TCHARs of the buffer pointed to by the pszFooter member. If the structure is not receiving information about a group, this member is ignored.")]
public int CchFooter;
/// <summary>
/// ID of the group.
/// </summary>
[Description("ID of the group.")]
public int IGroupId;
/// <summary>
/// Mask used with LVM_GETGROUPINFO (Microsoft Windows XP and Windows Vista) and LVM_SETGROUPINFO (Windows Vista only) to specify which flags in the state value are being retrieved or set.
/// </summary>
[Description("Mask used with LVM_GETGROUPINFO (Microsoft Windows XP and Windows Vista) and LVM_SETGROUPINFO (Windows Vista only) to specify which flags in the state value are being retrieved or set.")]
public int StateMask;
/// <summary>
/// Flag that can have one of the following values:LVGS_NORMALGroups are expanded, the group name is displayed, and all items in the group are displayed.
/// </summary>
[Description("Flag that can have one of the following values:LVGS_NORMAL Groups are expanded, the group name is displayed, and all items in the group are displayed.")]
public ListViewGroupState State;
/// <summary>
/// Indicates the alignment of the header or footer text for the group. It can have one or more of the following values. Use one of the header flags. Footer flags are optional. Windows XP: Footer flags are reserved.LVGA_FOOTER_CENTERReserved.
/// </summary>
[Description("Indicates the alignment of the header or footer text for the group. It can have one or more of the following values. Use one of the header flags. Footer flags are optional. Windows XP: Footer flags are reserved.LVGA_FOOTER_CENTERReserved.")]
public uint UAlign;
/// <summary>
/// Windows Vista. Pointer to a null-terminated string that contains the subtitle text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the subtitle text. This element is drawn under the header text.
/// </summary>
[Description("Windows Vista. Pointer to a null-terminated string that contains the subtitle text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the subtitle text. This element is drawn under the header text.")]
public IntPtr PszSubtitle;
/// <summary>
/// Windows Vista. Size, in TCHARs, of the buffer pointed to by the pszSubtitle member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Windows Vista. Size, in TCHARs, of the buffer pointed to by the pszSubtitle member. If the structure is not receiving information about a group, this member is ignored.")]
public uint CchSubtitle;
/// <summary>
/// Windows Vista. Pointer to a null-terminated string that contains the text for a task link when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the task text. This item is drawn right-aligned opposite the header text. When clicked by the user, the task link generates an LVN_LINKCLICK notification.
/// </summary>
[Description("Windows Vista. Pointer to a null-terminated string that contains the text for a task link when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the task text. This item is drawn right-aligned opposite the header text. When clicked by the user, the task link generates an LVN_LINKCLICK notification.")]
[MarshalAs(UnmanagedType.LPWStr)]
public string PszTask;
/// <summary>
/// Windows Vista. Size in TCHARs of the buffer pointed to by the pszTask member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Windows Vista. Size in TCHARs of the buffer pointed to by the pszTask member. If the structure is not receiving information about a group, this member is ignored.")]
public uint CchTask;
/// <summary>
/// Windows Vista. Pointer to a null-terminated string that contains the top description text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the top description text. This item is drawn opposite the title image when there is a title image, no extended image, and uAlign==LVGA_HEADER_CENTER.
/// </summary>
[Description("Windows Vista. Pointer to a null-terminated string that contains the top description text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the top description text. This item is drawn opposite the title image when there is a title image, no extended image, and uAlign==LVGA_HEADER_CENTER.")]
[MarshalAs(UnmanagedType.LPWStr)]
public string PszDescriptionTop;
/// <summary>
/// Windows Vista. Size in TCHARs of the buffer pointed to by the pszDescriptionTop member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Windows Vista. Size in TCHARs of the buffer pointed to by the pszDescriptionTop member. If the structure is not receiving information about a group, this member is ignored.")]
public uint CchDescriptionTop;
/// <summary>
/// Windows Vista. Pointer to a null-terminated string that contains the bottom description text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the bottom description text. This item is drawn under the top description text when there is a title image, no extended image, and uAlign==LVGA_HEADER_CENTER.
/// </summary>
[Description("Windows Vista. Pointer to a null-terminated string that contains the bottom description text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the bottom description text. This item is drawn under the top description text when there is a title image, no extended image, and uAlign==LVGA_HEADER_CENTER.")]
[MarshalAs(UnmanagedType.LPWStr)]
public string PszDescriptionBottom;
/// <summary>
/// Windows Vista. Size in TCHARs of the buffer pointed to by the pszDescriptionBottom member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Windows Vista. Size in TCHARs of the buffer pointed to by the pszDescriptionBottom member. If the structure is not receiving information about a group, this member is ignored.")]
public uint CchDescriptionBottom;
/// <summary>
/// Windows Vista. Index of the title image in the control imagelist.
/// </summary>
[Description("Windows Vista. Index of the title image in the control imagelist.")]
public int ITitleImage;
/// <summary>
/// Windows Vista. Index of the extended image in the control imagelist.
/// </summary>
[Description("Windows Vista. Index of the extended image in the control imagelist.")]
public int IExtendedImage;
/// <summary>
/// Windows Vista. Read-only.
/// </summary>
[Description("Windows Vista. Read-only.")]
public int IFirstItem;
/// <summary>
/// Windows Vista. Read-only in non-owner data mode.
/// </summary>
[Description("Windows Vista. Read-only in non-owner data mode.")]
public IntPtr CItems;
/// <summary>
/// Windows Vista. NULL if group is not a subset. Pointer to a null-terminated string that contains the subset title text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the subset title text.
/// </summary>
[Description("Windows Vista. NULL if group is not a subset. Pointer to a null-terminated string that contains the subset title text when item information is being set. If group information is being retrieved, this member specifies the address of the buffer that receives the subset title text.")]
public IntPtr PszSubsetTitle;
/// <summary>
/// Windows Vista. Size in TCHARs of the buffer pointed to by the pszSubsetTitle member. If the structure is not receiving information about a group, this member is ignored.
/// </summary>
[Description("Windows Vista. Size in TCHARs of the buffer pointed to by the pszSubsetTitle member. If the structure is not receiving information about a group, this member is ignored.")]
public IntPtr CchSubsetTitle;
}
public class GroupStateChangedEventArgs : EventArgs
{
public ListViewGroup Group { get; set; }
public bool IsCollapsed { get; set; }
public ListViewGroupState NewState { get; set; }
}
public enum ListViewGroupMask
{
None = 0x00000,
Header = 0x00001,
Footer = 0x00002,
State = 0x00004,
Align = 0x00008,
GroupId = 0x00010,
SubTitle = 0x00100,
Task = 0x00200,
DescriptionTop = 0x00400,
DescriptionBottom = 0x00800,
TitleImage = 0x01000,
ExtendedImage = 0x02000,
Items = 0x04000,
Subset = 0x08000,
SubsetItems = 0x10000
}
public enum ListViewGroupState
{
/// <summary>
/// Groups are expanded, the group name is displayed, and all items in the group are displayed.
/// </summary>
Normal = 0,
/// <summary>
/// The group is collapsed.
/// </summary>
Collapsed = 1,
/// <summary>
/// The group is hidden.
/// </summary>
Hidden = 2,
/// <summary>
/// Version 6.00 and Windows Vista. The group does not display a header.
/// </summary>
NoHeader = 4,
/// <summary>
/// Version 6.00 and Windows Vista. The group can be collapsed.
/// </summary>
Collapsible = 8,
/// <summary>
/// Version 6.00 and Windows Vista. The group has keyboard focus.
/// </summary>
Focused = 16,
/// <summary>
/// Version 6.00 and Windows Vista. The group is selected.
/// </summary>
Selected = 32,
/// <summary>
/// Version 6.00 and Windows Vista. The group displays only a portion of its items.
/// </summary>
SubSeted = 64,
/// <summary>
/// Version 6.00 and Windows Vista. The subset link of the group has keyboard focus.
/// </summary>
SubSetLinkFocused = 128,
}
// Required structures for the notification
[StructLayout(LayoutKind.Sequential)]
public struct NMHDR
{
public IntPtr hwndFrom;
public UIntPtr idFrom;
public int code;
}
[StructLayout(LayoutKind.Sequential)]
public struct NMLVGROUP
{
public NMHDR hdr;
public int iGroupId;
public uint uNewState;
public uint uOldState;
public int state; // Current state
}
}

View File

@@ -447,7 +447,7 @@
this.cbValues.BackColor = System.Drawing.SystemColors.Window;
this.cbValues.FormattingEnabled = true;
this.cbValues.Location = new System.Drawing.Point(961, 323);
this.cbValues.Margin = new System.Windows.Forms.Padding(7, 0, 7, 0);
this.cbValues.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.cbValues.Name = "cbValues";
this.cbValues.Size = new System.Drawing.Size(129, 32);
this.cbValues.TabIndex = 5;
@@ -565,8 +565,10 @@
this.pnlListview.TabIndex = 82;
//
// txtFilter
//
//
this.txtFilter.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtFilter.Dock = System.Windows.Forms.DockStyle.Top;
this.txtFilter.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txtFilter.Location = new System.Drawing.Point(0, 0);
this.txtFilter.Name = "txtFilter";
this.txtFilter.Size = new System.Drawing.Size(1540, 29);

View File

@@ -14,6 +14,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static nspector.ListViewEx;
namespace nspector
{
@@ -175,9 +176,22 @@ namespace nspector
}
finally
{
lvSettings.EndUpdate();
((ListViewGroupSorter)lvSettings).SortGroups(true);
foreach (ListViewGroup group in lvSettings.Groups)
{
if (_groupCollapsedStates.TryGetValue(group.Header, out bool isCollapsed))
{
lvSettings.SetGroupState(group, isCollapsed ? ListViewGroupState.Collapsed | ListViewGroupState.Collapsible : ListViewGroupState.Normal | ListViewGroupState.Collapsible);
}
else
{
lvSettings.SetGroupState(group, ListViewGroupState.Collapsible);
}
}
lvSettings.EndUpdate();
GC.Collect();
for (int i = 0; i < lvSettings.Items.Count; i++)
{
@@ -195,6 +209,7 @@ namespace nspector
}
}
}
}
private void RefreshProfilesCombo()
@@ -529,6 +544,69 @@ namespace nspector
tscbShowCustomSettingNamesOnly.Checked = showCsnOnly;
Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
lvSettings.GroupStateChanged += lvSettings_GroupStateChanged;
LoadGroupStates(Path.Combine(AppContext.BaseDirectory, "HiddenGroups.ini"));
}
private Dictionary<string, bool> _groupCollapsedStates = new();
private void lvSettings_GroupStateChanged(object sender, GroupStateChangedEventArgs e)
{
_groupCollapsedStates[e.Group.Header] = e.IsCollapsed;
SaveGroupStates(Path.Combine(AppContext.BaseDirectory, "HiddenGroups.ini"));
}
private bool SaveGroupStates(string filePath)
{
try
{
using (var writer = new StreamWriter(filePath))
{
foreach (var kvp in _groupCollapsedStates)
{
writer.WriteLine($"{kvp.Key}={kvp.Value}");
}
}
return true;
}
catch
{
return false;
}
}
private bool LoadGroupStates(string filePath)
{
_groupCollapsedStates.Clear();
if (!File.Exists(filePath))
return false;
try
{
foreach (var line in File.ReadAllLines(filePath))
{
int lastEqualIndex = line.LastIndexOf('=');
if (lastEqualIndex != -1)
{
var key = line.Substring(0, lastEqualIndex).Trim();
var valueStr = line.Substring(lastEqualIndex + 1).Trim();
if (bool.TryParse(valueStr, out bool value))
{
_groupCollapsedStates[key] = value;
}
}
}
return true;
}
catch
{
return false;
}
}
public static double ScaleFactor = 1;
@@ -629,6 +707,8 @@ namespace nspector
DeleteSelectedValue();
else
ResetSelectedValue();
ApplySearchFilter();
}
ToolTip appPathsTooltip = new ToolTip() { InitialDelay = 250 };
@@ -841,6 +921,8 @@ namespace nspector
catch { }
StoreChangesOfProfileToDriver();
ApplySearchFilter();
}
private void tsbBitValueEditor_Click(object sender, EventArgs e)
@@ -1297,28 +1379,95 @@ namespace nspector
CopyModifiedSettingsToClipBoard();
}
if (e.Control && e.Alt && e.KeyCode == Keys.D)
else if (e.Control && e.Alt && e.KeyCode == Keys.D)
{
EnableDevmode();
}
if (Debugger.IsAttached && e.Control && e.KeyCode == Keys.T)
else if (Debugger.IsAttached && e.Control && e.KeyCode == Keys.T)
{
TestStoreSettings();
}
if (e.Control && e.KeyCode == Keys.F)
else if (e.Control && e.KeyCode == Keys.F)
{
txtFilter.Focus();
}
if (e.KeyCode == Keys.Escape)
else if (e.KeyCode == Keys.Escape)
{
RefreshCurrentProfile();
}
else if (!e.Control && (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z ||
e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 ||
e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 ||
e.KeyCode == Keys.Space || e.KeyCode == Keys.OemPeriod))
{
txtFilter.Visible = true;
txtFilter.Focus();
txtFilter.Text += e.Shift ? e.KeyCode.ToString() : e.KeyCode.ToString().ToLower();
txtFilter.SelectionStart = txtFilter.Text.Length;
e.SuppressKeyPress = true;
e.Handled = true;
}
}
private void txtFilter_TextChanged(object sender, EventArgs e)
private CancellationTokenSource cts;
private void ApplySearchFilter(CancellationTokenSource cts = null)
{
var lowerInput = txtFilter.Text.Trim().ToLowerInvariant();
if (cts != null && cts.Token.IsCancellationRequested) return;
Invoke(new Action(() =>
{
RefreshCurrentProfile();
if (string.IsNullOrEmpty(lowerInput))
{
return;
}
lvSettings.BeginUpdate();
foreach (ListViewItem itm in lvSettings.Items)
{
if (!itm.Text.ToLowerInvariant().Contains(lowerInput))
{
itm.Remove();
}
}
lvSettings.EndUpdate();
txtFilter.Focus(); // Setting listbox sometimes steals focus away
}));
}
private async void txtFilter_TextChanged(object sender, EventArgs e)
{
cts?.Cancel();
cts = new CancellationTokenSource();
try
{
await Task.Delay(250, cts.Token); // search filter can be slow, wait for user to stop typing for ~250ms before we start refresh
if (cts.Token.IsCancellationRequested) return;
await Task.Run(() =>
{
ApplySearchFilter(cts);
});
}
catch (TaskCanceledException)
{
// Ignore cancellation
}
}
private void txtFilter_TextChangedD(object sender, EventArgs e)
{
RefreshCurrentProfile();