@@ -42,9 +42,50 @@ public ulong GetHash(string nameOrHex)
4242/// <summary>
4343/// Base class with shared UI helpers and wiring for EventWork grids.
4444/// </summary>
45- public abstract record EventWorkGridBase ( SplitContainer Container , DataGridView Grid , TextBox Search )
46- : IEventWorkGrid
45+ public abstract record EventWorkGridBase : IEventWorkGrid
4746{
47+ private readonly Timer _searchDebounce = new ( ) { Interval = 150 } ;
48+ private Action < string > ? _searchAction ;
49+ private SplitContainer Container { get ; }
50+ private TextBox Search { get ; }
51+ protected DataGridView Grid { get ; }
52+
53+ protected EventWorkGridBase ( SplitContainer container , DataGridView grid , TextBox search )
54+ {
55+ Container = container ;
56+ Grid = grid ;
57+ Search = search ;
58+
59+ _searchDebounce . Tick += SearchDebounceTick ;
60+ Search . Disposed += ( _ , _ ) => _searchDebounce . Dispose ( ) ;
61+ }
62+
63+ protected void WireSearch ( Action < string > applyFilter )
64+ {
65+ _searchAction = applyFilter ;
66+ Search . TextChanged += ( _ , _ ) => RestartSearchDebounce ( ) ;
67+ }
68+
69+ private void RestartSearchDebounce ( )
70+ {
71+ if ( Search . IsDisposed || Search . Disposing )
72+ return ;
73+
74+ _searchDebounce . Stop ( ) ;
75+ _searchDebounce . Start ( ) ;
76+ }
77+
78+ private void SearchDebounceTick ( object ? sender , EventArgs e )
79+ {
80+ _searchDebounce . Stop ( ) ;
81+ if ( _searchAction is null )
82+ return ;
83+ if ( Search . IsDisposed || Search . Disposing || Grid . IsDisposed || Grid . Disposing || Container . IsDisposed || Container . Disposing )
84+ return ;
85+
86+ _searchAction ( Search . Text ) ;
87+ }
88+
4889 protected static ( SplitContainer Container , TextBox Search ) CreateContainerCommon ( )
4990 {
5091 var container = new SplitContainer
@@ -53,13 +94,13 @@ protected static (SplitContainer Container, TextBox Search) CreateContainerCommo
5394 Orientation = Orientation . Horizontal ,
5495 FixedPanel = FixedPanel . Panel1 ,
5596 IsSplitterFixed = true ,
56- Margin = new Padding ( 0 ) ,
97+ Margin = Padding . Empty ,
5798 } ;
5899
59100 var search = new TextBox
60101 {
61102 Dock = DockStyle . Fill ,
62- Margin = new Padding ( 0 ) ,
103+ Margin = Padding . Empty ,
63104 PlaceholderText = "Search..." ,
64105 } ;
65106 container . Panel1 . Controls . Add ( search ) ;
@@ -140,8 +181,7 @@ private EventWorkGrid64(EventWorkStorage64<T> storage, EventWorkLookup names, Sp
140181 if ( typeof ( T ) == typeof ( ulong ) )
141182 Grid . CellValidated += ValidateU64 ;
142183
143- Search . TextChanged += ( _ , _ ) => ApplyFilter ( Search . Text ) ;
144-
184+ WireSearch ( ApplyFilter ) ;
145185 ToggleAutoSize ( true ) ;
146186 }
147187
@@ -186,7 +226,7 @@ public static EventWorkGrid64<bool> CreateFlags(TabPage host, EventWorkFlagStora
186226 AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode . None ,
187227 Dock = DockStyle . Fill ,
188228 RowHeadersVisible = false ,
189- Margin = new Padding ( 0 ) ,
229+ Margin = Padding . Empty ,
190230 DefaultCellStyle = new DataGridViewCellStyle { Font = font } ,
191231 } ;
192232 dgv . Columns . AddRange ( MakeIndexColumn ( font ) , MakeValueBoolColumn ( font , "Value" ) , MakeKeyColumn ( font ) ) ;
@@ -211,7 +251,7 @@ public static EventWorkGrid64<ulong> CreateValues(TabPage host, EventWorkValueSt
211251 AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode . None ,
212252 Dock = DockStyle . Fill ,
213253 RowHeadersVisible = false ,
214- Margin = new Padding ( 0 ) ,
254+ Margin = Padding . Empty ,
215255 DefaultCellStyle = new DataGridViewCellStyle { Font = font } ,
216256 } ;
217257 dgv . Columns . AddRange ( MakeIndexColumn ( font ) , MakeValueNumberColumn ( font , "Value" ) , MakeKeyColumn ( font ) ) ;
@@ -317,7 +357,7 @@ private EventWorkGridTuple(EventWorkValueStorageKey128 storage, EventWorkLookup
317357 Names = names ;
318358
319359 Grid . CellValueChanged += ValidateCell ;
320- Search . TextChanged += ( _ , _ ) => ApplyFilter ( Search . Text ) ;
360+ WireSearch ( ApplyFilter ) ;
321361 ToggleAutoSize ( true ) ;
322362 }
323363
@@ -338,7 +378,7 @@ public static EventWorkGridTuple CreateValues(TabPage host, EventWorkValueStorag
338378 AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode . None ,
339379 Dock = DockStyle . Fill ,
340380 RowHeadersVisible = false ,
341- Margin = new Padding ( 0 ) ,
381+ Margin = Padding . Empty ,
342382 DefaultCellStyle = new DataGridViewCellStyle { Font = font } ,
343383 } ;
344384 var c1 = MakeIndexColumn ( font ) ;
@@ -470,7 +510,7 @@ private EventWorkGrid128(EventWorkValueStorageKey128 storage, EventWorkLookup na
470510 Names = names ;
471511
472512 Grid . CellValidated += ValidateValue ;
473- Search . TextChanged += ( _ , _ ) => ApplyFilter ( Search . Text ) ;
513+ WireSearch ( ApplyFilter ) ;
474514 ToggleAutoSize ( true ) ;
475515 }
476516
@@ -491,7 +531,7 @@ public static EventWorkGrid128 CreateValues(TabPage host, EventWorkValueStorageK
491531 AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode . None ,
492532 Dock = DockStyle . Fill ,
493533 RowHeadersVisible = false ,
494- Margin = new Padding ( 0 ) ,
534+ Margin = Padding . Empty ,
495535 DefaultCellStyle = new DataGridViewCellStyle { Font = font } ,
496536 } ;
497537
@@ -619,7 +659,7 @@ private EventWorkGrid192(EventWorkValueStorageKey192 storage, EventWorkLookup na
619659 Names = names ;
620660
621661 Grid . CellValidated += ValidateValue ;
622- Search . TextChanged += ( _ , _ ) => ApplyFilter ( Search . Text ) ;
662+ WireSearch ( ApplyFilter ) ;
623663 ToggleAutoSize ( true ) ;
624664 }
625665
@@ -640,7 +680,7 @@ public static EventWorkGrid192 CreateValues(TabPage host, EventWorkValueStorageK
640680 AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode . None ,
641681 Dock = DockStyle . Fill ,
642682 RowHeadersVisible = false ,
643- Margin = new Padding ( 0 ) ,
683+ Margin = Padding . Empty ,
644684 DefaultCellStyle = new DataGridViewCellStyle { Font = font } ,
645685 } ;
646686
0 commit comments