//------------------------------------------------------------------------
        #region ** private stuff

        // update dialog to show current error
        void UpdateCurrentError()
        {
            // design time
            if (_errors == null)
            {
                return;
            }

            // finished with this batch of errors
            if (ErrorIndex >= _errors.Count)
            {
                // check whether the editor has more text to check
                while (_editor.HasMoreText())
                {
                    _errors = _spell.CheckText(_editor.Text);
                    if (_errors.Count > 0)
                    {
                        _errorCount += _errors.Count;
                        ErrorIndex   = 0;
                        return;
                    }
                }

                // editor has no more text...
                DialogResult = MessageBoxResult.OK;
                return;
            }

            // update current error
            CharRange err = CurrentError;

            // select word in editor
            _editor.Select(err.Start, err.Text.Length);

            // honor 'change all' list
            if (_changeAll.ContainsKey(err.Text))
            {
                _textChangeTo = _changeAll[err.Text];
                _btnChange_Click(this, new RoutedEventArgs());
                return;
            }

            // raise 'BadWordFound' event
            BadWordEventArgs e = new BadWordEventArgs(this, _editor as Control, err, _errors);

            _spell.OnBadWordFound(e);
            if (e.Cancel)
            {
                DialogResult = MessageBoxResult.Cancel;
                return;
            }

            // show whole sentence, highlight bad word
            _updatingText        = true;
            _sentence            = GetSentence(_editor.Text, err);
            _originalText        = _sentence.Text;
            _txtError.FontFamily = _editor.Control.FontFamily;
            _txtError.Text       = _sentence.Text;
            _txtError.Select(err.Start - _sentence.Start, err.Length);
            _txtError.Selection.FontWeight = FontWeights.Bold;
            _txtError.Selection.Foreground = _errorForeground;
            _updatingText = false;

            // repeated word?
            if (err.Duplicate)
            {
                // adjust dialog
                _lblNotInDictionary.Visibility = Visibility.Collapsed;
                _lblRepeatedWord.Visibility    = Visibility.Visible;
                _btnIgnoreAll.IsEnabled        = false;
                _btnChangeAll.IsEnabled        = false;
                _btnAdd.IsEnabled = false;

                // no suggestions
                _listSuggestions.Items.Clear();
            }
            else
            {
                // adjust dialog
                _lblRepeatedWord.Visibility    = Visibility.Collapsed;
                _lblNotInDictionary.Visibility = Visibility.Visible;
                _btnIgnoreAll.IsEnabled        = true;
                _btnChangeAll.IsEnabled        = true;
                _btnAdd.IsEnabled = true;

                // show suggestions
                UpdateSuggestions(err.Text);
            }

            // focus to new word
            _txtError.Focus();
            _btnSuggest.IsEnabled = false;
            AcceptButton          = _btnIgnore;

            // show 'Add' button only if user dictionary is enabled
            _btnAdd.Visibility = _spell.UserDictionary.Enabled ? Visibility.Visible : Visibility.Collapsed;

            // update button status
            UpdateButtonStatus();

            // all ready, fire ErrorDisplayed event
            OnErrorDisplayed(EventArgs.Empty);
        }
Пример #2
0
        //------------------------------------------------------------------------
        #region ** private stuff

        // update dialog to show current error
        private void UpdateCurrentError()
        {
            // design time
            if (DesignMode || _errors == null)
            {
                return;
            }

            // finished with this batch of errors
            if (ErrorIndex >= _errors.Count)
            {
                // check whether the editor has more text to check
                while (_editor.HasMoreText())
                {
                    _errors = _spell.CheckText(_editor.Text);
                    if (_errors.Count > 0)
                    {
                        _errorCount += _errors.Count;
                        ErrorIndex   = 0;
                        return;
                    }
                }

                // editor has no more text...
                DialogResult = DialogResult.OK;
                return;
            }

            // update current error
            CharRange err = CurrentError;

            // select word in editor
            _editor.Select(err.Start, err.Text.Length);

            // honor 'change all' list
            if (_changeAll.ContainsKey(err.Text))
            {
                _txtChangeTo.Text = _changeAll[err.Text];
                _btnChange_Click(this, EventArgs.Empty);
                return;
            }

            // show bad word, new text
            _txtError.Text    = err.Text;
            _txtChangeTo.Text = string.Empty;

            // repeated word?
            if (err.Duplicate)
            {
                // adjust dialog
                _lblNotInDictionary.Visible = false;
                _lblRepeatedWord.Visible    = true;
                _btnIgnoreAll.Enabled       = false;
                _btnChangeAll.Enabled       = false;
                _btnAdd.Enabled             = false;

                // no suggestions
                _listSuggestions.Items.Clear();
            }
            else
            {
                // adjust dialog
                _lblRepeatedWord.Visible    = false;
                _lblNotInDictionary.Visible = true;
                _btnIgnoreAll.Enabled       = true;
                _btnChangeAll.Enabled       = true;
                _btnAdd.Enabled             = true;

                // show suggestions
                string[] suggestions = _spell.GetSuggestions(err.Text);
                _listSuggestions.Items.Clear();
                if (suggestions.Length > 0)
                {
                    _listSuggestions.Items.AddRange(suggestions);
                    _listSuggestions.SelectedIndex = 0;
                }
                else
                {
                    _listSuggestions.Items.Add(_lblNoSuggestions.Text);
                    _listSuggestions.SelectedIndex = -1;
                }
            }

            // focus to new word
            _txtChangeTo.SelectAll();
            _txtChangeTo.Focus();
            _btnSuggest.Enabled = false;
            AcceptButton        = _btnIgnore;

            // show 'Add' button only if user dictionary is enabled
            _btnAdd.Visible = _spell.UserDictionary.Enabled;

            // all ready, fire ErrorDisplayed event
            OnErrorDisplayed(EventArgs.Empty);
        }
Пример #3
0
        //------------------------------------------------------------------------
        #region ** private stuff

        // update dialog to show current error
        private void UpdateCurrentError()
        {
            // design time
            if (DesignMode || _errors == null)
            {
                return;
            }

            // finished with this batch of errors
            if (ErrorIndex < 0 || ErrorIndex >= _errors.Count)
            {
                // check whether the editor has more text to check
                while (_editor.HasMoreText())
                {
                    _errors = _spell.CheckText(_editor.Text);
                    if (_errors.Count > 0)
                    {
                        _errorCount += _errors.Count;
                        ErrorIndex   = 0;
                        return;
                    }
                }

                // editor has no more text...
                DialogResult = DialogResult.OK;
                return;
            }

            // update current error
            CharRange err = CurrentError;

            // select word in editor
            _editor.Select(err.Start, err.Text.Length);

            // honor 'change all' list
            if (_changeAll.ContainsKey(err.Text))
            {
                _textChangeTo = _changeAll[err.Text];
                _btnChange_Click(this, EventArgs.Empty);
                return;
            }

            // show whole sentence, highlight bad word
            _sentence      = GetSentence(_editor.Text, err);
            _txtError.Font = _editor.Control.Font;
            _txtError.Text = _sentence.Text;
            _txtError.Select(err.Start - _sentence.Start, err.Length);
            _txtError.SelectionFont      = new Font(_txtError.Font, FontStyle.Bold);
            _txtError.SelectionColor     = _errorForeColor;
            _txtError.SelectionBackColor = _errorBackColor;
            _txtError.Select(_txtError.SelectionStart + _txtError.SelectionLength, 0);

            // repeated word?
            if (err.Duplicate)
            {
                // adjust dialog
                _lblNotInDictionary.Visible = false;
                _lblRepeatedWord.Visible    = true;
                _btnChange.Text             = _lblRemove.Text;
                _btnIgnoreAll.Enabled       = false;
                _btnChangeAll.Enabled       = false;
                _btnAdd.Enabled             = false;

                // no suggestions
                _listSuggestions.Items.Clear();
            }
            else
            {
                // adjust dialog
                _lblRepeatedWord.Visible    = false;
                _lblNotInDictionary.Visible = true;
                _btnChange.Text             = _lblChange.Text;
                _btnIgnoreAll.Enabled       = true;
                _btnChange.Enabled          = false;
                _btnChangeAll.Enabled       = false;
                _btnAdd.Enabled             = true;

                // show suggestions
                ShowSuggestions(err.Text);
            }

            // focus to new word
            _txtError.Focus();
            _btnSuggest.Enabled = false;
            AcceptButton        = _btnIgnore;

            // show 'Add' button only if user dictionary is enabled
            _btnAdd.Visible = _spell.UserDictionary.Enabled;

            // ready, fire BadWordDetected event
            BadWordEventArgs e = new BadWordEventArgs(this, _editor.Control, err, _errors);

            _spell.OnBadWordFound(e);

            // ignore error on event-handler request
            if (e.Cancel)
            {
                ErrorIndex++;
            }
        }