private void GlobalVariablesSource_OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (Favorites == null && RecentlyUsed == null) return;
switch (e.Action)
{
case NotifyCollectionChangedAction.Reset:
var variables = GlobalVariablesSource.ToSet();
if (Favorites != null) Favorites.RemoveAll(data => data.Key == FormulaEditorKey.GlobalVariable && !variables.Contains(data.GlobalVariable));
if (RecentlyUsed != null) RecentlyUsed.RemoveAll(data => data.Key == FormulaEditorKey.GlobalVariable && !variables.Contains(data.GlobalVariable));
break;
case NotifyCollectionChangedAction.Remove:
case NotifyCollectionChangedAction.Replace:
var deletedVariables = e.OldItems.Cast<GlobalVariable>().ToSet();
if (Favorites != null) Favorites.RemoveAll(data => data.Key == FormulaEditorKey.GlobalVariable && deletedVariables.Contains(data.GlobalVariable));
if (RecentlyUsed != null) RecentlyUsed.RemoveAll(data => data.Key == FormulaEditorKey.GlobalVariable && deletedVariables.Contains(data.GlobalVariable));
break;
}
}