Пример #1
0
        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (suppressUpdate)
            {
                return;
            }

            CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType <CustomRangeStart>().FirstOrDefault();

            if (rangeStart != null)
            {
                CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End;

                DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
                start.MoveToInline(rangeStart);

                DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document);
                end.MoveToInline(rangeEnd);

                DocumentSelection selection = this.radRichTextBox.Document.Selection;// new DocumentSelection(this.radRichTextBox.Document);

                selection.SetSelectionStart(start);
                selection.AddSelectionEnd(end);

                this.radRichTextBox.Insert(this.textBox.Text);
            }
        }
Пример #2
0
        private void UpdateTextBoxText()
        {
            string textInRange;

            CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType<CustomRangeStart>().FirstOrDefault();
            if (rangeStart != null)
            {
                CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End;

                DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
                start.MoveToInline(rangeStart);

                DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document);
                end.MoveToInline(rangeEnd);

                DocumentSelection selection = new DocumentSelection(this.radRichTextBox.Document);

                selection.SetSelectionStart(start);
                selection.AddSelectionEnd(end);

                string text = selection.GetSelectedText();

                textInRange = text;
            }
            else
            {
                textInRange = string.Empty;
            }

            this.suppressUpdate = true;

            this.textBox.Text = textInRange;

            this.suppressUpdate = false;
        }
        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);
            }
        }
        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);                
            }
        }
Пример #5
0
        private void ShowDialog()
        {
            ImageInline imageInline = this.radRichTextBox.Document.EnumerateChildrenOfType<ImageInline>().FirstOrDefault();
            if (imageInline != null)
            {
                DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
                DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document);
                start.MoveToInline(imageInline);
                end.MoveToPosition(start);
                end.MoveToNext();

                this.radRichTextBox.Document.Selection.AddSelectionStart(start);
                this.radRichTextBox.Document.Selection.AddSelectionEnd(end);

                if (this.radRichTextBox.Document.Selection.GetSelectedSingleInline() is ImageInline)
                {
                    this.radRichTextBox.ShowImageEditorDialog();
                }
            }
        }
Пример #6
0
        private void ShowImageEditorDialog()
        {
            ImageInline imageInline = this.radRichTextBox.Document.EnumerateChildrenOfType <ImageInline>().FirstOrDefault();

            if (imageInline != null)
            {
                DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
                DocumentPosition end   = new DocumentPosition(this.radRichTextBox.Document);
                start.MoveToInline(imageInline);
                end.MoveToPosition(start);
                end.MoveToNext();

                this.radRichTextBox.Document.Selection.AddSelectionStart(start);
                this.radRichTextBox.Document.Selection.AddSelectionEnd(end);

                if (this.radRichTextBox.Document.Selection.GetSelectedSingleInline() is ImageInline)
                {
                    this.radRichTextBox.ShowImageEditorDialog();
                }
            }
        }
Пример #7
0
        private void UpdateTextBoxText()
        {
            string textInRange;

            CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType <CustomRangeStart>().FirstOrDefault();

            if (rangeStart != null)
            {
                CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End;

                DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
                start.MoveToInline(rangeStart);

                DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document);
                end.MoveToInline(rangeEnd);

                DocumentSelection selection = new DocumentSelection(this.radRichTextBox.Document);

                selection.SetSelectionStart(start);
                selection.AddSelectionEnd(end);

                string text = selection.GetSelectedText();

                textInRange = text;
            }
            else
            {
                textInRange = string.Empty;
            }

            this.suppressUpdate = true;

            this.textBox.Text = textInRange;

            this.suppressUpdate = false;
        }
Пример #8
0
        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (suppressUpdate)
            {
                return;
            }

            CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType<CustomRangeStart>().FirstOrDefault();
            if (rangeStart != null)
            {
                CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End;

                DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
                start.MoveToInline(rangeStart);

                DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document);
                end.MoveToInline(rangeEnd);

                DocumentSelection selection = this.radRichTextBox.Document.Selection;// new DocumentSelection(this.radRichTextBox.Document);

                selection.SetSelectionStart(start);
                selection.AddSelectionEnd(end);

                this.radRichTextBox.Insert(this.textBox.Text);
            }
        }
        private void ReplaceSemanticRange(RadDocument document, string semanticRangeName, DocumentFragment replacement)
        {
            RecipeRangeStart start = null;
            RecipeRangeEnd end = null;
            foreach (RecipeRangeStart rangeStart in document.GetAnnotationMarkersOfType<RecipeRangeStart>())
            {
                if (rangeStart.Name == semanticRangeName)
                {
                    start = rangeStart;
                    end = (RecipeRangeEnd)rangeStart.End;
                }
            }

            if (start != null && end != null)
            {
                DocumentPosition startPosition = new DocumentPosition(document);
                startPosition.MoveToInline((InlineLayoutBox)start.FirstLayoutBox, 0);
                startPosition.MoveToNext();
                DocumentPosition endPosition = new DocumentPosition(document);
                endPosition.MoveToInline((InlineLayoutBox)end.FirstLayoutBox, 0);

                document.DeleteRange(startPosition, endPosition);

                document.CaretPosition.MoveToInline((InlineLayoutBox)start.FirstLayoutBox, 0);
                document.CaretPosition.MoveToNext();
                document.InsertFragment(replacement);
            }
        }
        private string ExportAnnotationRangeFragment(RadDocument document, string semanticRangeName)
        {
            RecipeRangeStart semanticRangestart = null;
            RecipeRangeEnd semanticRangeEnd = null;
            foreach (RecipeRangeStart rangeStart in document.GetAnnotationMarkersOfType<RecipeRangeStart>())
            {
                if (rangeStart.Name == semanticRangeName)
                {
                    semanticRangestart = rangeStart;
                    semanticRangeEnd = (RecipeRangeEnd)rangeStart.End;
                }
            }

            if (semanticRangestart != null && semanticRangeEnd != null)
            {
                DocumentPosition startPosition = new DocumentPosition(document);
                startPosition.MoveToInline((InlineLayoutBox)semanticRangestart.FirstLayoutBox, 0);

                DocumentPosition endPosition = new DocumentPosition(document);
                endPosition.MoveToInline((InlineLayoutBox)semanticRangeEnd.FirstLayoutBox, 0);

                DocumentSelection selection = new DocumentSelection(document);
                selection.SetSelectionStart(startPosition);
                selection.AddSelectionEnd(endPosition);

                DocumentFragment fragment = new DocumentFragment(selection);
                RadDocument fragmentDocument = fragment.ToDocument();

                HtmlFormatProvider htmlFormatProvider = new HtmlFormatProvider();
                htmlFormatProvider.ExportSettings = new HtmlExportSettings();
                htmlFormatProvider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
                htmlFormatProvider.ExportSettings.StylesExportMode = StylesExportMode.Inline;
                htmlFormatProvider.ExportSettings.StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles;

                return htmlFormatProvider.Export(fragmentDocument);
            }

            return string.Empty;
        }