Skip to content

Commit

Permalink
Optimize import/clear shopping list
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Pain committed Dec 11, 2022
1 parent 96d3027 commit 3f73397
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions EDEngineer/Views/CommanderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ private void LoadBlueprints(ILanguage languages, IEnumerable<Blueprint> blueprin
Settings.Default.ShoppingList.Add(text);
}

Settings.Default.Save();
if (!importingShoppingList)
{
Settings.Default.Save();
}
}
};
}
Expand Down Expand Up @@ -400,15 +403,20 @@ public void ShoppingListChange(Blueprint blueprint, int i)
{
blueprint.ShoppingListCount += i;

OnPropertyChanged(nameof(ShoppingList));
OnPropertyChanged(nameof(ShoppingListItem));
// Don't bother UI when there is import in progress.
if (!importingShoppingList)
{
OnPropertyChanged(nameof(ShoppingList));
OnPropertyChanged(nameof(ShoppingListItem));
}
}
}

public void ImportShoppingList()
{
if (Helpers.TryRetrieveShoppingList(out var shoppingListItems))
{
importingShoppingList = true;
var blueprints = State.Blueprints;

if (shoppingListItems != null && shoppingListItems.Count > 0)
Expand All @@ -433,6 +441,7 @@ public void ImportShoppingList()
break;
case MessageBoxResult.Cancel:
// User pressed Cancel button so skip out of Import
importingShoppingList = false;
return;
}

Expand All @@ -441,7 +450,7 @@ public void ImportShoppingList()
}

RefreshShoppingList();

importingShoppingList = false;
}
}

Expand Down Expand Up @@ -478,14 +487,21 @@ public void ExportShoppingList()

public void ClearShoppingList()
{
var importingShoppingListOld = importingShoppingList;
importingShoppingList = true;

foreach (var tuple in ShoppingList.Composition.ToList())
{
ShoppingListChange(tuple.Item1, tuple.Item2 * -1);
}

importingShoppingList = importingShoppingListOld;
}

public int ShoppingListItem => 0;

public bool importingShoppingList { get; private set; }

public override string ToString()
{
return $"CMDR {CommanderName}";
Expand Down

0 comments on commit 3f73397

Please sign in to comment.