5
5
using System . IO ;
6
6
using System . Linq ;
7
7
using System . Text ;
8
+ using System . Threading ;
8
9
using System . Threading . Tasks ;
9
10
using System . Windows . Forms ;
10
11
@@ -17,6 +18,7 @@ public class BundleListMenuItem : ToolStripMenuItem
17
18
{
18
19
private readonly IBundleProvider provider ;
19
20
private readonly IGitBundleMapper mapper ;
21
+ private bool isLoading ;
20
22
21
23
internal BundleListMenuItem ( IBundleProvider provider , IGitBundleMapper mapper , IGitBundleFactory bundleFactory , PluginSettings settings )
22
24
{
@@ -34,31 +36,43 @@ internal BundleListMenuItem(IBundleProvider provider, IGitBundleMapper mapper, I
34
36
35
37
private async void OnDropDownOpening ( object sender , EventArgs e )
36
38
{
37
- foreach ( var item in DropDown . Items . OfType < BundleMapMenuItem > ( ) . ToList ( ) )
38
- DropDown . Items . Remove ( item ) ;
39
+ if ( isLoading )
40
+ return ;
39
41
40
- NoDataMenuItem noData = DropDown . Items . OfType < NoDataMenuItem > ( ) . FirstOrDefault ( ) ;
41
- if ( noData != null )
42
- DropDown . Items . Remove ( noData ) ;
42
+ try
43
+ {
44
+ isLoading = true ;
43
45
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 ) ;
46
48
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 ) ;
49
52
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 ) ;
57
55
58
- SetItemsEnabled ( true ) ;
59
- DropDown . Items . AddRange ( await CreateBundleItemsAsync ( ) ) ;
56
+ DropDown . Items . Add ( new ToolStripSeparator ( ) ) ;
57
+ int loadingIndex = DropDown . Items . Add ( new LoadingMenuItem ( ) ) ;
60
58
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
+ }
62
76
}
63
77
64
78
private async Task < ToolStripItem [ ] > CreateBundleItemsAsync ( )
0 commit comments