Catrobat.IDE.Core.ViewModels.Editor.Formula.FormulaKeyboardViewModel.GlobalVariablesSource_OnCollectionChanged C# (CSharp) Method

GlobalVariablesSource_OnCollectionChanged() private method

private GlobalVariablesSource_OnCollectionChanged ( object sender, NotifyCollectionChangedEventArgs e ) : void
sender object
e System.Collections.Specialized.NotifyCollectionChangedEventArgs
return void
        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;
            }
        }