コード例 #1
0
        /// <summary>
        /// Update the state of the controls based on the current issue
        /// </summary>
        /// <param name="isDisabled">True if the control host is disabled, false if not.</param>
        /// <param name="groupByWord">True to group suggestions by word (multiple languages), or false to
        /// list them as-is (single language).</param>
        /// <param name="currentIssue">The current spelling issue.</param>
        public void UpdateState(bool isDisabled, bool groupByWord, ISpellingIssue currentIssue)
        {
            try
            {
                updatingState = lbSuggestions.IsEnabled = true;

                btnReplace.IsEnabled     = btnReplaceAll.IsEnabled = btnIgnoreOnce.IsEnabled = btnIgnoreAll.IsEnabled =
                    btnAddWord.IsEnabled = btnUndo.IsEnabled = txtMisspelledWord.IsEnabled = false;
                lblIssue.Content         = "_Misspelled Word";
                txtMisspelledWord.Text   = null;
                lbSuggestions.Items.Clear();

                this.CurrentIssue = currentIssue;

                if (isDisabled)
                {
                    lblDisabled.Visibility = Visibility.Visible;
                    return;
                }

                lblDisabled.Visibility = Visibility.Collapsed;

                if (currentIssue == null)
                {
                    txtMisspelledWord.Text = this.NoCurrentIssueText;
                    return;
                }

                if (currentIssue.MisspellingType == MisspellingType.DoubledWord)
                {
                    lblIssue.Content     = "_Doubled Word";
                    btnReplace.IsEnabled = btnIgnoreOnce.IsEnabled = true;
                    lbSuggestions.Items.Add("(Delete word)");
                }
                else
                {
                    txtMisspelledWord.IsEnabled = btnIgnoreOnce.IsEnabled = btnIgnoreAll.IsEnabled = true;
                    btnAddWord.IsEnabled        = (currentIssue.MisspellingType == MisspellingType.MisspelledWord);

                    switch (currentIssue.MisspellingType)
                    {
                    case MisspellingType.CompoundTerm:
                        lblIssue.Content = "Co_mpound Term";
                        break;

                    case MisspellingType.DeprecatedTerm:
                        lblIssue.Content = "_Deprecated Term";
                        break;

                    case MisspellingType.UnrecognizedWord:
                        lblIssue.Content = "Un_recognized Word";
                        break;

                    default:
                        break;
                    }

                    if (currentIssue.Suggestions.Any())
                    {
                        btnReplace.IsEnabled = btnReplaceAll.IsEnabled = true;

                        IEnumerable <ISpellingSuggestion> suggestions;

                        // Group suggestions by word if there are multiple dictionaries
                        if (groupByWord)
                        {
                            suggestions = currentIssue.Suggestions.GroupBy(w => w.Suggestion).Select(g =>
                                                                                                     new MultiLanguageSpellingSuggestion(g.Select(w => w.Culture), g.Key));
                        }
                        else
                        {
                            suggestions = currentIssue.Suggestions;
                        }

                        foreach (var s in suggestions)
                        {
                            lbSuggestions.Items.Add(s);
                        }

                        lbSuggestions.SelectedIndex = 0;
                    }
                    else
                    {
                        lbSuggestions.Items.Add("(No suggestions)");
                    }
                }

                txtMisspelledWord.Text = currentIssue.Word;
            }
            finally
            {
                updatingState = false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Update the state of the controls based on the current issue
        /// </summary>
        /// <param name="isDisabled">True if the control host is disabled, false if not.</param>
        /// <param name="groupByWord">True to group suggestions by word (multiple languages), or false to
        /// list them as-is (single language).</param>
        /// <param name="currentIssue">The current spelling issue.</param>
        public void UpdateState(bool isDisabled, bool groupByWord, ISpellingIssue currentIssue)
        {
            try
            {
                updatingState = lbSuggestions.IsEnabled = true;

                btnReplace.IsEnabled = btnReplaceAll.IsEnabled = btnIgnoreOnce.IsEnabled = btnIgnoreAll.IsEnabled =
                    btnAddWord.IsEnabled = btnUndo.IsEnabled = txtMisspelledWord.IsEnabled = false;
                lblIssue.Content = "_Misspelled Word";
                txtMisspelledWord.Text = null;
                lbSuggestions.Items.Clear();

                this.CurrentIssue = currentIssue;

                if(isDisabled)
                {
                    lblDisabled.Visibility = Visibility.Visible;
                    return;
                }

                lblDisabled.Visibility = Visibility.Collapsed;

                if(currentIssue == null)
                {
                    txtMisspelledWord.Text = this.NoCurrentIssueText;
                    return;
                }

                if(currentIssue.MisspellingType == MisspellingType.DoubledWord)
                {
                    lblIssue.Content = "_Doubled Word";
                    btnReplace.IsEnabled = btnIgnoreOnce.IsEnabled = true;
                    lbSuggestions.Items.Add("(Delete word)");
                }
                else
                {
                    txtMisspelledWord.IsEnabled = btnIgnoreOnce.IsEnabled = btnIgnoreAll.IsEnabled = true;

                    switch(currentIssue.MisspellingType)
                    {
                        case MisspellingType.CompoundTerm:
                            lblIssue.Content = "Co_mpound Term";
                            break;

                        case MisspellingType.DeprecatedTerm:
                            lblIssue.Content = "_Deprecated Term";
                            break;

                        case MisspellingType.UnrecognizedWord:
                            lblIssue.Content = "Un_recognized Word";
                            break;

                        default:
                            break;
                    }

                    if(currentIssue.Suggestions.Any())
                    {
                        btnReplace.IsEnabled = btnReplaceAll.IsEnabled = true;
                        btnAddWord.IsEnabled = (currentIssue.MisspellingType == MisspellingType.MisspelledWord);

                        IEnumerable<ISpellingSuggestion> suggestions;

                        // Group suggestions by word if there are multiple dictionaries
                        if(groupByWord)
                        {
                            suggestions = currentIssue.Suggestions.GroupBy(w => w.Suggestion).Select(g =>
                                new MultiLanguageSpellingSuggestion(g.Select(w => w.Culture), g.Key));
                        }
                        else
                            suggestions = currentIssue.Suggestions;

                        foreach(var s in suggestions)
                            lbSuggestions.Items.Add(s);

                        lbSuggestions.SelectedIndex = 0;
                    }
                    else
                        lbSuggestions.Items.Add("(No suggestions)");
                }

                txtMisspelledWord.Text = currentIssue.Word;
            }
            finally
            {
                updatingState = false;
            }
        }