55using System . IO ;
66using System . Linq ;
77using System . Text ;
8+ using System . Threading ;
89using System . Threading . Tasks ;
910using System . Windows . Forms ;
1011
@@ -17,6 +18,7 @@ public class BundleListMenuItem : ToolStripMenuItem
1718 {
1819 private readonly IBundleProvider provider ;
1920 private readonly IGitBundleMapper mapper ;
21+ private bool isLoading ;
2022
2123 internal BundleListMenuItem ( IBundleProvider provider , IGitBundleMapper mapper , IGitBundleFactory bundleFactory , PluginSettings settings )
2224 {
@@ -34,31 +36,43 @@ internal BundleListMenuItem(IBundleProvider provider, IGitBundleMapper mapper, I
3436
3537 private async void OnDropDownOpening ( object sender , EventArgs e )
3638 {
37- foreach ( var item in DropDown . Items . OfType < BundleMapMenuItem > ( ) . ToList ( ) )
38- DropDown . Items . Remove ( item ) ;
39+ if ( isLoading )
40+ return ;
3941
40- NoDataMenuItem noData = DropDown . Items . OfType < NoDataMenuItem > ( ) . FirstOrDefault ( ) ;
41- if ( noData != null )
42- DropDown . Items . Remove ( noData ) ;
42+ try
43+ {
44+ isLoading = true ;
4345
44- if ( DropDown . Items . Count == 3 )
45- DropDown . Items . RemoveAt ( 2 ) ;
46+ foreach ( var item in DropDown . Items . OfType < BundleMapMenuItem > ( ) . ToList ( ) )
47+ DropDown . Items . Remove ( item ) ;
4648
47- DropDown . Items . Add ( new ToolStripSeparator ( ) ) ;
48- int loadingIndex = DropDown . Items . Add ( new LoadingMenuItem ( ) ) ;
49+ NoDataMenuItem noData = DropDown . Items . OfType < NoDataMenuItem > ( ) . FirstOrDefault ( ) ;
50+ if ( noData != null )
51+ DropDown . Items . Remove ( noData ) ;
4952
50- if ( ! await provider . IsAvailableAsync ( ) )
51- {
52- DropDown . Items . RemoveAt ( 2 ) ;
53- DropDown . Items . RemoveAt ( 2 ) ;
54- SetItemsEnabled ( false ) ;
55- return ;
56- }
53+ if ( DropDown . Items . Count == 3 )
54+ DropDown . Items . RemoveAt ( 2 ) ;
5755
58- SetItemsEnabled ( true ) ;
59- DropDown . Items . AddRange ( await CreateBundleItemsAsync ( ) ) ;
56+ DropDown . Items . Add ( new ToolStripSeparator ( ) ) ;
57+ int loadingIndex = DropDown . Items . Add ( new LoadingMenuItem ( ) ) ;
6058
61- DropDown . Items . RemoveAt ( loadingIndex ) ;
59+ if ( ! await provider . IsAvailableAsync ( ) )
60+ {
61+ DropDown . Items . RemoveAt ( 2 ) ;
62+ DropDown . Items . RemoveAt ( 2 ) ;
63+ SetItemsEnabled ( false ) ;
64+ return ;
65+ }
66+
67+ SetItemsEnabled ( true ) ;
68+ DropDown . Items . AddRange ( await CreateBundleItemsAsync ( ) ) ;
69+
70+ DropDown . Items . RemoveAt ( loadingIndex ) ;
71+ }
72+ finally
73+ {
74+ isLoading = false ;
75+ }
6276 }
6377
6478 private async Task < ToolStripItem [ ] > CreateBundleItemsAsync ( )
0 commit comments