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

@ -93,6 +93,7 @@ public partial class MainForm : Form
this.Load += new EventHandler( this.MainForm_Load ) ; this.Load += new EventHandler( this.MainForm_Load ) ;
this.FormClosing += new FormClosingEventHandler( this.MainForm_FormClosing ) ; this.FormClosing += new FormClosingEventHandler( this.MainForm_FormClosing ) ;
this.Resize += new EventHandler( this.MainForm_Resize ) ; this.Resize += new EventHandler( this.MainForm_Resize ) ;
this.mSearchQuery.KeyPress += this.SearchQuery_KeyPress ;
this.mSearchQuery.TextChanged += new EventHandler( this.SearchQuery_TextChanged ) ; this.mSearchQuery.TextChanged += new EventHandler( this.SearchQuery_TextChanged ) ;
this.mSearchResults.SelectionChanged += new EventHandler( this.SearchResults_SelectionChanged ) ; this.mSearchResults.SelectionChanged += new EventHandler( this.SearchResults_SelectionChanged ) ;
@ -185,7 +186,7 @@ public partial class MainForm : Form
} }
if ( keyCode == Keys.Escape ) { if ( keyCode == Keys.Escape ) {
// clear the search query // clear the search query
loadSearchResults( mChartImages.Values, "SHOW-ALL", true ) ; loadSearchResults( null, "", true ) ;
return true ; return true ;
} }
if ( keyCode == Keys.Return ) if ( keyCode == Keys.Return )
@ -212,15 +213,10 @@ public partial class MainForm : Form
if ( (ch >= 65 && ch <= 90) || ch == 32 ) if ( (ch >= 65 && ch <= 90) || ch == 32 )
sendKey = ((char)ch).ToString().ToLower() ; sendKey = ((char)ch).ToString().ToLower() ;
else if ( ch >= 48 && ch <= 57 ) 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 ) else if ( keyCode == Keys.Back )
sendKey = "{BKSP}" ; sendKey = "{BKSP}" ;
if ( sendKey != "" ) { 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 // send the keypress to the search query textbox
mSearchQuery.Focus() ; mSearchQuery.Focus() ;
mDisableProcessCmdKey = true ; mDisableProcessCmdKey = true ;
@ -458,6 +454,16 @@ public partial class MainForm : Form
doMainFormResize( null ) ; 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 ) private void SearchQuery_TextChanged( object sender, EventArgs e )
{ {
// update the search results // update the search results

Loading…
Cancel
Save