Beispiel #1
0
        public void SetOptionAndUpdatePreview <T> (T value, IOption option, string preview)
        {
            if (option is Option <CodeStyleOption <T> > )
            {
                var opt = (CodeStyleOption <T>)BooleanCodeStyleOptionViewModel.GetOptionOrDefault(Options, option, Language);
                opt.Value = value;
                Options   = Options.WithChangedOption((Option <CodeStyleOption <T> >)option, opt);
            }
            else if (option is PerLanguageOption <CodeStyleOption <T> > )
            {
                var opt = (CodeStyleOption <T>)BooleanCodeStyleOptionViewModel.GetOptionOrDefault(Options, option, Language);                 // PerLanguageOption in unwrapped.
                opt.Value = value;
                Options   = Options.WithChangedOption((PerLanguageOption <CodeStyleOption <T> >)option, Language, opt);
            }
            else if (option is Option <T> )
            {
                Options = Options.WithChangedOption((Option <T>)option, value);
            }
            else if (option is PerLanguageOption <T> )
            {
                Options = Options.WithChangedOption((PerLanguageOption <T>)option, Language, value);
            }
            else
            {
                throw new InvalidOperationException("Unexpected option type" + option);
            }

            UpdateDocument(preview);
        }
Beispiel #2
0
        public CheckBoxWithComboOptionViewModel(IOption option, string description, string truePreview, string falsePreview, AbstractOptionPreviewViewModel info, OptionSet options, IList <NotificationOptionViewModel> items)
            : base(option, description, truePreview, falsePreview, info)
        {
            NotificationOptions = items;

            var codeStyleOption = ((CodeStyleOption <bool>)BooleanCodeStyleOptionViewModel.GetOptionOrDefault(options, option, info.Language));

            SetProperty(ref _isChecked, codeStyleOption.Value);

            var notificationViewModel = items.Where(i => i.Notification.Severity == codeStyleOption.Notification.Severity).Single();

            SetProperty(ref _selectedNotificationOption, notificationViewModel);
        }
        private EnumCodeStyleOptionViewModel(
            IOption option,
            string language,
            string description,
            T [] enumValues,
            string [] previews,
            AbstractOptionPreviewViewModel info,
            OptionSet options,
            string groupName,
            List <CodeStylePreference> preferences)
            : base(option, description, info, options, groupName, preferences)
        {
            Debug.Assert(preferences.Count == enumValues.Length);
            Debug.Assert(previews.Length == enumValues.Length);

            _enumValues = enumValues.ToImmutableArray();
            _previews   = previews.ToImmutableArray();

            var codeStyleOption = (CodeStyleOption <T>)BooleanCodeStyleOptionViewModel.GetOptionOrDefault(options, option, language);

            var enumIndex = _enumValues.IndexOf(codeStyleOption.Value);

            if (enumIndex < 0 || enumIndex >= Preferences.Count)
            {
                enumIndex = 0;
            }

            _selectedPreference = Preferences [enumIndex];

            var notificationViewModel = NotificationPreferences.Single(i => i.Notification.Severity == codeStyleOption.Notification.Severity);

            _selectedNotificationPreference = NotificationPreferences.Single(p => p.Notification.Severity == notificationViewModel.Notification.Severity);

            NotifyPropertyChanged(nameof(SelectedPreference));
            NotifyPropertyChanged(nameof(SelectedNotificationPreference));
        }
 public RadioButtonViewModel(string description, string preview, string group, TOption value, Option <TOption> option, AbstractOptionPreviewViewModel info, OptionSet options)
     : base(description, preview, info, options, isChecked: BooleanCodeStyleOptionViewModel.GetOptionOrDefault(options, option, info.Language).Equals(value), group: group)
 {
     _value  = value;
     _option = option;
 }
 public CheckBoxOptionViewModel(IOption option, string description, string truePreview, string falsePreview, AbstractOptionPreviewViewModel info, OptionSet options)
     : base(option, description, truePreview, falsePreview, info)
 {
     SetProperty(ref _isChecked, (bool)BooleanCodeStyleOptionViewModel.GetOptionOrDefault(options, option, info.Language));
 }