Reworked how the search query TTL is implemented.

master
Pacman Ghost 5 years ago
parent 7a534c1939
commit 69813f9f46
  1. 25
      src/MainForm.cs
  2. 20
      src/MainForm.ui.cs

@ -180,6 +180,12 @@ public partial class MainForm : Form
if ( key == mSearchResultsKey )
return ;
// initialize
if ( chartImages == null ) {
chartImages = mChartImages.Values ;
key = "SHOW-ALL" ;
}
// clear the search results
mSearchResults.SuspendLayout() ;
mSearchResults.Items.Clear() ;
@ -191,18 +197,15 @@ public partial class MainForm : Form
foreach( ChartImage chartImage in chartImages ) {
ImageListViewItem item = chartImage.imageListViewItem ;
mSearchResults.Items.Add( item ) ;
if ( nItems++ == 0 && key != "" )
if ( nItems++ == 0 && key != "" && key != "SHOW-ALL" )
item.Selected = true ;
}
mSearchResults.ResumeLayout( true ) ;
mSearchResultsKey = key ;
// clear the search query
if ( clearSearchQuery ) {
mSearchQueryTextChangedDisabled = true ;
mSearchQuery.Text = "" ;
mSearchQueryTextChangedDisabled = false ;
}
if ( clearSearchQuery )
setSearchQuery( "", false ) ;
}
public void showShortcuts()
@ -267,7 +270,15 @@ public partial class MainForm : Form
mWebBrowser.BringToFront() ;
}
public void setSearchQuery( string s ) { mSearchQuery.Text = s ; }
public void setSearchQuery( string queryString, bool raiseEvents=true )
{
// set the search query string
if ( ! raiseEvents )
mSearchQueryTextChangedDisabled = true ;
mSearchQuery.Text = queryString ;
if ( ! raiseEvents )
mSearchQueryTextChangedDisabled = false ;
}
private void setChartImagePanelScrollPos( int? hscrollPos, int? vscrollPos )
{

@ -93,6 +93,7 @@ public partial class MainForm : Form
this.Load += new EventHandler( this.MainForm_Load ) ;
this.FormClosing += new FormClosingEventHandler( this.MainForm_FormClosing ) ;
this.Resize += new EventHandler( this.MainForm_Resize ) ;
this.mSearchQuery.KeyPress += this.SearchQuery_KeyPress ;
this.mSearchQuery.TextChanged += new EventHandler( this.SearchQuery_TextChanged ) ;
this.mSearchResults.SelectionChanged += new EventHandler( this.SearchResults_SelectionChanged ) ;
@ -185,7 +186,7 @@ public partial class MainForm : Form
}
if ( keyCode == Keys.Escape ) {
// clear the search query
loadSearchResults( mChartImages.Values, "SHOW-ALL", true ) ;
loadSearchResults( null, "", true ) ;
return true ;
}
if ( keyCode == Keys.Return )
@ -212,15 +213,10 @@ public partial class MainForm : Form
if ( (ch >= 65 && ch <= 90) || ch == 32 )
sendKey = ((char)ch).ToString().ToLower() ;
else if ( ch >= 48 && ch <= 57 )
sendKey = keyCode.ToString().Substring( 1 ) ;
sendKey = keyCode.ToString().Substring( 1 ) ; // nb: this will also detect Shift 0-9 :-/
else if ( keyCode == Keys.Back )
sendKey = "{BKSP}" ;
if ( sendKey != "" ) {
// check if it's time to start a new search query
int ttl = Program.appConfig.getIntVal( new string[]{"SearchQueryTTL"}, 5 ) ;
if ( (DateTime.Now - mLastKeyPressTimeStamp).TotalSeconds > ttl )
mSearchQuery.Text = "" ;
mLastKeyPressTimeStamp = DateTime.Now ;
// send the keypress to the search query textbox
mSearchQuery.Focus() ;
mDisableProcessCmdKey = true ;
@ -458,6 +454,16 @@ public partial class MainForm : Form
doMainFormResize( null ) ;
}
private void SearchQuery_KeyPress( object sender, KeyPressEventArgs e )
{
// check if it's time to start a new search query
int ttl = Program.appConfig.getIntVal( new string[]{"SearchQueryTTL"}, 5 ) ;
if ( (DateTime.Now - mLastKeyPressTimeStamp).TotalSeconds > ttl ) {
setSearchQuery( "", false ) ;
}
mLastKeyPressTimeStamp = DateTime.Now ;
}
private void SearchQuery_TextChanged( object sender, EventArgs e )
{
// update the search results

Loading…
Cancel
Save