Update the UI as images are loaded during startup.

master
Pacman Ghost 5 years ago
parent 279237d826
commit 225f9e00bf
  1. 17
      src/MainForm.cs
  2. 8
      src/MainForm.ui.cs

@ -1,5 +1,6 @@
using System ;
using System.IO ;
using System.Threading ;
using System.Drawing ;
using System.Collections.Generic ;
using System.Windows.Forms ;
@ -46,6 +47,8 @@ public partial class MainForm : Form
dataDir, "*.*", SearchOption.AllDirectories
) ;
foreach( string fname in files ) {
// load the next image
string extn = Path.GetExtension( fname ).ToLower() ;
if ( ! mValidImageExtensions.Contains( extn ) )
continue ;
@ -61,8 +64,20 @@ public partial class MainForm : Form
key = fullPath ;
}
logger.Debug( $"Loading image: {key}" ) ;
mChartImages[ key ] = new ChartImage( key, fullPath ) ;
ChartImage chartImage = new ChartImage( key, fullPath ) ;
mChartImages[ key ] = chartImage ;
// add the image to the list
ImageListViewItem item = chartImage.imageListViewItem ;
mSearchResults.Invoke( (MethodInvoker) ( () => mSearchResults.Items.Add( item ) ) ) ;
}
// everything has been loaded, allow searches
mSearchQuery.Invoke( (MethodInvoker) ( () => {
mSearchLabel.Enabled = true ;
mSearchQuery.Enabled = true ;
mSearchQuery.Focus() ;
} ) ) ;
}
private void updateSearchResults( string searchQuery )

@ -2,6 +2,7 @@ using System ;
using System.Text ;
using System.Drawing ;
using System.IO ;
using System.Threading ;
using System.Runtime.InteropServices ;
using System.Collections.Generic ;
using System.Windows.Forms ;
@ -131,8 +132,11 @@ public partial class MainForm : Form
doMainFormResize( null ) ;
// load the chart images
loadChartImages() ;
loadSearchResults( mChartImages.Values, "" ) ;
// NOTE: This can take some time, so we update the UI as they are loaded.
mSearchLabel.Enabled = false ;
mSearchQuery.Enabled = false ;
Thread thread = new Thread( () => loadChartImages() ) ;
thread.Start() ;
}
private void MainForm_FormClosing( object sender, FormClosingEventArgs e )

Loading…
Cancel
Save