Esempio n. 1
0
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                SpanLayoutBox spanBox = this.Document.GetLayoutBoxByPosition(e.Location) as SpanLayoutBox;
                this.BuildContextMenu(spanBox).Show(this, e.Location);
            }

            base.OnMouseDown(e);
        }
Esempio n. 2
0
        private void ReplaceCurrentWord(SpanLayoutBox spanBox, string newWord)
        {
            this.Document.CaretPosition.MoveToInline(spanBox, 0);

            DocumentPosition endPosition = new DocumentPosition(this.Document.CaretPosition);

            endPosition.MoveToCurrentWordEnd();

            this.Document.Selection.Clear();
            this.Document.Selection.AddSelectionStart(this.Document.CaretPosition);
            this.Document.Selection.AddSelectionEnd(endPosition);

            this.Insert(newWord);
        }
        private void HighlightOccurrencesInVisibleBoxes(IEnumerable <SpanLayoutBox> spanList)
        {
            if (spanList.Count() == 0)
            {
                return;
            }
            SpanLayoutBox firstBox = spanList.First();
            SpanLayoutBox lastBox  = spanList.Last();

            DocumentPosition searchStart = new DocumentPosition(this.Document);
            DocumentPosition searchEnd   = new DocumentPosition(this.Document);

            searchStart.MoveToInline(firstBox, 0);
            searchEnd.MoveToInline(lastBox, lastBox.PositionsCountInBox - 1);

            DocumentTextSearch textSearch = new DocumentTextSearch(this.Document);

            TextRange textRange = textSearch.Find(word, searchStart, searchEnd);
            int       count     = 0;

            while (textRange != null)
            {
                count++;
                DocumentPosition lineStart = new DocumentPosition(textRange.StartPosition);
                DocumentPosition lineEnd   = new DocumentPosition(lineStart);
                lineEnd.MoveToCurrentLineEnd();
                while (lineEnd < textRange.EndPosition)
                {
                    this.FlushBoxes(lineStart, lineEnd);
                    lineStart.MoveToCurrentLineEnd();
                    lineStart.MoveToNext();
                    lineEnd.MoveToNext();
                    lineEnd.MoveToCurrentLineEnd();
                }
                this.FlushBoxes(lineStart, textRange.EndPosition);

                searchStart.MoveToPosition(textRange.EndPosition);
                if (searchStart >= searchEnd)
                {
                    break;
                }
                textRange = textSearch.Find(word, searchStart, searchEnd);
            }
        }
Esempio n. 4
0
        private RadDropDownMenu BuildContextMenu(SpanLayoutBox spanBox)
        {
            RadDropDownMenu menu = new RadDropDownMenu();
            RadMenuItem     menuItem;

            if (this.Document.Selection.IsEmpty && this.IsSpellCheckingEnabled && spanBox != null)
            {
                this.Document.CaretPosition.MoveToInline(spanBox, 0);

                string spanBoxTextAlphaNumericOnly = String.Concat(spanBox.Text.TakeWhile(c => char.IsLetterOrDigit(c)));

                if (spanBoxTextAlphaNumericOnly.Length > 0 && !this.ControlSpellChecker.SpellChecker.CheckWordIsCorrect(spanBoxTextAlphaNumericOnly))
                {
                    string[] suggestions = (string[])this.ControlSpellChecker.SpellChecker.GetSuggestions(spanBox.Text);

                    if (suggestions.Length <= 0)
                    {
                        menuItem         = new RadMenuItem("(No Spelling Suggestions)");
                        menuItem.Enabled = false;
                        menu.Items.Add(menuItem);
                    }

                    foreach (string suggestion in suggestions)
                    {
                        menuItem        = new RadMenuItem(suggestion);
                        menuItem.Click += (object sender, EventArgs e) => { this.ReplaceCurrentWord(spanBox, (sender as RadMenuItem).Text); };
                        menu.Items.Add(menuItem);
                    }

                    menu.Items.Add(new SeparatorElement());

                    menuItem        = new RadMenuItem("Add to Dictionary");
                    menuItem.Click += (object sender, EventArgs e) => { this.ControlSpellChecker.SpellChecker.AddWord(spanBoxTextAlphaNumericOnly); };
                    menu.Items.Add(menuItem);

                    menu.Items.Add(new SeparatorElement());
                }
            }

            menuItem        = new RadMenuItem("Undo");
            menuItem.Click += (object sender, EventArgs e) => { this.Undo(); };
            menu.Items.Add(menuItem);

            menu.Items.Add(new SeparatorElement());

            menuItem        = new RadMenuItem("Cut");
            menuItem.Click += (object sender, EventArgs e) => { this.Cut(); };
            menu.Items.Add(menuItem);

            menuItem        = new RadMenuItem("Copy");
            menuItem.Click += (object sender, EventArgs e) => { this.Copy(); };
            menu.Items.Add(menuItem);

            menuItem        = new RadMenuItem("Paste");
            menuItem.Click += (object sender, EventArgs e) => { this.Paste(); };

            menu.Items.Add(menuItem);

            menuItem        = new RadMenuItem("Delete");
            menuItem.Click += (object sender, EventArgs e) => { this.Delete(false); };
            menu.Items.Add(menuItem);

            menu.Items.Add(new SeparatorElement());

            menuItem        = new RadMenuItem("Select All");
            menuItem.Click += (object sender, EventArgs e) => { this.Document.Selection.SelectAll(); };
            menu.Items.Add(menuItem);

            return(menu);
        }