@@ -186,11 +186,14 @@ private void HotkeysDeactivate()
186186 private void OnWindowAdded ( object sender , GwmWindowEventArgs e )
187187 {
188188 if ( ! ( e . Form is AutoTypeCtxForm ) ) return ;
189- if ( m_host . MainWindow . DocumentManager . GetOpenDatabases ( ) . Count < 1 ) return ;
189+ int iOpenedDatabases = m_host . MainWindow . DocumentManager . GetOpenDatabases ( ) . Count ;
190+ if ( ! Config . SearchAsYouType && iOpenedDatabases < 1 ) return ;
190191 e . Form . Shown += OnAutoTypeFormShown ;
191192
193+ if ( iOpenedDatabases < 1 ) return ;
192194 PluginDebug . AddInfo ( "Auto-Type entry selection window added" , 0 ) ;
193195
196+
194197 List < AutoTypeCtx > lCtx = ( List < AutoTypeCtx > ) Tools . GetField ( "m_lCtxs" , e . Form ) ;
195198 if ( lCtx == null ) return ;
196199 // Adjust content
@@ -253,8 +256,17 @@ private void OnWindowRemoved(object sender, GwmWindowEventArgs e)
253256
254257 private void OnAutoTypeFormShown ( object sender , EventArgs e )
255258 {
256- Form f = sender as AutoTypeCtxForm ;
259+ if ( m_host . MainWindow . DocumentManager . GetOpenDatabases ( ) . Count >= 1 ) InitializeAutoTypeListView ( sender , e ) ;
260+
261+ if ( Config . SearchAsYouType ) AddSearchfield ( sender as AutoTypeCtxForm ) ;
262+ }
263+
264+ private void InitializeAutoTypeListView ( object sender , EventArgs e )
265+ {
266+ AutoTypeCtxForm f = sender as AutoTypeCtxForm ;
257267 if ( f == null ) return ;
268+ //AddSearchfield(f);
269+ if ( m_host . MainWindow . DocumentManager . GetOpenDatabases ( ) . Count < 1 ) return ;
258270 ListView lv = Tools . GetControl ( "m_lvItems" , f ) as ListView ;
259271 PluginDebug . AddInfo ( "Auto-Type entry selection window shown" , 0 ) ;
260272 if ( ( lv != null ) && ( lv . Items . Count == 0 ) && ! KeePass . Program . Config . Integration . AutoTypeAlwaysShowSelDialog )
@@ -343,7 +355,62 @@ private void OnAutoTypeFormShown(object sender, EventArgs e)
343355 catch ( Exception ) { }
344356 }
345357
346- private void AutoTypeForm_ShowGroups_CheckedChanged ( object sender , EventArgs e )
358+ private class _SearchAsYouTypeData
359+ {
360+ internal ListView ShownEntries ;
361+ internal List < ListViewItem > AllEntries ;
362+ }
363+ private void AddSearchfield ( AutoTypeCtxForm f )
364+ {
365+ var lvShownEntries = Tools . GetControl ( "m_lvItems" , f ) as ListView ;
366+ if ( lvShownEntries == null )
367+ {
368+ PluginDebug . AddError ( "Could not locate m_lvItems, search-as-you-type field not added" ) ;
369+ return ;
370+ }
371+ var c = lvShownEntries . Parent ;
372+ Label lSearch = new Label ( ) ;
373+ TextBox tbSearch = new TextBox ( ) ;
374+ c . Controls . Add ( lSearch ) ;
375+ c . Controls . Add ( tbSearch ) ;
376+ lSearch . Text = KeePass . Resources . KPRes . FindEntries ;
377+ lSearch . AutoSize = true ;
378+ tbSearch . Left = lvShownEntries . Left + lSearch . Width + DpiUtil . ScaleIntX ( 10 ) ;
379+ lSearch . Left = lvShownEntries . Left ;
380+ tbSearch . Top = lvShownEntries . Top ;
381+ lSearch . Top = lvShownEntries . Top + tbSearch . Height / 2 - lSearch . Height / 2 ;
382+ tbSearch . Width = lvShownEntries . Width / 2 ;
383+ List < ListViewItem > lvAllEntries = new List < ListViewItem > ( lvShownEntries . Items . Cast < ListViewItem > ( ) ) ;
384+ tbSearch . Tag = new _SearchAsYouTypeData ( ) { AllEntries = lvAllEntries , ShownEntries = lvShownEntries } ;
385+ tbSearch . TextChanged += OnFilterSearchResults ;
386+ int iGap = DpiUtil . ScaleIntY ( 10 ) ;
387+ int iHeight = lvShownEntries . Height ;
388+ tbSearch . Dock = lvShownEntries . Dock = DockStyle . None ;
389+ lvShownEntries . Top += tbSearch . Height + iGap - 1 ;
390+ lvShownEntries . Height = iHeight - tbSearch . Height - iGap ;
391+ }
392+
393+ private void OnFilterSearchResults ( object sender , EventArgs e )
394+ {
395+ TextBox tbSearch = sender as TextBox ;
396+ if ( tbSearch == null ) return ;
397+ _SearchAsYouTypeData st = tbSearch . Tag as _SearchAsYouTypeData ;
398+ if ( st == null ) return ;
399+ string s = tbSearch . Text . ToLowerInvariant ( ) ;
400+ st . ShownEntries . BeginUpdate ( ) ;
401+ st . ShownEntries . Items . Clear ( ) ;
402+ st . ShownEntries . Items . AddRange ( st . AllEntries . Where ( x =>
403+ x . Text . ToLowerInvariant ( ) . Contains ( s ) // Entry title
404+ ||
405+ x . SubItems [ 1 ] . Text . ToLowerInvariant ( ) . Contains ( s ) // User name
406+ ) . ToArray ( ) ) ;
407+ st . ShownEntries . EndUpdate ( ) ;
408+ if ( ! st . ShownEntries . ShowGroups ) return ;
409+ int column = st . ShownEntries . Columns . IndexOf ( m_SortColumn ) ;
410+ AdjustGroups ( st . ShownEntries , column ) ;
411+ }
412+
413+ private void AutoTypeForm_ShowGroups_CheckedChanged ( object sender , EventArgs e )
347414 {
348415 Form f = ( sender as Control ) . FindForm ( ) ;
349416 ListView lv = Tools . GetControl ( "m_lvItems" , f ) as ListView ;
@@ -597,6 +664,7 @@ private void OptionsFormShown(object sender, Tools.OptionsFormsEventArgs e)
597664 options . cbSpecialColumnsRespectPWEnter . Checked = Config . SpecialColumnsRespectPWEnter ;
598665 options . cbKeepATOpen . Checked = Config . KeepATOpen ;
599666 options . cbExcludeExpiredGroups . Checked = Config . ExcludeExpiredGroups ;
667+ options . cbSearchAsYouType . Checked = Config . SearchAsYouType ;
600668 e . form . Shown += options . OptionsForm_Shown ;
601669 Tools . AddPluginToOptionsForm ( this , options ) ;
602670 }
@@ -623,6 +691,7 @@ private void OptionsForm_Closed(object sender, Tools.OptionsFormsEventArgs e)
623691 Config . SpecialColumnsRespectPWEnter = options . cbSpecialColumnsRespectPWEnter . Checked ;
624692 Config . KeepATOpen = options . cbKeepATOpen . Checked ;
625693 Config . ExcludeExpiredGroups = options . cbExcludeExpiredGroups . Checked ;
694+ Config . SearchAsYouType = options . cbSearchAsYouType . Checked ;
626695
627696 if ( ( Config . AATHotkey != Keys . None ) || ( Config . PWOnlyHotkey != Keys . None ) )
628697 HotkeysActivate ( ) ;
0 commit comments