Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit b0f6301

Browse files
committed
Optimize import/clear shopping list
1 parent fea509c commit b0f6301

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

EDEngineer/Views/CommanderViewModel.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ private void LoadBlueprints(ILanguage languages, IEnumerable<Blueprint> blueprin
312312
Settings.Default.ShoppingList.Add(text);
313313
}
314314

315-
Settings.Default.Save();
315+
if (!importingShoppingList)
316+
{
317+
Settings.Default.Save();
318+
}
316319
}
317320
};
318321
}
@@ -400,15 +403,20 @@ public void ShoppingListChange(Blueprint blueprint, int i)
400403
{
401404
blueprint.ShoppingListCount += i;
402405

403-
OnPropertyChanged(nameof(ShoppingList));
404-
OnPropertyChanged(nameof(ShoppingListItem));
406+
// Don't bother UI when there is import in progress.
407+
if (!importingShoppingList)
408+
{
409+
OnPropertyChanged(nameof(ShoppingList));
410+
OnPropertyChanged(nameof(ShoppingListItem));
411+
}
405412
}
406413
}
407414

408415
public void ImportShoppingList()
409416
{
410417
if (Helpers.TryRetrieveShoppingList(out var shoppingListItems))
411418
{
419+
importingShoppingList = true;
412420
var blueprints = State.Blueprints;
413421

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

@@ -441,7 +450,7 @@ public void ImportShoppingList()
441450
}
442451

443452
RefreshShoppingList();
444-
453+
importingShoppingList = false;
445454
}
446455
}
447456

@@ -478,14 +487,21 @@ public void ExportShoppingList()
478487

479488
public void ClearShoppingList()
480489
{
490+
var importingShoppingListOld = importingShoppingList;
491+
importingShoppingList = true;
492+
481493
foreach (var tuple in ShoppingList.Composition.ToList())
482494
{
483495
ShoppingListChange(tuple.Item1, tuple.Item2 * -1);
484496
}
497+
498+
importingShoppingList = importingShoppingListOld;
485499
}
486500

487501
public int ShoppingListItem => 0;
488502

503+
public bool importingShoppingList { get; private set; }
504+
489505
public override string ToString()
490506
{
491507
return $"CMDR {CommanderName}";

0 commit comments

Comments
 (0)