Skip to content

Commit

Permalink
Fix for crash when trying to remove gdemu without preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
sonik-br committed Feb 20, 2022
1 parent 712f711 commit f767206
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/GDMENUCardManager.AvaloniaUI/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,29 @@ private async Task renameSelection(RenameBy renameBy)
// item.Name = name;
//}

private void GridOnKeyDown(object sender, KeyEventArgs e)
private async void GridOnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Delete && !(e.Source is TextBox))
{
List<GdItem> toRemove = new List<GdItem>();
foreach (GdItem item in dg1.SelectedItems)
if (!(item.SdNumber == 1 && item.Ip.Name == "GDMENU"))//dont let the user exclude GDMENU
{
if (item.SdNumber == 1)
{
if (item.Ip == null)
{
IsBusy = true;
await Manager.LoadIP(item);
IsBusy = false;
}
if (item.Ip.Name != "GDMENU")//dont let the user exclude GDMENU
toRemove.Add(item);
}
else
{
toRemove.Add(item);
}
}

foreach (var item in toRemove)
Manager.ItemList.Remove(item);
Expand Down
19 changes: 17 additions & 2 deletions src/GDMENUCardManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private async Task renameSelection(RenameBy renameBy)
IsBusy = false;
}

private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
private async void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F2 && !(e.OriginalSource is TextBox))
{
Expand All @@ -457,8 +457,23 @@ private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
var grid = (DataGrid)sender;
List<GdItem> toRemove = new List<GdItem>();
foreach (GdItem item in grid.SelectedItems)
if (!(item.SdNumber == 1 && item.Ip.Name == "GDMENU"))//dont let the user exclude GDMENU
{
if (item.SdNumber == 1)
{
if (item.Ip == null)
{
IsBusy = true;
await Manager.LoadIP(item);
IsBusy = false;
}
if (item.Ip.Name != "GDMENU")//dont let the user exclude GDMENU
toRemove.Add(item);
}
else
{
toRemove.Add(item);
}
}

foreach (var item in toRemove)
Manager.ItemList.Remove(item);
Expand Down

0 comments on commit f767206

Please sign in to comment.