示例#1
0
        private void btnIgnore_Click(object sender, EventArgs e)
        {
            if (LanguageFeature.SupportsFeature(this.textView.Language, "Spellcheck.Check") == false)
            {
                return;
            }

            this.selectionStart = this.textView.SelectionStart + this.textView.SelectionLength;
            this.GotoNext();
        }
示例#2
0
        private void btnAddWord_Click(object sender, EventArgs e)
        {
            if (LanguageFeature.SupportsFeature(this.textView.Language, "Spellcheck.AddWord"))
            {
                if (String.IsNullOrEmpty(this.textView.SelectedText))
                {
                    Bridge.Get().Error(Strings.Spellchecking_CannotAddEmptyWord, Strings.Spellchecking_Title);
                    return;
                }

                var state = new LFSValueAsync <string>(this.textView.SelectedText);
                state.Done += state_Done;
                LanguageFeature.FeaturePerform(this.textView.Language, "Spellcheck.AddWord", state);
            }
        }
示例#3
0
        private void btnReplace_Click(object sender, EventArgs e)
        {
            if (LanguageFeature.SupportsFeature(this.textView.Language, "Spellcheck.Check") == false)
            {
                return;
            }

            var diff = this.tbxReplaceWith.Text.Length - this.textView.SelectionLength;

            Tag = new object();
            this.textView.SelectedText = this.tbxReplaceWith.Text;
            Tag = null;

            this.selectionStart += diff;

            this.GotoNext();
        }
示例#4
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            if (this.textView.TextLength == 0)
            {
                Bridge.Get().Error(Strings.Spellchecking_TextControlIsEmpty, Strings.Spellchecking_Title);
                return;
            }

            if (this.language == null)
            {
                Bridge.Get().Error(@"There was no language for the cultureinfo, so cannot spellcheck for it.", @"Internal error");
                Close();
                return;
            }

            if (LanguageFeature.SupportsFeature(this.language, "Spellcheck.Check") == false && LanguageFeature.SupportsFeature(this.language, "Synonym") == false)
            {
                var question = String.Format(Strings.Spellchecking_LexiconsAreNotInstalled_AskDownload, this.language.Name);

                if (Bridge.Get <IBDialogs>().AskYesNo(question, Strings.Spellchecking_Title))
                {
                    this.ShowGetAddtionalSpellcheckResources();

                    if (Bridge.Get <IBDialogs>().AskYesNo(Strings.Languages_Download_RestartRequired, Strings.Spellchecking_Title))
                    {
                        Application.Restart();
                    }
                }

                Close();
                return;
            }

            this.selectionStart = this.textView.SelectionStart;

            this.cbxEnableInlineSpellcheck.Checked    = SpellcheckSettings.InlineEnabled;
            this.cbxIgnoreAllCaps.Checked             = SpellcheckSettings.IgnoreAllCaps;
            this.cbxIgnoreWordsWithNumbers.Checked    = SpellcheckSettings.IgnoreWithNumbers;
            this.cbxIgnoreWordsWithAsianChars.Checked = SpellcheckSettings.IgnoreWithAsian;
            this.tbxLinesWithPrefix.Text = SpellcheckSettings.LinesWithPrefix;

            this.GotoNext();
        }
示例#5
0
        private void btnIgnoreWord_Click(object sender, EventArgs e)
        {
            if (LanguageFeature.SupportsFeature(this.textView.Language, "Spellcheck.Check") == false)
            {
                return;
            }

            foreach (var ignoredWord in SpellcheckSettings.IgnoredWords)
            {
                if (ignoredWord.Equals(this.textView.SelectedText, StringComparison.CurrentCultureIgnoreCase) == false)
                {
                    SpellcheckSettings.AddIgnoreWord(this.textView.SelectedText);
                }
            }

            this.selectionStart = this.textView.SelectionStart + this.textView.SelectionLength;
            this.GotoNext();
        }
示例#6
0
        private bool GotoNext()
        {
            if (LanguageFeature.SupportsFeature(this.textView.Language, "Spellcheck.Check") == false)
            {
                return(false);
            }

            var searchFrom = Math.Max(0, this.selectionStart);

            var regex = new Regex(InvariantStrings.REGEX_WORD_BARRIER_STRICT + "([\\w'-]+?)" + InvariantStrings.REGEX_WORD_BARRIER_STRICT);

            var text = this.textView.TextGet();

            while (true)
            {
                var match = regex.Match(text, searchFrom);

                if (match.Success == false)
                {
                    break;
                }

                var value = match.Groups[2];

                // Check for unwanted match characters, and abort if so is instructed.
                if (SpellcheckSettings.CheckIfWordIsValid(value.Value, this.textView.GetLineText(this.textView.GetLineFromCharIndex(searchFrom))) == false)
                {
                    searchFrom += value.Length;
                    continue;
                }

                var spellcheckValid = false;
                foreach (var check in LanguageFeature.FeatureFetchMultiple <bool>(this.textView.Language, "Spellcheck.Check", new LFSString(value.Value)))
                {
                    spellcheckValid = check;
                    if (spellcheckValid)
                    {
                        break;
                    }
                }

                if (spellcheckValid == false)
                {
                    this.lbxSuggestions.Items.Clear();

                    Tag = new object();

                    this.textView.SelectionStart  = this.selectionStart = value.Index;
                    this.textView.SelectionLength = this.selectionLength = value.Length;
                    this.textView.ScrollToCaret();

                    Tag = null;

                    foreach (string suggestion in LanguageFeature.FeatureFetchMultiple <string>(this.textView.Language, "Spellcheck.Suggest", new LFSString(value.Value)))
                    {
                        this.lbxSuggestions.Items.Add(suggestion);
                    }

                    if (this.lbxSuggestions.Items.Count == 0)
                    {
                        this.tbxReplaceWith.Clear();
                        this.tbxReplaceWith.Focus();
                    }
                    else
                    {
                        this.lbxSuggestions.SelectedIndex = 0;
                    }

                    return(true);
                }

                searchFrom += value.Length;
            }

            Bridge.Get().Info(Strings.Spellchecking_EndOfText_Success, Strings.Spellchecking_Title);
            return(false);
        }