public void NamesListRemove()
        {
            // Arrange
            var namesList = new NamesList(Directory.GetCurrentDirectory(), "en", false, null);
            namesList.Add("Jones123");

            // Act
            namesList.Remove("Jones123");

            // Assert
            Assert.IsFalse(namesList.GetNames().Contains("Jones123"));
        }
        public void NamesListIsInNamesEtcMultiWordList()
        {
            // Arrange
            var namesList = new NamesList(Directory.GetCurrentDirectory(), "en", false, null);

            // Act
            namesList.Add("Charlie Parker123");
            var exists = namesList.IsInNamesEtcMultiWordList("This is Charlie Parker123!", "Charlie Parker123");

            // Assert
            Assert.IsTrue(exists);
        }
        public void NamesListAddMultiWord()
        {
            // Arrange
            var namesList = new NamesList(Directory.GetCurrentDirectory(), "en", false, null);

            // Act
            namesList.Add("Charlie Parker123");
            var exists = namesList.GetMultiNames().Contains("Charlie Parker123");

            // Assert
            Assert.IsTrue(exists);
        }
        private void ButtonOkClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBoxAddName.Text))
            {
                return;
            }

            NewName = textBoxAddName.Text.RemoveControlCharacters().Trim();
            string languageName = null;
            _language = Configuration.Settings.Language.Main;

            if (!string.IsNullOrEmpty(Configuration.Settings.General.SpellCheckLanguage))
            {
                languageName = Configuration.Settings.General.SpellCheckLanguage;
            }
            else
            {
                List<string> list = Utilities.GetDictionaryLanguages();
                if (list.Count > 0)
                {
                    string name = list[0];
                    int start = name.LastIndexOf('[');
                    int end = name.LastIndexOf(']');
                    if (start > 0 && end > start)
                    {
                        start++;
                        name = name.Substring(start, end - start);
                        languageName = name;
                    }
                    else
                    {
                        MessageBox.Show(string.Format(_language.InvalidLanguageNameX, name));
                        return;
                    }
                }
            }

            languageName = LanguageAutoDetect.AutoDetectLanguageName(languageName, _subtitle);
            if (comboBoxDictionaries.Items.Count > 0)
            {
                string name = comboBoxDictionaries.SelectedItem.ToString();
                int start = name.LastIndexOf('[');
                int end = name.LastIndexOf(']');
                if (start >= 0 && end > start)
                {
                    start++;
                    name = name.Substring(start, end - start);
                    languageName = name;
                }
            }

            if (string.IsNullOrEmpty(languageName))
                languageName = "en_US";

            var namesList = new NamesList(Configuration.DictionariesFolder, languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
            if (namesList.Add(textBoxAddName.Text))
                DialogResult = DialogResult.OK;
            else
                DialogResult = DialogResult.Cancel;
        }
        public bool AddName(string word)
        {
            if (word == null || word.Length <= 1 || _namesEtcList.Contains(word))
                return false;

            _namesEtcList.Add(word);
            _namesEtcListUppercase.Add(word.ToUpper());
            if (_languageName.StartsWith("en_", StringComparison.Ordinal) && !word.EndsWith('s'))
            {
                _namesEtcList.Add(word + "s");
                _namesEtcListUppercase.Add(word.ToUpper() + "S");
            }
            if (!word.EndsWith('s'))
            {
                _namesEtcListWithApostrophe.Add(word + "'s");
                _namesEtcListUppercase.Add(word.ToUpper() + "'S");
            }
            if (!word.EndsWith('\''))
                _namesEtcListWithApostrophe.Add(word + "'");

            var namesList = new NamesList(Configuration.DictionariesFolder, _languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
            namesList.Add(word);
            return true;
        }
Exemple #6
0
 private void ButtonAddNamesEtcClick(object sender, EventArgs e)
 {
     string language = GetCurrentWordListLanguage();
     string text = textBoxNameEtc.Text.RemoveControlCharacters().Trim();
     if (!string.IsNullOrEmpty(language) && text.Length > 1 && !_wordListNamesEtc.Contains(text))
     {
         var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
         namesList.Add(text);
         LoadNamesEtc(language, true);
         labelStatus.Text = string.Format(Configuration.Settings.Language.Settings.WordAddedX, text);
         textBoxNameEtc.Text = string.Empty;
         textBoxNameEtc.Focus();
         for (int i = 0; i < listBoxNamesEtc.Items.Count; i++)
         {
             if (listBoxNamesEtc.Items[i].ToString() == text)
             {
                 listBoxNamesEtc.SelectedIndex = i;
                 int top = i - 5;
                 if (top < 0)
                     top = 0;
                 listBoxNamesEtc.TopIndex = top;
                 break;
             }
         }
     }
     else
     {
         MessageBox.Show(Configuration.Settings.Language.Settings.WordAlreadyExists);
     }
 }
        public void DoAction(SpellCheckAction action)
        {
            switch (action)
            {
                case SpellCheckAction.Change:
                    _noOfChangedWords++;
                    _mainWindow.CorrectWord(_prefix + ChangeWord + _postfix, _currentParagraph, _prefix + _currentWord + _postfix, ref _firstChange, _wordsIndex);
                    break;
                case SpellCheckAction.ChangeAll:
                    _noOfChangedWords++;
                    if (!_changeAllDictionary.ContainsKey(_currentWord))
                        _changeAllDictionary.Add(_currentWord, ChangeWord);
                    _mainWindow.CorrectWord(_prefix + ChangeWord + _postfix, _currentParagraph, _prefix + _currentWord + _postfix, ref _firstChange, -1);
                    break;
                case SpellCheckAction.Skip:
                    _noOfSkippedWords++;
                    break;
                case SpellCheckAction.SkipAll:
                    _noOfSkippedWords++;
                    _skipAllList.Add(ChangeWord.ToUpper());
                    if (ChangeWord.EndsWith('\'') || ChangeWord.StartsWith('\''))
                        _skipAllList.Add(ChangeWord.ToUpper().Trim('\''));
                    break;
                case SpellCheckAction.AddToDictionary:
                    if (_userWordList.IndexOf(ChangeWord) < 0)
                    {
                        _noOfAddedWords++;
                        string s = ChangeWord.Trim().ToLower();
                        if (s.Contains(' '))
                            _userPhraseList.Add(s);
                        else
                            _userWordList.Add(s);
                        Utilities.AddToUserDictionary(s, _languageName);
                    }
                    break;
                case SpellCheckAction.AddToNamesEtc:
                    if (ChangeWord.Length > 1 && !_namesEtcList.Contains(ChangeWord))
                    {
                        _namesEtcList.Add(ChangeWord);
                        _namesEtcListUppercase.Add(ChangeWord.ToUpper());
                        if (_languageName.StartsWith("en_", StringComparison.Ordinal) && !ChangeWord.EndsWith('s'))
                        {
                            _namesEtcList.Add(ChangeWord + "s");
                            _namesEtcListUppercase.Add(ChangeWord.ToUpper() + "S");
                        }
                        if (!ChangeWord.EndsWith('s'))
                        {
                            _namesEtcListWithApostrophe.Add(ChangeWord + "'s");
                            _namesEtcListUppercase.Add(ChangeWord.ToUpper() + "'S");
                        }
                        if (!ChangeWord.EndsWith('\''))
                            _namesEtcListWithApostrophe.Add(ChangeWord + "'");

                        var namesList = new NamesList(Configuration.DictionariesFolder, _languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
                        namesList.Add(ChangeWord);
                    }
                    break;
                case SpellCheckAction.ChangeWholeText:
                    _mainWindow.ShowStatus(string.Format(Configuration.Settings.Language.Main.SpellCheckChangedXToY, _currentParagraph.Text.Replace(Environment.NewLine, " "), ChangeWholeText.Replace(Environment.NewLine, " ")));
                    _currentParagraph.Text = ChangeWholeText;
                    _mainWindow.ChangeWholeTextMainPart(ref _noOfChangedWords, ref _firstChange, _currentIndex, _currentParagraph);

                    break;
            }
            labelActionInfo.Text = string.Empty;
            PrepareNextWord();
            CheckActions();
        }