|
|
|
@ -3,6 +3,7 @@ using System.Text ; |
|
|
|
|
using System.IO ; |
|
|
|
|
using System.Threading ; |
|
|
|
|
using System.Drawing ; |
|
|
|
|
using System.Security ; |
|
|
|
|
using System.Collections.Generic ; |
|
|
|
|
using System.Windows.Forms ; |
|
|
|
|
|
|
|
|
@ -22,7 +23,7 @@ public partial class MainForm : Form |
|
|
|
|
private Label mSearchLabel = new Label() ; |
|
|
|
|
private TextBox mSearchQuery = new TextBox() ; |
|
|
|
|
private ImageListView mSearchResults = new ImageListView() ; |
|
|
|
|
private WebBrowser mStartupWebBrowser = new WebBrowser() ; |
|
|
|
|
private WebBrowser mWebBrowser = new WebBrowser() ; |
|
|
|
|
private Panel mChartImagePanel = new Panel() ; |
|
|
|
|
private PictureBox mChartImagePictureBox = new PictureBox() ; |
|
|
|
|
|
|
|
|
@ -114,12 +115,11 @@ public partial class MainForm : Form |
|
|
|
|
buf = buf.Replace( "{{BAD-SHORTCUTS}}", badShortcuts ) ; |
|
|
|
|
buf = buf.Replace( "{{OTHER-MESSAGES}}", otherMsgs ) ; |
|
|
|
|
} |
|
|
|
|
mStartupWebBrowser.DocumentText = buf ; |
|
|
|
|
mWebBrowser.DocumentText = buf ; |
|
|
|
|
|
|
|
|
|
// allow searches |
|
|
|
|
mSearchLabel.Enabled = true ; |
|
|
|
|
mSearchQuery.Enabled = true ; |
|
|
|
|
mSearchResults.Enabled = true ; |
|
|
|
|
mSearchQuery.Focus() ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -201,6 +201,68 @@ public partial class MainForm : Form |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void showShortcuts() |
|
|
|
|
{ |
|
|
|
|
// load the report template |
|
|
|
|
string fname = Path.Combine( Program.resourcesDir, "shortcuts.html" ) ; |
|
|
|
|
if ( ! File.Exists( fname ) ) { |
|
|
|
|
Program.showErrorMsg( "Can't find the shortcuts report template." ) ; |
|
|
|
|
return ; |
|
|
|
|
} |
|
|
|
|
string htmlBuf = File.ReadAllText( fname ) ; |
|
|
|
|
|
|
|
|
|
// FUDGE! We also log the shortcuts, in case WebBrowser is not working e.g. on Mono :-/ |
|
|
|
|
ILog logger = LogManager.GetLogger( "shortcuts" ) ; |
|
|
|
|
|
|
|
|
|
// generate HTML fragments for each type of shortcut |
|
|
|
|
Dictionary<Type,List<Shortcut>> registeredShortcuts = Shortcut.getRegisteredShortcuts() ; |
|
|
|
|
string makeShortcutsHtml( string caption, Type shortcutType ) { |
|
|
|
|
logger.Info( $"SHORTCUTS: {caption}" ) ; |
|
|
|
|
List<Shortcut> shortcuts ; |
|
|
|
|
if ( ! registeredShortcuts.TryGetValue( shortcutType, out shortcuts ) ) |
|
|
|
|
return "" ; |
|
|
|
|
shortcuts.Sort( (lhs, rhs) => { |
|
|
|
|
int rc = String.Compare( lhs.getKeyCode().ToString().ToLower(), rhs.getKeyCode().ToString().ToLower() ) ; |
|
|
|
|
if ( rc != 0 ) |
|
|
|
|
return rc ; |
|
|
|
|
int nLhsModifiers = lhs.countModifiers() ; |
|
|
|
|
int nRhsModifiers = rhs.countModifiers() ; |
|
|
|
|
if ( nLhsModifiers < nRhsModifiers ) |
|
|
|
|
return -1 ; |
|
|
|
|
else if ( nLhsModifiers > nRhsModifiers ) |
|
|
|
|
return +1 ; |
|
|
|
|
else |
|
|
|
|
return 0 ; |
|
|
|
|
} ) ; |
|
|
|
|
StringBuilder buf = new StringBuilder() ; |
|
|
|
|
buf.Append( $"<div class='header'> {caption} </div>" ) ; |
|
|
|
|
buf.Append( "<table class='shortcuts'>" ) ; |
|
|
|
|
foreach( Shortcut shortcut in shortcuts ) { |
|
|
|
|
logger.Info( $"- {shortcut} => {shortcut.textDescription()}" ) ; |
|
|
|
|
buf.Append( "<tr>" ) ; |
|
|
|
|
buf.Append( "<td class='key'>" + SecurityElement.Escape(shortcut.ToString()) ) ; |
|
|
|
|
buf.Append( "<td class='val'>" + shortcut.htmlDescription() ) ; |
|
|
|
|
} |
|
|
|
|
buf.Append( "</table>" ) ; |
|
|
|
|
return buf.ToString() ; |
|
|
|
|
} |
|
|
|
|
string htmlBuf2a = makeShortcutsHtml( "Search queries", typeof(SearchQueryShortcut) ) ; |
|
|
|
|
string htmlBuf2b = makeShortcutsHtml( "Images", typeof(ChartImageShortcut) ) ; |
|
|
|
|
|
|
|
|
|
// generate the shortcuts report |
|
|
|
|
if ( htmlBuf2a != "" && htmlBuf2b != "" ) { |
|
|
|
|
mWebBrowser.DocumentText = htmlBuf.Replace( "{{SHORTCUTS}}", |
|
|
|
|
"<table><tr><td style='padding-right:2em;'>" + htmlBuf2a + "<td>" + htmlBuf2b + "</table>" |
|
|
|
|
) ; |
|
|
|
|
} else if ( htmlBuf2a != "" ) |
|
|
|
|
mWebBrowser.DocumentText = htmlBuf.Replace( "{{SHORTCUTS}}", htmlBuf2a ) ; |
|
|
|
|
else if ( htmlBuf2b != "" ) |
|
|
|
|
mWebBrowser.DocumentText = htmlBuf.Replace( "{{SHORTCUTS}}", htmlBuf2b ) ; |
|
|
|
|
else |
|
|
|
|
mWebBrowser.DocumentText = htmlBuf.Replace( "{{SHORTCUTS}}", "There are no shortcuts defined." ) ; |
|
|
|
|
mWebBrowser.BringToFront() ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setSearchQuery( string s ) { mSearchQuery.Text = s ; } |
|
|
|
|
|
|
|
|
|
private void setChartImagePanelScrollPos( int? hscrollPos, int? vscrollPos ) |
|
|
|
|