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];
            }
        }
Ejemplo n.º 2
0
        public NewItemDialogViewModel(ISolutionItemProvideService provider, ICurrentCoreVersion currentCore)
        {
            Dictionary <string, NewItemPrototypeGroup> groups = new();

            Categories = 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;
                    Categories.Add(group);
                }

                bool isCompatible = item.IsCompatibleWithCore(currentCore.Current);

                if (!isCompatible && coreIsSpecific)
                {
                    continue;
                }

                var info = new NewItemPrototypeInfo(item, isCompatible);
                group.Add(info);
            }

            Accept = new DelegateCommand(() =>
            {
                CloseOk?.Invoke();
            });
            Cancel = new DelegateCommand(() =>
            {
                CloseCancel?.Invoke();
            });

            Categories.RemoveIf(c => c.Count == 0);

            if (Categories.Count > 0)
            {
                SelectedCategory = Categories[0];
            }

            if (Categories.Count > 0 && Categories[0].Count > 0)
            {
                SelectedPrototype = Categories[0][0];
            }
        }