private void _btnBatch_Click(object sender, RoutedEventArgs e)
        {
            // check a word
            foreach (string word in "yes;no;yesno;do;don't;ain't;aint".Split(';'))
            {
                WriteLine("CheckWord(\"{0}\") = {1}", word, _c1SpellChecker.CheckWord(word));
            }

            // check some text
            var someText = "this text comtains two errrors.";
            var errors   = _c1SpellChecker.CheckText(someText);

            WriteLine("CheckText(\"{0}\") =", someText);
            foreach (var error in errors)
            {
                WriteLine("\t{0}, {1}-{2}", error.Text, error.Start, error.Length);
                foreach (string suggestion in _c1SpellChecker.GetSuggestions(error.Text, 1000))
                {
                    WriteLine("\t\t{0}?", suggestion);
                }
            }

            // get suggestions
            var badWord = "traim";

            WriteLine("GetSuggestions(\"{0}\")", badWord);
            foreach (string suggestion in _c1SpellChecker.GetSuggestions(badWord, 1000))
            {
                WriteLine("\t{0}?", suggestion);
            }
        }
Esempio n. 2
0
 // spell-check a Run object, add errors to list
 void PerformSpellCheck(Run run)
 {
     foreach (var error in _spell.CheckText(run.Text))
     {
         var errorRange = new TextRange(
             run.ContentStart.GetPositionAtOffset(error.Start),
             run.ContentStart.GetPositionAtOffset(error.Start + error.Length));
         _errorRanges.Add(errorRange);
     }
 }
Esempio n. 3
0
        //------------------------------------------------------------------------
        #region ** object model

        /// <summary>
        /// Initializes the dialog to use the given parameters.
        /// </summary>
        /// <param name="spell"><see cref="C1SpellChecker"/> to use for spelling.</param>
        /// <param name="editor"><see cref="ISpellCheckableEditor"/> that contains the text to spell-check.</param>
        /// <param name="errors"><see cref="CharRangeList"/> that contains the initial error list.</param>
        public void Initialize(C1SpellChecker spell, ISpellCheckableEditor editor, CharRangeList errors)
        {
            _spell  = spell;
            _editor = editor;
            _errors = errors;
            if (_errors == null)
            {
                _errors = _spell.CheckText(_editor.Text);
            }
            _errorCount += _errors.Count;
        }
        //------------------------------------------------------------------------
        #region ** object model

        /// <summary>
        /// Initializes the dialog to use the given parameters.
        /// </summary>
        /// <param name="spell"><see cref="C1SpellChecker"/> to use for spelling.</param>
        /// <param name="editor"><see cref="ISpellCheckableEditor"/> that contains the text to spell-check.</param>
        /// <param name="errors"><see cref="CharRangeList"/> that contains the initial error list.</param>
        public void Initialize(C1SpellChecker spell, ISpellCheckableEditor editor, CharRangeList errors)
        {
            // save references to all objects
            _spell  = spell;
            _editor = editor;
            _errors = errors;
            if (_errors == null)
            {
                _errors = _spell.CheckText(_editor.Text);
            }
            _errorCount += _errors.Count;

            // go show the first error
            ErrorIndex = 0;
        }
Esempio n. 5
0
        //------------------------------------------------------------------------
        #region ** object model

        /// <summary>
        /// Initializes the dialog to use the given parameters.
        /// </summary>
        /// <param name="spell"><see cref="C1SpellChecker"/> to use for spelling.</param>
        /// <param name="editor"><see cref="ISpellCheckableEditor"/> that contains the text to spell-check.</param>
        /// <param name="errors"><see cref="CharRangeList"/> that contains the initial error list.</param>
        public void Initialize(C1SpellChecker spell, ISpellCheckableEditor editor, CharRangeList errors)
        {
            // initialize members
            _spell  = spell;
            _editor = editor;
            _errors = errors;

            // initialize 'change all' list
            _changeAll.Clear();
            foreach (string key in _spell.AutoReplaceList.Keys)
            {
                _changeAll[key] = _spell.AutoReplaceList[key];
            }

            // initialize error list
            if (_errors == null)
            {
                _errors = _spell.CheckText(_editor.Text);
            }
            _errorCount += _errors.Count;
        }
Esempio n. 6
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);
        }
        //------------------------------------------------------------------------
        #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);
        }
        /// <summary>
        /// Initializes the dialog to use the given parameters.
        /// </summary>
        /// <param name="spell"><see cref="C1SpellChecker"/> to use for spelling.</param>
        /// <param name="editor"><see cref="ISpellCheckableEditor"/> that contains the text to spell-check.</param>
        /// <param name="errors"><see cref="CharRangeList"/> that contains the initial error list.</param>
        public void Initialize(C1SpellChecker spell, ISpellCheckableEditor editor, CharRangeList errors)
        {
            // save references to all objects
            _spell = spell;
            _editor = editor;
            _errors = errors;
            if (_errors == null)
            {
                _errors = _spell.CheckText(_editor.Text);
            }
            _errorCount += _errors.Count;

            // go show the first error
            ErrorIndex = 0;
        }
Esempio n. 9
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++;
            }
        }