Ejemplo n.º 1
0
 void _spellChecker_BadWordFound(object sender, BadWordEventArgs e)
 {
     // ignore bad words after selection end
     if (e.BadWord.Start >= _selectionEnd)
     {
         var dlg = e.Dialog as C1SpellDialog;
         dlg.CancelButton.PerformClick();
     }
 }
Ejemplo n.º 2
0
 private void c1SpellChecker1_BadWordFound(object sender, BadWordEventArgs e)
 {
     Console.WriteLine("Bad word found {0}, {1} of {2}", e.BadWord.Text, e.BadWordList.IndexOf(e.BadWord) + 1, e.BadWordList.Count);
     if (e.Dialog != null)
     {
         // show some feedback on the status line
         int index = e.BadWordList.IndexOf(e.BadWord) + 1;
         status.Text = string.Format("Error {0} of {1}: '{2}'", index, e.BadWordList.Count, e.BadWord.Text);
     }
     else
     {
         // prevent control from underlining words that start with a capital
         //if (char.IsUpper(e.BadWord.Text[0]))
         //{
         //    e.Cancel = true;
         //}
     }
 }
        //------------------------------------------------------------------------
        #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);
        }
 void _c1SpellChecker_BadWordFound(object sender, BadWordEventArgs e)
 {
     WriteLine("BadWordFound: \"{0}\" {1}", e.BadWord.Text, e.BadWord.Duplicate ? "(duplicate)" : string.Empty);
 }
 void _c1SpellChecker_BadWordFound(object sender, BadWordEventArgs e)
 {
     WriteLine("BadWordFound: \"{0}\" {1}", e.BadWord.Text, e.BadWord.Duplicate ? "(duplicate)" : string.Empty);
 }
        // 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))
            {
                _txtChangeTo.Text = _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 bad word, new text
            _txtError.Text = err.Text;
            _txtChangeTo.Text = string.Empty;

            // 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
            _txtChangeTo.SelectAll();
            _txtChangeTo.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);
        }
Ejemplo n.º 7
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++;
            }
        }