You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.2 KiB
86 lines
3.2 KiB
using System ;
|
|
using System.IO ;
|
|
using System.Collections.Generic ;
|
|
using System.Windows.Forms ;
|
|
|
|
using Manina.Windows.Forms ;
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
public partial class MainForm : Form
|
|
{
|
|
private readonly HashSet<string> mValidImageExtensions = new HashSet<string>{ ".png", ".jpg", ".gif" } ;
|
|
|
|
private Dictionary<string,ChartImage> mChartImages = new Dictionary<string,ChartImage>() ;
|
|
|
|
private SplitContainer mSplitter = new SplitContainer() ;
|
|
private UserControl mSearchUserControl = new UserControl() ;
|
|
private Label mSearchLabel = new Label() ;
|
|
private TextBox mSearchQuery = new TextBox() ;
|
|
private ImageListView mSearchResults = new ImageListView() ;
|
|
private PictureBox mImagePictureBox = new PictureBox() ;
|
|
|
|
public MainForm()
|
|
{
|
|
// initialize the form
|
|
InitializeComponent() ;
|
|
}
|
|
|
|
private void loadChartImages()
|
|
{
|
|
// locate the chart images
|
|
string dataDir = Path.GetFullPath( Program.dataDir ) ;
|
|
IEnumerable<string> files = Directory.EnumerateFiles(
|
|
dataDir, "*.*", SearchOption.AllDirectories
|
|
) ;
|
|
foreach( string fname in files ) {
|
|
string extn = Path.GetExtension( fname ).ToLower() ;
|
|
if ( ! mValidImageExtensions.Contains( extn ) )
|
|
continue ;
|
|
string key ;
|
|
string fullPath = Path.GetFullPath( fname ) ;
|
|
if ( fullPath.StartsWith( dataDir ) ) {
|
|
key = fname.Substring( dataDir.Length ) ;
|
|
if ( key.StartsWith( "/" ) || key.StartsWith( "\\" ) )
|
|
key = key.Substring( 1 ) ;
|
|
} else {
|
|
// NOTE: I don't think we should ever get here :-/ If we do, the user will have to manage
|
|
// their configuration using full paths for the image files, but at least we will still run...
|
|
key = fullPath ;
|
|
}
|
|
Program.logTraceMsg( String.Format( "Loading image: {0}", key ) ) ;
|
|
mChartImages[ key ] = new ChartImage( key, fullPath ) ;
|
|
}
|
|
}
|
|
|
|
private void updateSearchResults( string searchQuery )
|
|
{
|
|
// search for matching chart images
|
|
List<ChartImage> results = new List<ChartImage>() ;
|
|
searchQuery = searchQuery.ToLower() ;
|
|
foreach ( ChartImage chartImage in mChartImages.Values ) {
|
|
if ( chartImage.caption().ToLower().IndexOf( searchQuery ) >= 0 )
|
|
results.Add( chartImage ) ;
|
|
}
|
|
loadSearchResults( results ) ;
|
|
}
|
|
|
|
private void loadSearchResults( IEnumerable<ChartImage> chartImages )
|
|
{
|
|
// clear the search results
|
|
mSearchResults.SuspendLayout() ;
|
|
mSearchResults.Items.Clear() ;
|
|
mSearchResults.ResumeLayout( true ) ;
|
|
|
|
// load the search results
|
|
mSearchResults.SuspendLayout() ;
|
|
int nItems = 0 ;
|
|
foreach( ChartImage chartImage in chartImages ) {
|
|
ImageListViewItem item = chartImage.imageListViewItem ;
|
|
mSearchResults.Items.Add( item ) ;
|
|
if ( nItems++ == 0 )
|
|
item.Selected = true ;
|
|
}
|
|
mSearchResults.ResumeLayout( true ) ;
|
|
}
|
|
}
|
|
|