コード例 #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);
        }