Added the ability to run a search query using a shortcut.

master
Pacman Ghost 5 years ago
parent e033a5072d
commit 911be971bc
  1. 7
      data/search-queries.json
  2. 8
      src/ChartImage.cs
  3. 2
      src/MainForm.cs
  4. 4
      src/Program.cs
  5. 26
      src/Program2.cs
  6. 24
      src/Shortcut.cs

@ -0,0 +1,7 @@
[
{ "query": "to",
"shortcut": "Ctrl-T"
}
]

@ -40,8 +40,12 @@ public class ChartImage
shortcut = new ChartImageShortcut( keys.Value ) ;
Shortcut.registerShortcut( shortcut ) ;
}
logger.Info( $"Registering shortcut: {shortcut.ToString()} => {caption()}" ) ;
((ChartImageShortcut)shortcut).addChartImage( this ) ;
if ( shortcut is ChartImageShortcut ) {
logger.Info( $"Registering image shortcut: {shortcut} => {caption()}" ) ;
((ChartImageShortcut)shortcut).addChartImage( this ) ;
}
else
Program.logStartupMsg( "bad-shortcut", $"Found duplicate: {shortcut}" ) ;
}
}

@ -201,6 +201,8 @@ public partial class MainForm : Form
}
}
public void setSearchQuery( string s ) { mSearchQuery.Text = s ; }
private void setChartImagePanelScrollPos( int? hscrollPos, int? vscrollPos )
{
// FUDGE! These need to be set twice to take effect on Windows :-/

@ -65,6 +65,10 @@ public static partial class Program
// load the data config
mDataConfig = new JsonConfig( "data config", Path.Combine( mDataDir, "config.json" ) ) ;
// load pre-defined search queries
fname = Path.Combine( mDataDir, "search-queries.json" ) ;
loadPredefinedSearchQueries( fname ) ;
// load the debug config
mDebugConfig = new JsonConfig( "debug config", Path.Combine( mBaseDir, "debug.json" ) ) ;

@ -1,5 +1,6 @@
using System.Security ;
using System ;
using System.Text ;
using System.Security ;
using System.Windows.Forms ;
using System.Collections.Generic ;
@ -19,6 +20,29 @@ public static partial class Program
}
}
private static void loadPredefinedSearchQueries( string fname )
{
// load the pre-defined search queries
JsonConfig jsonConfig = new JsonConfig( "pre-defined search queries", fname ) ;
ILog logger = LogManager.GetLogger( "shortcuts" ) ;
foreach( dynamic entry in jsonConfig.data ) {
string queryString = entry["query"] ?? "" ;
if ( queryString == "" ) {
Program.logStartupMsg( "bad-shortcut", $"{entry["shortcut"]}: Missing query string" ) ;
continue ;
}
string shortcutString = entry["shortcut"] ?? "" ;
Keys? keys = Shortcut.parseShortcutString( (string) shortcutString ) ;
if ( keys == null ) {
Program.logStartupMsg( "bad-shortcut", $"{queryString}: {shortcutString}" ) ;
continue ;
}
Shortcut shortcut = new SearchQueryShortcut( keys.Value, queryString ) ;
logger.Info( $"Registering search query shortcut: {shortcut} => {queryString}" ) ;
Shortcut.registerShortcut( shortcut ) ;
}
}
public static void logStartupMsg( string key, string msg )
{
// log the startup message

@ -61,6 +61,9 @@ public abstract class Shortcut
public static void registerShortcut( Shortcut shortcut )
{
// register the shortcut
if ( findRegisteredShortcut( shortcut.mKeys ) != null ) {
Program.logStartupMsg( "bad-shortcut", $"Found duplicate: {shortcut}" ) ;
}
mRegisteredShortcuts[ shortcut.mKeys ] = shortcut ;
}
@ -110,3 +113,24 @@ public class ChartImageShortcut : Shortcut
public void addChartImage( ChartImage ci ) { mChartImages.Add( ci ) ; }
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class SearchQueryShortcut : Shortcut
{
private string mSearchQuery ;
public SearchQueryShortcut( Keys keys, string searchQuery ) : base( keys )
{
// initialize
mSearchQuery = searchQuery ;
}
public override void executeShortcut()
{
// execute the shortcut
Program.mainForm.setSearchQuery( mSearchQuery ) ;
ILog logger = LogManager.GetLogger( "shortcuts" ) ;
logger.Debug( $"- {mSearchQuery}" ) ;
}
}

Loading…
Cancel
Save