public void SetOptionAndUpdatePreview <T>(T value, IOption option, string preview)
        {
            if (option is Option <CodeStyleOption <T> > )
            {
                var opt = OptionStore.GetOption((Option <CodeStyleOption <T> >)option);
                opt.Value = value;
                OptionStore.SetOption((Option <CodeStyleOption <T> >)option, opt);
            }
            else if (option is PerLanguageOption <CodeStyleOption <T> > )
            {
                var opt = OptionStore.GetOption((PerLanguageOption <CodeStyleOption <T> >)option, Language);
                opt.Value = value;
                OptionStore.SetOption((PerLanguageOption <CodeStyleOption <T> >)option, Language, opt);
            }
            else if (option is Option <T> )
            {
                OptionStore.SetOption((Option <T>)option, value);
            }
            else if (option is PerLanguageOption <T> )
            {
                OptionStore.SetOption((PerLanguageOption <T>)option, Language, value);
            }
            else
            {
                throw new InvalidOperationException("Unexpected option type");
            }

            UpdateDocument(preview);
        }
        public BooleanCodeStyleOptionViewModel(
            IOption option,
            string description,
            string truePreview,
            string falsePreview,
            AbstractOptionPreviewViewModel info,
            OptionStore optionStore,
            string groupName,
            List <CodeStylePreference> preferences = null,
            List <NotificationOptionViewModel> notificationPreferences = null)
            : base(option, description, info, groupName, preferences, notificationPreferences)
        {
            _truePreview  = truePreview;
            _falsePreview = falsePreview;

            var codeStyleOption = ((CodeStyleOption <bool>)optionStore.GetOption(new OptionKey(option, option.IsPerLanguage ? info.Language : null)));

            _selectedPreference = Preferences.Single(c => c.IsChecked == codeStyleOption.Value);

            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));
        }
Ejemplo n.º 3
0
 public CheckBoxOptionViewModel(
     IOption option,
     string description,
     string truePreview,
     string falsePreview,
     AbstractOptionPreviewViewModel info,
     OptionStore optionStore
     ) : base(option, description, truePreview, falsePreview, info)
 {
     SetProperty(
         ref _isChecked,
         (bool)optionStore.GetOption(
             new OptionKey(option, option.IsPerLanguage ? info.Language : null)
             )
         );
 }
Ejemplo n.º 4
0
 public RadioButtonViewModel(
     string description,
     string preview,
     string group,
     TOption value,
     Option <TOption> option,
     AbstractOptionPreviewViewModel info,
     OptionStore optionStore
     )
     : base(
         description,
         preview,
         info,
         isChecked: optionStore.GetOption(option).Equals(value),
         group: group
         )
 {
     _value  = value;
     _option = option;
 }
Ejemplo n.º 5
0
        private EnumCodeStyleOptionViewModel(
            IOption option,
            string language,
            string description,
            T[] enumValues,
            string[] previews,
            AbstractOptionPreviewViewModel info,
            OptionStore optionStore,
            string groupName,
            List <CodeStylePreference> preferences)
            : base(option, description, info, groupName, preferences)
        {
            Debug.Assert(preferences.Count == enumValues.Length);
            Debug.Assert(previews.Length == enumValues.Length);

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

            var codeStyleOption = (CodeStyleOption <T>)optionStore.GetOption(new OptionKey(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));
        }