Exemplo n.º 1
0
        public SettingsVM(ISettings settings, UIElementsIntegration uiIntegration)
        {
            this.settings = settings;

            CloseCommand = new Command(Close);
            ResetCommand = new Command(Reset);
            SaveCommand  = new Command(Save);

            SettingsSections = new ObservableCollection <SettingsSectionVM>();
            ControlSelector  = new ConfigControlTemplateSelector();

            var groups = uiIntegration.SettingItems.Groups.Where(g => g != null).OrderBy(g => uiIntegration.SettingItems.GetGroupOrder(g));

            foreach (var section in groups)
            {
                var sectionVM = new SettingsSectionVM(section);

                foreach (SettingItem item in uiIntegration.SettingItems[section])
                {
                    Type controlType = item.ControlType ?? GetDefaultControlType(item.DefaultValue.GetType());

                    if (controlType != null)
                    {
                        var vm = new SettingVM(settings, item.Name, item.EnabledCondition, controlType);
                        sectionVM.Add(vm);
                    }
                }

                SettingsSections.Add(sectionVM);
            }

            SelectedSection = SettingsSections.FirstOrDefault();

            Text.LocaleChanged += () => NotifyPropertyChanged(
                nameof(WindowTitle),
                nameof(SaveText),
                nameof(CloseText),
                nameof(ResetToDefaultsText)
                );

            this.settings.Save("Current");
        }
Exemplo n.º 2
0
        public SettingsVM(ISettings settings, SettingsConfig settingConfig)
        {
            this.settings = settings;

            CloseCommand = new Command(Close);
            ResetCommand = new Command(Reset);
            SaveCommand  = new Command(Save);

            SettingsSections = new ObservableCollection <SettingsSectionVM>();
            ControlSelector  = new ConfigControlTemplateSelector();

            var sections = settingConfig.Where(c => !string.IsNullOrEmpty(c.Section)).GroupBy(c => c.Section);

            foreach (var section in sections)
            {
                var sectionVM = new SettingsSectionVM()
                {
                    Title = section.Key
                };

                foreach (SettingItem item in section)
                {
                    Type controlType = item.Section != null ?
                                       (item.ControlType ?? GetDefaultControlType(item.DefaultValue.GetType())) :
                                       null;

                    if (controlType != null)
                    {
                        sectionVM.Add(new SettingVM(settings, item.Name, item.EnabledCondition, controlType));
                    }
                }

                SettingsSections.Add(sectionVM);
            }

            SelectedSection = SettingsSections.FirstOrDefault();

            this.settings.Save("Current");
        }