Repeated used of a shortcut now cycles through the results.

master
Pacman Ghost 3 years ago
parent c404fcb01b
commit 714659f22e
  1. 3
      src/MainForm.cs
  2. 34
      src/MainForm.ui.cs
  3. 24
      src/Shortcut.cs

@ -210,6 +210,9 @@ public partial class MainForm : Form
// clear the search query
if ( clearSearchQuery )
setSearchQuery( "", false ) ;
// reset the repeated shortkey
Shortcut.resetLastShortcut() ;
}
public void showShortcuts()

@ -157,22 +157,7 @@ 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() + "}" ) ;
mDisableProcessCmdKey = false ;
selectSearchResult( keyCode ) ;
return true ;
}
@ -296,6 +281,23 @@ public partial class MainForm : Form
return false ;
}
public void selectSearchResult( Keys keyCode )
{
if ( mSearchResults.Items.Count == 0 )
return ;
int selIndex = 0 ;
if ( mSearchResults.SelectedItems.Count > 0 ) {
ImageListViewItem selItem = mSearchResults.SelectedItems[0] ;
if ( keyCode == Keys.Left )
selIndex = (selItem.Index > 0) ? selItem.Index-1 : mSearchResults.Items.Count-1 ;
else if ( keyCode == Keys.Right )
selIndex = (selItem.Index < mSearchResults.Items.Count-1) ? selItem.Index+1 : 0 ;
else
Debug.Assert( false, $"Unexpected keyCode: {keyCode}" ) ;
}
mSearchResults.setSelection( selIndex ) ;
}
private int ChartImagePanel_MaxScrollX() { return Math.Max( 0, mChartImagePanel.HorizontalScroll.Maximum-mChartImagePanel.Width) + 17 ; }
private int ChartImagePanel_MaxScrollY() { return Math.Max( 0, mChartImagePanel.VerticalScroll.Maximum-mChartImagePanel.Height) + 17 ; }

@ -12,6 +12,8 @@ public abstract class Shortcut
{
private static Dictionary<Keys,Shortcut> mRegisteredShortcuts = new Dictionary<Keys,Shortcut>() ;
private static Shortcut mLastShortcut = null ;
private static DateTime mLastShortcutTimestamp = DateTime.Now ;
private Keys mKeys ;
@ -52,13 +54,33 @@ public abstract class Shortcut
if ( shortcut == null )
return false ;
// found one - execute it
// found one - check if it's the same as the last shortcut used
ILog logger = LogManager.GetLogger( "shortcuts" ) ;
if ( mLastShortcut != null && Object.ReferenceEquals( shortcut, mLastShortcut ) ) {
// yup - check how much time has passed since the last shortcut was used
TimeSpan delta = DateTime.Now - mLastShortcutTimestamp ;
double cutoff = Program.appConfig.getDoubleVal( new string[]{"ShortcutRepeatThreshold"}, 5 ) ;
logger.Debug( $"Repeated shortcut: {mLastShortcut} ; delta={delta.TotalSeconds} ; cutoff={cutoff}" ) ;
if ( delta.TotalSeconds <= cutoff ) {
// less than the threshold - select the next search result instead
logger.Debug( "- Selecting next search result instead." ) ;
Program.mainForm.selectSearchResult( Keys.Right ) ;
mLastShortcutTimestamp = DateTime.Now ;
return true ;
}
}
logger.Info( $"Executing shortcut: {shortcut}" ) ;
shortcut.executeShortcut() ;
mLastShortcut = shortcut ;
mLastShortcutTimestamp = DateTime.Now ;
return true ;
}
public static void resetLastShortcut()
{
mLastShortcut = null ;
}
public static void registerShortcut( Shortcut shortcut )
{
// register the shortcut

Loading…
Cancel
Save