Esempio n. 1
0
        /// <summary>
        /// Replace all occurrences of the misspelled word with the selected word
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will
        /// be raised and will notify us of the remaining misspellings.</remarks>
        private void btnReplaceAll_Click(object sender, RoutedEventArgs e)
        {
            SpellingSuggestion suggestion;

            if (misspellings.Count != 0 && misspellings[0].Word.Length != 0)
            {
                if (!lbSuggestions.IsEnabled)
                {
                    suggestion = new SpellingSuggestion(null, txtMisspelledWord.Text.Trim());
                }
                else
                {
                    if (lbSuggestions.SelectedIndex < 0)
                    {
                        if (lbSuggestions.Items.Count != 0 && lbSuggestions.SelectedIndex < 0)
                        {
                            lbSuggestions.SelectedIndex = 0;
                        }

                        return;
                    }

                    suggestion = (SpellingSuggestion)lbSuggestions.SelectedItem;
                }

                currentTagger.Dictionary.ReplaceAllOccurrences(misspellings[0].Word, suggestion);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Replace the misspelled word with the given suggestion
        /// </summary>
        /// <param name="suggestion">The suggestion with which to replace the word</param>
        private void ReplaceWord(SpellingSuggestion suggestion)
        {
            int index = selectedMisspelling.Span.Start;

            textBox.Text           = textBox.Text.Remove(index, selectedMisspelling.Span.Length).Insert(index, suggestion.Suggestion);
            textBox.SelectionStart = index + suggestion.Suggestion.Length;
        }
Esempio n. 3
0
        public static string GetDisplayHtml(this SpellingSuggestion suggestion)
        {
            //Query must have either key words or job title or name
            //There shouldn't ever be spelling suggestions for names, but handle it anyway
            var keywords = string.Empty;

            if (suggestion.Criteria.KeywordsExpression != null)
            {
                keywords = suggestion.Criteria.KeywordsExpression.GetUserExpression();
            }
            else if (suggestion.Criteria.JobTitleExpression != null)
            {
                keywords = suggestion.Criteria.JobTitleExpression.GetUserExpression();
            }
            else if (!string.IsNullOrEmpty(suggestion.Criteria.Name))
            {
                keywords = suggestion.Criteria.Name;
            }

            foreach (var correction in suggestion.Corrections)
            {
                keywords = keywords.Replace(correction.Value, "<b><i>" + correction.Value + "</i></b>");
            }
            return(keywords);
        }
Esempio n. 4
0
 /// <summary>Constructor for multi-language spelling suggestions smart tag actions.</summary>
 /// <param name="trackingSpan">The tracking span.</param>
 /// <param name="replaceWith">The suggestion to replace misspelled word with</param>
 /// <param name="cultures">The cultures from which the suggested word was chosen.</param>
 /// <param name="dictionary">The dictionary used to perform the Replace All action</param>
 public MultiLanguageSpellSmartTagAction(ITrackingSpan trackingSpan,
                                         SpellingSuggestion replaceWith,
                                         IEnumerable <CultureInfo> cultures,
                                         SpellingDictionary dictionary)
     : base(trackingSpan, replaceWith, dictionary)
 {
     this.cultures    = cultures.ToArray();
     this.displayText = null;
 }
 /// <summary>Constructor for multi-language spelling suggestions smart tag actions.</summary>
 /// <param name="trackingSpan">The tracking span.</param>
 /// <param name="replaceWith">The suggestion to replace misspelled word with</param>
 /// <param name="cultures">The cultures from which the suggested word was chosen.</param>
 /// <param name="dictionary">The dictionary used to perform the Replace All action</param>
 public MultiLanguageSpellSmartTagAction(ITrackingSpan trackingSpan,
                                         SpellingSuggestion replaceWith,
                                         IEnumerable<CultureInfo> cultures,
                                         SpellingDictionary dictionary)
     : base(trackingSpan, replaceWith, dictionary)
 {
     this.cultures = cultures.ToArray();
     this.displayText = null;
 }
        public ICollection <string> GetSuggestions(string word)
        {
            var appSuggestions = this.document.Content.GetSpellingSuggestions();

            string[] strArray = new string[appSuggestions.Count];
            for (int i = 0; i < appSuggestions.Count; i++)
            {
                SpellingSuggestion suggestion = appSuggestions[i + 1];
                strArray[i] = suggestion.Name;
            }

            return(strArray);
        }
Esempio n. 7
0
        public override IEnumerable <SpellingSuggestion> GetSuggestions(string word)
        {
            // Get the suggestions from Hunspell.
            string[] words = hunspell.Suggest(word);

            // Wrap each suggested word in a spelling suggestion.
            var suggestions = new List <SpellingSuggestion>();

            foreach (string suggestedWord in words)
            {
                var suggestion = new SpellingSuggestion(suggestedWord);
                suggestions.Add(suggestion);
            }

            // Return the resulting suggestions.
            return(suggestions);
        }
Esempio n. 8
0
        //=====================================================================

        /// <inheritdoc />
        public override void Invoke(CancellationToken cancellationToken)
        {
            var replacement = replaceWith;

            if (escapeApostrophes)
            {
                replacement = new SpellingSuggestion(replacement.Culture, replacement.Suggestion.Replace("'", "''"));
            }

            if (dictionary != null && Keyboard.Modifiers == ModifierKeys.Control)
            {
                dictionary.ReplaceAllOccurrences(this.Span.GetText(this.Span.TextBuffer.CurrentSnapshot), replacement);
            }
            else
            {
                this.Span.TextBuffer.Replace(this.Span.GetSpan(this.Span.TextBuffer.CurrentSnapshot), replacement.Suggestion);
            }
        }
        /// <summary>
        /// Replace all occurrences of the misspelled word with the selected word
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will
        /// be raised and will notify us of the remaining misspellings.</remarks>
        private void cmdReplaceAll_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            MisspellingTag currentIssue = ucSpellCheck.CurrentIssue as MisspellingTag;

            if (currentIssue != null && currentIssue.Word.Length != 0)
            {
                var suggestion = ucSpellCheck.SelectedSuggestion;

                if (suggestion != null)
                {
                    var replacement = suggestion;

                    if (currentIssue.EscapeApostrophes)
                    {
                        replacement = new SpellingSuggestion(replacement.Culture, replacement.Suggestion.Replace("'", "''"));
                    }

                    currentTagger.Dictionary.ReplaceAllOccurrences(currentIssue.Word, replacement);
                }
            }
        }
Esempio n. 10
0
        //=====================================================================

        /// <summary>
        /// Constructor for spelling suggestions smart tag actions
        /// </summary>
        /// <param name="span">The word span to replace</param>
        /// <param name="replaceWith">The suggestion to replace misspelled word with</param>
        /// <param name="dictionary">The dictionary used to perform the Replace All action</param>
        public SpellSmartTagAction(ITrackingSpan span, SpellingSuggestion replaceWith, SpellingDictionary dictionary)
        {
            this.span        = span;
            this.replaceWith = replaceWith;
            this.dictionary  = dictionary;
        }
 //=====================================================================
 /// <summary>
 /// Constructor for spelling suggestions smart tag actions
 /// </summary>
 /// <param name="span">The word span to replace</param>
 /// <param name="replaceWith">The suggestion to replace misspelled word with</param>
 /// <param name="dictionary">The dictionary used to perform the Replace All action</param>
 public SpellSmartTagAction(ITrackingSpan span, SpellingSuggestion replaceWith, SpellingDictionary dictionary)
 {
     this.span = span;
     this.replaceWith = replaceWith;
     this.dictionary = dictionary;
 }
        /// <summary>
        /// Replace all occurrences of the misspelled word with the selected word
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        /// <remarks>Since we're making the change through the dictionary, the <c>TagsChanged</c> event will
        /// be raised and will notify us of the remaining misspellings.</remarks>
        private void btnReplaceAll_Click(object sender, RoutedEventArgs e)
        {
            SpellingSuggestion suggestion;

            if(misspellings.Count != 0 && misspellings[0].Word.Length != 0)
            {
                if(!lbSuggestions.IsEnabled)
                    suggestion = new SpellingSuggestion(null, txtMisspelledWord.Text.Trim());
                else
                {
                    if(lbSuggestions.SelectedIndex < 0)
                    {
                        if(lbSuggestions.Items.Count != 0 && lbSuggestions.SelectedIndex < 0)
                            lbSuggestions.SelectedIndex = 0;

                        return;
                    }

                    suggestion = (SpellingSuggestion)lbSuggestions.SelectedItem;
                }

                currentTagger.Dictionary.ReplaceAllOccurrences(misspellings[0].Word, suggestion);
            }
        }