From 92094c68186ce589d228e8fed24d220e50bf9e4a Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 20 Jul 2019 10:06:44 +0000 Subject: [PATCH] Wraparound when using the arrow keys to select search results. --- src/AppImageListView.cs | 13 ++++++++++++- src/MainForm.cs | 2 +- src/MainForm.ui.cs | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/AppImageListView.cs b/src/AppImageListView.cs index 7c3e236..c557a54 100644 --- a/src/AppImageListView.cs +++ b/src/AppImageListView.cs @@ -4,11 +4,22 @@ using Manina.Windows.Forms ; // -------------------------------------------------------------------- -public class AppImageListView +public class AppImageListView : ImageListView { + public class AppImageListViewRenderer : ImageListView.ImageListViewRenderer { // NOTE: This disables the large preview image in Gallery mode. public override void DrawGalleryImage( Graphics g, ImageListViewItem lvi , Image img, Rectangle rc ) {} } + + public void setSelection( int selIndex ) + { + // set the selected item + for ( int i=0 ; i < Items.Count ; ++i ) + Items[i].Selected = (i == selIndex) ; + Items.FocusedItem = Items[selIndex] ; + EnsureVisible( selIndex ) ; + } + } diff --git a/src/MainForm.cs b/src/MainForm.cs index 3d46955..05412ba 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -23,7 +23,7 @@ public partial class MainForm : Form private UserControl mSearchUserControl = new UserControl() ; private Label mSearchLabel = new Label() ; private TextBox mSearchQuery = new TextBox() ; - private ImageListView mSearchResults = new ImageListView() ; + private AppImageListView mSearchResults = new AppImageListView() ; private WebBrowser mWebBrowser = new WebBrowser() ; private Panel mChartImagePanel = new Panel() ; private PictureBox mChartImagePictureBox = new PictureBox() ; diff --git a/src/MainForm.ui.cs b/src/MainForm.ui.cs index c90a8f0..3b9c8c5 100644 --- a/src/MainForm.ui.cs +++ b/src/MainForm.ui.cs @@ -146,6 +146,18 @@ public partial class MainForm : Form // send the keypress to the search results // NOTE: We could also respond to Up/Down and scroll the ChartImage vertically, // but that would be confusing, given that Left/Right selects a search result. + if ( mSearchResults.Items.Count > 1 && mSearchResults.SelectedItems.Count > 0 ) { + // check for wrap-around + ImageListViewItem selItem = mSearchResults.SelectedItems[0] ; + if ( keyCode == Keys.Left && Object.ReferenceEquals( selItem, mSearchResults.Items[0] ) ) { + mSearchResults.setSelection( mSearchResults.Items.Count-1 ) ; + return true ; + } + if ( keyCode == Keys.Right && Object.ReferenceEquals( selItem, mSearchResults.Items[mSearchResults.Items.Count-1] ) ) { + mSearchResults.setSelection( 0 ) ; + return true ; + } + } mSearchResults.Focus() ; mDisableProcessCmdKey = true ; SendKeys.SendWait( "{" + keyCode.ToString() + "}" ) ;