Ejemplo n.º 1
0
                        ))", RegexOptions.IgnoreCase);                 // non-capturing groups used for better performance

        /// <summary>
        /// Checks if the word is correct type based on chosen Filter.
        /// </summary>
        private bool IsCorrectWordType(GermanWordTranslationPair pairToBeChecked)
        {
            string word              = pairToBeChecked.Word;
            string pattern           = string.Empty;
            bool   isCorrectWordType = true;

            switch (Filter)
            {
            case WordType.Nouns:     // Only nouns are visible
                return(pairToBeChecked.WordIsANoun);

            case WordType.Verbs:
                isCorrectWordType = verbsRegex.IsMatch(word);
                break;

            case WordType.AllButNounsAndVerbs:
                isCorrectWordType = allButRegex.IsMatch(word);
                break;

            default:
                break;     // WordType.All selected so no extra filtering
            }

            return(isCorrectWordType);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes the GermanWordTranslationPair, given as an argument to the method, from the Dictionary.
        /// </summary>
        /// <param name="parameter">GermanWordTranslationPair to be removed from the Dictionary.</param>
        private void RemoveWord(object parameter)
        {
            GermanWordTranslationPair pair = parameter as GermanWordTranslationPair;

            Dictionary.Remove(pair);
            SaveRequired = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if the parameter is a GermanWordTranslationPair.
        /// If it is it can be removed from the Dictionary.
        /// </summary>
        /// <returns>True if the parameter is a valid pair, false if it's not.</returns>
        private bool CanRemoveWord(object parameter)
        {
            GermanWordTranslationPair pair = parameter as GermanWordTranslationPair;

            if (pair == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the first letter of the given GermanWordTranslationPair. Ignores first 4
 /// letters of the Word property string if the word is a noun.
 /// </summary>
 private string GetFirstLetter(GermanWordTranslationPair pair)
 {
     if (pair.WordIsANoun)
     {
         return(pair.Word[4].ToString().ToLower());
     }
     else
     {
         return(pair.Word[0].ToString().ToLower());
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks if the GermanWordTranslationPair's Translation contains CurrentInputWord.
        /// </summary>
        private bool IsCorrectTranslation(GermanWordTranslationPair pairToBeChecked)
        {
            // For clarity's sake changing variable name into something more appropriate
            string currentInputTranslation = CurrentInputWord;
            string translation             = pairToBeChecked.Translation;

            // Case should be ignored
            currentInputTranslation = currentInputTranslation.ToLower();
            translation             = translation.ToLower();

            bool containsWord = translation.Contains(currentInputTranslation);

            return(containsWord);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks if the given object is shown in the view or filtered.
        /// </summary>
        /// <param name="obj">GermanWordTranslationPair to be checked.</param>
        /// <returns>True if it's shown, false if it's hidden.</returns>
        private bool IsShownInView(object obj)
        {
            GermanWordTranslationPair pairToBeChecked = (GermanWordTranslationPair)obj;
            bool isCorrectWordType = IsCorrectWordType(pairToBeChecked);

            if (FilterByTranslation)
            {
                return(isCorrectWordType && IsCorrectTranslation(pairToBeChecked));
            }
            else
            {
                return(isCorrectWordType && IsCorrectWord(pairToBeChecked));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks if the GermanWordTranslationPair's Word starts with the CurrentInputWord.
        /// </summary>
        /// <returns></returns>
        private bool IsCorrectWord(GermanWordTranslationPair pairToBeChecked)
        {
            string word        = pairToBeChecked.Word;
            string revisedWord = string.Empty;

            if (pairToBeChecked.WordIsANoun)
            {
                // Gets a word without articles for gender
                revisedWord = word.Substring(4);
            }

            bool isStartingWithInputWord = word.StartsWith(CurrentInputWord, true, CultureInfo.InvariantCulture) ||
                                           revisedWord.StartsWith(CurrentInputWord, true, CultureInfo.InvariantCulture);

            return(isStartingWithInputWord);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Inserts a new GermanWordTranslationPair into the Dictionary,
        /// if the word isn't in the Dictionary already.
        /// </summary>
        private void InsertWord(object parameter)
        {
            GermanWordTranslationPair inputPair = new GermanWordTranslationPair(CurrentInputWord);

            if (Dictionary.Contains(inputPair))
            {
                string caption = languageViewModel.GetNotification("InsertWordCaption");
                string message = "\"" + CurrentInputWord + "\"" + languageViewModel.GetNotification("InsertWordMessage");
                MessageBox.Show(message, caption);
            }
            else
            {
                Dictionary.Add(inputPair);
                SaveRequired = true;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a run on every new letter occurence, holding the first letter as text,
        /// for the specified paragraph.
        /// </summary>
        /// <param name="pair">Pair whose word's first letter is checked.</param>
        private void CreateFirstLetterRun(Paragraph parentParagraph, GermanWordTranslationPair pair, int index)
        {
            // Set font size, bold and underline properties
            RunProperties firstLetterRunProp = new RunProperties(new Bold());
            Underline     underlinedLetter   = new Underline()
            {
                Val = UnderlineValues.Single
            };
            FontSize letterSize = new FontSize()
            {
                Val = StringValue.FromString("26")
            };

            firstLetterRunProp.Append(underlinedLetter, letterSize);

            // Create run
            Run  firstLetterRun  = new Run();
            Text firstLetterText = new Text();

            firstLetterRun.Append(firstLetterRunProp);
            firstLetterRun.Append(firstLetterText, new Break(), new Break(), new Break());

            string firstLetter = GetFirstLetter(pair);

            if (index == 0)
            {
                // Write the first letter of the first word
                firstLetterText.Text = firstLetter.ToUpper();
                parentParagraph.Append(firstLetterRun);
            }
            else
            {
                var    previousPair        = Dictionary[index - 1];
                string previousFirstLetter = GetFirstLetter(previousPair);

                if (firstLetter != previousFirstLetter)
                {
                    // New letter starting, add 2 empty lines before adding the letter
                    firstLetterText.Text = firstLetter.ToUpper();
                    parentParagraph.Append(new Break(), new Break(), firstLetterRun);
                }
            }
        }
 /// <summary>
 /// Gets the first letter of the given GermanWordTranslationPair. Ignores first 4 
 /// letters of the Word property string if the word is a noun.
 /// </summary>
 private string GetFirstLetter(GermanWordTranslationPair pair)
 {
     if (pair.WordIsANoun)
     {
         return pair.Word[4].ToString().ToLower();
     }
     else
     {
         return pair.Word[0].ToString().ToLower();
     }
 }
        /// <summary>
        /// Creates a run on every new letter occurence, holding the first letter as text,
        /// for the specified paragraph.
        /// </summary>
        /// <param name="pair">Pair whose word's first letter is checked.</param>
        private void CreateFirstLetterRun(Paragraph parentParagraph, GermanWordTranslationPair pair, int index)
        {
            // Set font size, bold and underline properties
            RunProperties firstLetterRunProp = new RunProperties(new Bold());
            Underline underlinedLetter = new Underline() { Val = UnderlineValues.Single };
            FontSize letterSize = new FontSize() { Val = StringValue.FromString("26") };
            firstLetterRunProp.Append(underlinedLetter, letterSize);

            // Create run
            Run firstLetterRun = new Run();
            Text firstLetterText = new Text();
            firstLetterRun.Append(firstLetterRunProp);            
            firstLetterRun.Append(firstLetterText, new Break(), new Break(), new Break());
            
            string firstLetter = GetFirstLetter(pair);
            if (index == 0)
            {
                // Write the first letter of the first word
                firstLetterText.Text = firstLetter.ToUpper();
                parentParagraph.Append(firstLetterRun);
            }
            else
            {
                var previousPair = Dictionary[index - 1];
                string previousFirstLetter = GetFirstLetter(previousPair);

                if (firstLetter != previousFirstLetter)
                {
                    // New letter starting, add 2 empty lines before adding the letter
                    firstLetterText.Text = firstLetter.ToUpper();
                    parentParagraph.Append(new Break(), new Break(), firstLetterRun);
                }
            }
        }
 /// <summary>
 /// Checks if the GermanWordTranslationPair's Translation contains CurrentInputWord.
 /// </summary>
 private bool IsCorrectTranslation(GermanWordTranslationPair pairToBeChecked)
 {
     // For clarity's sake changing variable name into something more appropriate            
     string currentInputTranslation = CurrentInputWord;
     string translation = pairToBeChecked.Translation;
     
     // Case should be ignored
     currentInputTranslation = currentInputTranslation.ToLower();
     translation = translation.ToLower();
     
     bool containsWord = translation.Contains(currentInputTranslation);
     return containsWord;            
 }
        /// <summary>
        /// Checks if the GermanWordTranslationPair's Word starts with the CurrentInputWord.
        /// </summary>
        /// <returns></returns>
        private bool IsCorrectWord(GermanWordTranslationPair pairToBeChecked)
        {
            string word = pairToBeChecked.Word;
            string revisedWord = string.Empty;

            if (pairToBeChecked.WordIsANoun)
            {
                // Gets a word without articles for gender
                revisedWord = word.Substring(4);
            }
            
            bool isStartingWithInputWord = word.StartsWith(CurrentInputWord, true, CultureInfo.InvariantCulture) ||
                revisedWord.StartsWith(CurrentInputWord, true, CultureInfo.InvariantCulture);

            return isStartingWithInputWord;            
        }
                        ))", RegexOptions.IgnoreCase); // non-capturing groups used for better performance                                                  

        /// <summary>
        /// Checks if the word is correct type based on chosen Filter.
        /// </summary>
        private bool IsCorrectWordType(GermanWordTranslationPair pairToBeChecked)
        {
            string word = pairToBeChecked.Word;
            string pattern = string.Empty;
            bool isCorrectWordType = true;
            
            switch (Filter)
            {
                case WordType.Nouns: // Only nouns are visible
                    return pairToBeChecked.WordIsANoun;                    
                case WordType.Verbs:                    
                    isCorrectWordType = verbsRegex.IsMatch(word);
                    break;
                case WordType.AllButNounsAndVerbs:
                    isCorrectWordType = allButRegex.IsMatch(word);
                    break;
                default: 
                    break; // WordType.All selected so no extra filtering
            }
                        
            return isCorrectWordType;
        }
        /// <summary>
        /// Inserts a new GermanWordTranslationPair into the Dictionary, 
        /// if the word isn't in the Dictionary already.
        /// </summary>
        private void InsertWord(object parameter)
        {
            GermanWordTranslationPair inputPair = new GermanWordTranslationPair(CurrentInputWord);

            if (Dictionary.Contains(inputPair))
            {
                string caption = languageViewModel.GetNotification("InsertWordCaption");
                string message = "\"" + CurrentInputWord + "\"" + languageViewModel.GetNotification("InsertWordMessage");
                MessageBox.Show(message, caption);
            }
            else
            {
                Dictionary.Add(inputPair);
                SaveRequired = true;
            }
        }