Ejemplo n.º 1
0
        public PrimaryOptionsControl([NotNull] Lifetime lifetime, OptionsSettingsSmartContext settings)
        {
            _settings = settings;

            InitializeComponent();

            groupBoxUserDictionary.Text = ResourceAccessor.GetString("UI_UserDictionaryListTitle")
                                          ?? "User Dictionary";
            groupBoxIgnoredWords.Text = ResourceAccessor.GetString("UI_IgnoredWordListTitle")
                                        ?? "Ignored Words";

            // Extract the string keys from the settings and apply them to the UI list boxes.
            UserWords.Initialize(
                settings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.UserEntries)
                .ToArray()
                );

            IgnoreWords.Initialize(
                settings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreEntries)
                .ToArray()
                );

            // Monitor the changed properties on the UI list boxes and when changed apply the modifications to the settings collection to be saved.

            var userWordsProperty = WinFormsProperty.Create(lifetime, UserWords, x => x.CurrentItems, true);

            userWordsProperty.Change.Advise_NoAcknowledgement(lifetime, x => ApplyChanges(settings, UserWords, p => p.UserEntries));

            var ignoreWordsProperty = WinFormsProperty.Create(lifetime, IgnoreWords, x => x.CurrentItems, true);

            ignoreWordsProperty.Change.Advise_NoAcknowledgement(lifetime, x => ApplyChanges(settings, IgnoreWords, p => p.IgnoreEntries));

            ResetDictionariesGrid(settings);
        }
Ejemplo n.º 2
0
        private void dataGridViewDictList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.RowIndex >= dataGridViewDictList.Rows.Count)
            {
                return;
            }

            var row      = dataGridViewDictList.Rows[e.RowIndex];
            var dictName = Convert.ToString(row.Cells[0].Value);

            var isForSpellCheck = Convert.ToBoolean(row.Cells[1].Value);
            var isForIgnore     = Convert.ToBoolean(row.Cells[2].Value);

            switch (e.ColumnIndex)
            {
            case 0: return;

            case 1: {
                var currentForSepllCheck = new HashSet <string>(_settings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.SpellCheckDictionaries));
                if (isForSpellCheck && !currentForSepllCheck.Contains(dictName))
                {
                    _settings.SetIndexedValue((SpellCheckSettings x) => x.SpellCheckDictionaries, dictName, default(byte));
                    _changesMade = true;
                }
                else if (!isForSpellCheck && currentForSepllCheck.Contains(dictName))
                {
                    _settings.RemoveIndexedValue((SpellCheckSettings x) => x.SpellCheckDictionaries, dictName);
                    _changesMade = true;
                }

                if (isForSpellCheck && isForIgnore)
                {
                    row.Cells[2].Value = false;                     // uncheck the ignore one
                }
                break;
            }

            case 2: {
                var currentForIgnore = new HashSet <string>(_settings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreDictionaries));
                if (isForIgnore && !currentForIgnore.Contains(dictName))
                {
                    _settings.SetIndexedValue((SpellCheckSettings x) => x.IgnoreDictionaries, dictName, default(byte));
                    _changesMade = true;
                }
                else if (!isForIgnore && currentForIgnore.Contains(dictName))
                {
                    _settings.RemoveIndexedValue((SpellCheckSettings x) => x.IgnoreDictionaries, dictName);
                    _changesMade = true;
                }

                if (isForSpellCheck && isForIgnore)
                {
                    row.Cells[1].Value = false;                     // uncheck the spell check one
                }
                break;
            }

            default: return;
            }
        }
Ejemplo n.º 3
0
        public AsyncConverterConfigureAwaitPage([NotNull] Lifetime lifetime, [NotNull] OptionsSettingsSmartContext store,
                                                IPromptWinForm promptWinForms)
            : base(lifetime, store)
        {
            AddHeader("In class and method will be ignored ConfigureAwait suggestion");
            var editItemViewModelFactory = new DefaultCollectionEditItemViewModelFactory(null);
            var buttonProviderFactory    = new DefaultButtonProviderFactory(lifetime, promptWinForms, editItemViewModelFactory);
            var attributeTypes           = new StringCollectionEditViewModel(lifetime, "Attributes:",
                                                                             buttonProviderFactory, editItemViewModelFactory);

            foreach (var type in store.EnumIndexedValues(AsyncConverterSettingsAccessor.ConfigureAwaitIgnoreAttributeTypes))
            {
                attributeTypes.AddItem(type);
            }

            attributeTypes.Items.CollectionChanged += (o, e) =>
            {
                foreach (
                    var entryIndex in
                    OptionsSettingsSmartContext.EnumEntryIndices(AsyncConverterSettingsAccessor.ConfigureAwaitIgnoreAttributeTypes)
                    .ToArray())
                {
                    OptionsSettingsSmartContext.RemoveIndexedValue(AsyncConverterSettingsAccessor.ConfigureAwaitIgnoreAttributeTypes,
                                                                   entryIndex);
                }
                foreach (
                    var editItemViewModel in
                    attributeTypes.Items)
                {
                    OptionsSettingsSmartContext.SetIndexedValue(AsyncConverterSettingsAccessor.ConfigureAwaitIgnoreAttributeTypes,
                                                                editItemViewModel.PresentableName, editItemViewModel.PresentableName);
                }
            };
            AddCustomOption(attributeTypes);
        }
        /// <summary>
        ///     Invoked when OK button in the options dialog is pressed.
        ///     If the page returns <c>false</c>, the the options dialog won't be closed, and focus will be put into this page.
        /// </summary>
        public override bool OnOk()
        {
            Expression <Func <ExternalCodeSettingsKey, IIndexedEntry <string, string> > > generatedFileMasks = key => key.Paths;

            string[] addedPaths   = _externalCodePathsCollectionEdit.Items.Value;
            var      currentPaths = new HashSet <string>();

            foreach (string currentPath in _settings.EnumEntryIndices(generatedFileMasks))
            {
                if (!addedPaths.Contains(currentPath))
                {
                    _settings.RemoveIndexedValue(generatedFileMasks, currentPath);
                }
                else
                {
                    currentPaths.Add(currentPath);
                }
            }
            foreach (string entryIndex in addedPaths.Where(x => !currentPaths.Contains(x)))
            {
                _settings.SetIndexedValue(generatedFileMasks, entryIndex, entryIndex);
            }

            return(base.OnOk());
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Invoked when OK button in the options dialog is pressed.
        ///     If the page returns <c>false</c>, the the options dialog won't be closed, and focus will be put into this page.
        /// </summary>
        public override bool OnOk()
        {
            Expression <Func <UnitySettings, IIndexedEntry <string, string> > > unityClasses    = key => key.UnityClasses;
            Expression <Func <UnitySettings, IIndexedEntry <string, string> > > unityAttributes = key => key.UnityUsageAttributes;

            string[]         addedUnityClasses   = m_unityClassesCollectionEdit.Items.Value;
            HashSet <string> currentUnityClasses = new HashSet <string>();

            foreach (string currentUnityClass in m_settings.EnumEntryIndices(unityClasses))
            {
                if (!addedUnityClasses.Contains(currentUnityClass))
                {
                    m_settings.RemoveIndexedValue(unityClasses, currentUnityClass);
                }
                else
                {
                    currentUnityClasses.Add(currentUnityClass);
                }
            }
            foreach (string entryIndex in addedUnityClasses.Where(x => !currentUnityClasses.Contains(x)))
            {
                m_settings.SetIndexedValue(unityClasses, entryIndex, entryIndex);
            }

            string[]         addedUnityAttributes   = m_unityAttributesCollectionEdit.Items.Value;
            HashSet <string> currentUnityAttributes = new HashSet <string>();

            foreach (string currentUnityAttribute in m_settings.EnumEntryIndices(unityAttributes))
            {
                if (!addedUnityAttributes.Contains(currentUnityAttribute))
                {
                    m_settings.RemoveIndexedValue(unityAttributes, currentUnityAttribute);
                }
                else
                {
                    currentUnityAttributes.Add(currentUnityAttribute);
                }
            }
            foreach (string entryIndex in addedUnityAttributes.Where(x => !currentUnityAttributes.Contains(x)))
            {
                m_settings.SetIndexedValue(unityAttributes, entryIndex, entryIndex);
            }

            return(base.OnOk());
        }
Ejemplo n.º 6
0
 private void RefreshCustomDictionaryList()
 {
     _optionsUI.lstCustomDictionaries.Items.Clear();
     foreach (string item in _settings.EnumEntryIndices <CustomDictionarySettings, string, CustomDictionary>(
                  x => x.CustomDictionaries))
     {
         _optionsUI.lstCustomDictionaries.Items.Add(item);
     }
 }
Ejemplo n.º 7
0
        private void ResetDictionariesGrid(OptionsSettingsSmartContext settings = null)
        {
            if (null == settings)
            {
                settings = _settings;
            }

            var availableDictionaries  = SpellChecker.GetAllAvailableDictionaryNames();
            var ignoreDictionaries     = new HashSet <string>(settings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.IgnoreDictionaries));
            var spellCheckDictionaries = new HashSet <string>(settings.EnumEntryIndices <SpellCheckSettings, string, byte>(x => x.SpellCheckDictionaries));

            dataGridViewDictList.Rows.Clear();
            foreach (var dictionary in availableDictionaries.OrderBy(x => x, StringComparer.OrdinalIgnoreCase))
            {
                var isSpellCheck = spellCheckDictionaries.Contains(dictionary);
                var isIgnore     = ignoreDictionaries.Contains(dictionary);
                dataGridViewDictList.Rows.Add(dictionary, isSpellCheck, isIgnore);
            }
            dataGridViewDictList.Update();
            dataGridViewDictList.Invalidate();
        }
Ejemplo n.º 8
0
        public AsyncSuffixOptionsPage([NotNull] Lifetime lifetime, [NotNull] OptionsSettingsSmartContext store,
                                      IWindowsHookManager windowsHookManager, FormValidators formValidators, IUIApplication iuiApplication)
            : base(lifetime, store)
        {
            AddHeader("Tests");
            AddBoolOption(
                (AsyncSuffixSettings options) => options.ExcludeTestMethodsFromAnalysis,
                "Exclude test methods from analysis");
            var editItemViewModelFactory = new DefaultCollectionEditItemViewModelFactory(null);
            var buttonProviderFactory    = new DefaultButtonProviderFactory(lifetime, windowsHookManager, formValidators,
                                                                            iuiApplication, editItemViewModelFactory);
            var customAsyncTypes = new StringCollectionEditViewModel(lifetime, "Treat these types as async:",
                                                                     buttonProviderFactory, editItemViewModelFactory);

            store.EnumEntryIndices(AsyncSuffixSettingsAccessor.CustomAsyncTypes)
            .ToArray()
            .ForEach(x => customAsyncTypes.AddItem(x));
            customAsyncTypes.Items.CollectionChanged += (o, e) =>
            {
                foreach (
                    var entryIndex in
                    OptionsSettingsSmartContext.EnumEntryIndices(AsyncSuffixSettingsAccessor.CustomAsyncTypes)
                    .ToArray())
                {
                    OptionsSettingsSmartContext.RemoveIndexedValue(AsyncSuffixSettingsAccessor.CustomAsyncTypes,
                                                                   entryIndex);
                }
                foreach (
                    var editItemViewModel in
                    customAsyncTypes.Items)
                {
                    OptionsSettingsSmartContext.SetIndexedValue(AsyncSuffixSettingsAccessor.CustomAsyncTypes,
                                                                editItemViewModel.PresentableName, editItemViewModel.PresentableName);
                }
            };
            AddHeader("Custom types");
            AddCustomOption(customAsyncTypes);
        }