public NewItemDialogViewModel(ISolutionItemProvideService provider) { Dictionary <string, NewItemPrototypeGroup> groups = new(); ItemPrototypes = new ObservableCollection <NewItemPrototypeGroup>(); foreach (var item in provider.AllCompatible) { if (!groups.TryGetValue(item.GetGroupName(), out var group)) { group = new NewItemPrototypeGroup(item.GetGroupName()); groups[item.GetGroupName()] = group; ItemPrototypes.Add(group); } var info = new NewItemPrototypeInfo(item); group.Add(info); FlatItemPrototypes.Add(info); } Accept = new DelegateCommand(() => { CloseOk?.Invoke(); }); Cancel = new DelegateCommand(() => { CloseCancel?.Invoke(); }); if (ItemPrototypes.Count > 0 && ItemPrototypes[0].Count > 0) { SelectedPrototype = ItemPrototypes[0][0]; } }
public NewItemDialogViewModel(ISolutionItemProvideService provider, ICurrentCoreVersion currentCore) { Dictionary <string, NewItemPrototypeGroup> groups = new(); ItemPrototypes = new ObservableCollection <NewItemPrototypeGroup>(); bool coreIsSpecific = currentCore.IsSpecified; foreach (var item in provider.All) { if (!groups.TryGetValue(item.GetGroupName(), out var group)) { group = new NewItemPrototypeGroup(item.GetGroupName()); groups[item.GetGroupName()] = group; ItemPrototypes.Add(group); } bool isCompatible = item.IsCompatibleWithCore(currentCore.Current); if (!isCompatible && coreIsSpecific) { continue; } var info = new NewItemPrototypeInfo(item, isCompatible); group.Add(info); FlatItemPrototypes.Add(info); } Accept = new DelegateCommand(() => { CloseOk?.Invoke(); }); Cancel = new DelegateCommand(() => { CloseCancel?.Invoke(); }); if (ItemPrototypes.Count > 0 && ItemPrototypes[0].Count > 0) { SelectedPrototype = ItemPrototypes[0][0]; } }