Exemplo n.º 1
0
 private void WordName_TextChanged(object sender, EventArgs e)
 {
     try
     {
         WordData newWord = new WordData();
         newWord.word = WordName.Text.Trim();
         Tuple <bool, List <WordData> > findResult = dictionary.Contains(newWord);
         if (findResult.Item1)
         {
             WordData selectedWord = findResult.Item2[0];
             if (WordName.Text.Trim().Length > findResult.Item2[findResult.Item2.Count - 1].word.Length)
             {
                 LoadWordData(null);
                 WordName.Text         = Globals.ThisAddIn.Application.Selection.Text;
                 WordList.SelectedItem = null;
             }
             else
             {
                 LoadWordData(findResult.Item2[0]);
                 WordList.SelectedItem = findResult.Item2;
             }
             WordComboBox.Items.Clear();
             foreach (WordData word in findResult.Item2)
             {
                 if (word.word.Length >= Globals.ThisAddIn.Application.Selection.Text.Trim().Length)
                 {
                     WordComboBox.Items.Add(word);
                 }
             }
             if (WordComboBox.Items.Count > 0)
             {
                 WordComboBox.SelectedIndex = 0;
             }
         }
         else
         {
             WordList.SelectedItem = null;
             LoadWordData(null);
             WordComboBox.Text = "";
             WordComboBox.Items.Clear();
             if (Globals.ThisAddIn.currentText == WordName.Text)
             {
                 WordName.Text = Globals.ThisAddIn.Application.Selection.Text;
             }
         }
     }
     catch (NullReferenceException ee)
     {
         NoDictionaryDetected nddWindow = new NoDictionaryDetected();
         nddWindow.ShowDialog();
         nddWindow.StartPosition = FormStartPosition.CenterScreen;
     }
 }
Exemplo n.º 2
0
        private void Add_Button_Click(object sender, EventArgs e)
        {
            WordData newWord = new WordData();

            newWord.word = WordName.Text.Trim();
            if (dictionaryData != null)
            {
                Tuple <bool, List <WordData> > findResult = dictionary.Contains(newWord);
                if (findResult.Item1 &&
                    findResult.Item2[findResult.Item2.Count - 1].word.Length >= newWord.word.Length)
                {
                    WordList.SelectedItem = findResult.Item2;
                    MessageBox.Show("Word Already Exist!");
                    return;
                }
                if (isAllSpace(WordName.Text))
                {
                    MessageBox.Show("No word detected!");
                }
                else
                {
                    newWord.definition = Definition.Text as string;
                    newWord.type       = getSelectedType();
                    newWord.Group      = Group_ComboBox.SelectedItem as string;
                    if (newWord.Group == null)
                    {
                        newWord.Group = Group_ComboBox.Text;
                        List <WordData> wordlist = new List <WordData>();
                        dictionaryData.Groups.Add(Group_ComboBox.Text);
                        Group_ComboBox.Items.Add(Group_ComboBox.Text);
                    }
                    if (newWord.Group == null || newWord.Group == "")
                    {
                        newWord.Group = Group_ComboBox.Items[0].ToString();
                    }
                    dictionary.AddWord(newWord);
                    WordList.Items.Add(newWord);
                    WordList.SelectedItem = newWord;
                }
            }
            else
            {
                NoDictionaryDetected nddWindow = new NoDictionaryDetected();
                nddWindow.ShowDialog();
                nddWindow.StartPosition = FormStartPosition.CenterScreen;
            }
        }