From db6cc00a72c6a68b11566400e2d00813eb80a703 Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 11 Jul 2019 08:53:13 +0000 Subject: [PATCH] Automatically start a new search after some time has passed. --- src/MainForm.cs | 1 + src/MainForm.ui.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index a0efe06..bc3de67 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -26,6 +26,7 @@ public partial class MainForm : Form private Point? mMouseDragAnchor = null ; private Tuple mScrollDragAnchor ; private double mUserZoom = 1.0 ; + private DateTime mLastKeyPressTimeStamp = DateTime.Now ; public MainForm() { diff --git a/src/MainForm.ui.cs b/src/MainForm.ui.cs index 847a773..68551a7 100644 --- a/src/MainForm.ui.cs +++ b/src/MainForm.ui.cs @@ -73,6 +73,7 @@ public partial class MainForm : Form this.FormClosing += new FormClosingEventHandler( this.MainForm_FormClosing ) ; this.Resize += new EventHandler( this.MainForm_Resize ) ; this.mSearchQuery.TextChanged += new EventHandler( this.SearchQuery_TextChanged ) ; + this.mSearchQuery.KeyPress += new KeyPressEventHandler( this.SearchQuery_KeyPress ) ; this.mSearchQuery.KeyDown += new KeyEventHandler( this.SearchQuery_KeyDown ) ; this.mSearchResults.KeyPress += new KeyPressEventHandler( this.SearchResults_KeyPress ) ; this.mSearchResults.SelectionChanged += new EventHandler( this.SearchResults_SelectionChanged ) ; @@ -338,6 +339,20 @@ public partial class MainForm : Form updateSearchResults( mSearchQuery.Text.Trim() ) ; } + private void SearchQuery_KeyPress( object sender, KeyPressEventArgs e ) + { + // check how much time has passed since the last keypress + int ch = (int) e.KeyChar ; + if ( ch >= 32 && ch < 127 ) { + int ttl = Program.appConfig.getIntVal( new string[]{"SearchQueryTTL"}, 5 ) ; + if ( (DateTime.Now - mLastKeyPressTimeStamp).TotalSeconds > ttl ) { + // it's been a while - start a new search query + mSearchQuery.Text = "" ; + } + mLastKeyPressTimeStamp = DateTime.Now ; + } + } + private void SearchQuery_KeyDown( object sender, KeyEventArgs e ) { // check if there are any ChartImage's associated with the keypress @@ -375,8 +390,8 @@ public partial class MainForm : Form if ( ch == 27 ) mSearchQuery.Text = "" ; else if ( ch >= 32 && ch < 127 ) { - mSearchQuery.AppendText( e.KeyChar.ToString() ) ; mSearchQuery.Focus() ; + SendKeys.Send( e.KeyChar.ToString() ) ; } } }