Skip to content

Commit 14c0c3e

Browse files
committed
#30 - Once loading is in progress, it just wails util it finishes (instead of starting a new one).
1 parent 3575580 commit 14c0c3e

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

src/GitExtensions.BundleBackuper/UI/BundleListMenuItem.cs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Text;
8+
using System.Threading;
89
using System.Threading.Tasks;
910
using 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

Comments
 (0)