예제 #1
0
        private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            editor.Document.Selection.Clear();

            var search       = new DocumentTextSearch(editor.Document);
            var lastPosition = new DocumentPosition(editor.Document);

            bool endOfDocument   = false;
            bool theFirstFinding = true;

            while (!endOfDocument)
            {
                TextRange range;

                range = search.Find("#break#", theFirstFinding ? new DocumentPosition(editor.Document) : lastPosition);

                if (range != null)
                {
                    theFirstFinding = false;
                    lastPosition    = range.EndPosition;

                    editor.Document.Selection.AddSelectionStart(range.StartPosition);
                    editor.Document.Selection.AddSelectionEnd(range.EndPosition);

                    var documentEditor = new RadDocumentEditor(editor.Document);
                    documentEditor.InsertLineBreak();
                }
                else
                {
                    endOfDocument = true;
                }
            }
        }
        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);
            }
        }
예제 #3
0
        private void btnReplaceAll_Click(object sender, RoutedEventArgs e)
        {
            int foundCount = 0;

            this.richTextBox.SuspendUpdateLayout();
            this.Document.BeginUpdate();
            try
            {
                using (DocumentPosition startFindPosition = new DocumentPosition(this.Document.DocumentLayoutBox, true))
                {
                    var found = true;

                    while (found)
                    {
                        DocumentTextSearch textSearch = new DocumentTextSearch(this.Document);
                        TextRange          find       = textSearch.Find(this.GetSearchText(), startFindPosition);

                        found = find != null;

                        if (found)
                        {
                            startFindPosition.MoveToPosition(find.EndPosition);
                            startFindPosition.AnchorToNextFormattingSymbol();

                            //This is needed to update the current style for editing
                            this.Document.CaretPosition.MoveToPosition(find.StartPosition);
                            find.SetSelection(this.Document);
                            if (this.replaceCallback(this.tbReplaceText.Text))
                            {
                                foundCount++;
                            }
                            startFindPosition.RemoveAnchorFromNextFormattingSymbol();
                            startFindPosition.MoveToPosition(this.Document.CaretPosition);
                        }
                    }
                }
            }
            finally
            {
                this.Document.EndUpdate();
                this.richTextBox.ResumeUpdateLayout();
            }

            RadWindow.Alert(new DialogParameters()
            {
                Header  = this.Header,
                Content = string.Format(LocalizationManager.GetString("Documents_FindReplaceDialog_MadeReplacements"), foundCount),
                Owner   = this
            });
        }
        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 Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            editor.Document.Selection.Clear();

            var search = new DocumentTextSearch(editor.Document);
            var lastPosition = new DocumentPosition(editor.Document);

            bool endOfDocument = false;
            bool theFirstFinding = true;

            while (!endOfDocument)
            {
                TextRange range;

                range = search.Find("#break#", theFirstFinding ? new DocumentPosition(editor.Document) : lastPosition);

                if (range != null)
                {
                    theFirstFinding = false;
                    lastPosition = range.EndPosition;

                    editor.Document.Selection.AddSelectionStart(range.StartPosition);
                    editor.Document.Selection.AddSelectionEnd(range.EndPosition);

                    var documentEditor = new RadDocumentEditor(editor.Document);
                    documentEditor.InsertLineBreak();
                }
                else
                {
                    endOfDocument = true;
                }
            }
        }
예제 #6
0
        public void FindNext(DocumentPosition fromPosition)
        {
            this.tbFindText.Focus();
            this.tbFindText.SelectAll();

            if (this.selectReplaceStateService.IsLastFoundSuccessful)
            {
                this.selectReplaceStateService.UnsubscribeFromDocumentEvents();
                this.selectReplaceStateService.SubscribeForDocumentEvents();
            }

            if (this.initialFindPosition == null)
            {
                this.initialFindPosition = new DocumentPosition(fromPosition);
            }

            DocumentTextSearch textSearch = new DocumentTextSearch(this.Document);
            TextRange          find       = textSearch.Find(this.GetSearchText(), fromPosition);

            if (find != null)
            {
                if (find.StartPosition >= this.initialFindPosition && !this.passedThroughEnd ||
                    find.StartPosition < this.initialFindPosition && this.passedThroughEnd)
                {
                    this.selectReplaceStateService.SelectFoundRange(find);
                    this.richTextBox.ActiveEditorPresenter.UpdateScrollOffsetFromDocumentPosition(find.StartPosition);
                    this.RepositionDialog(find.StartPosition);
                }
                else
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        RadWindow.Alert(new DialogParameters()
                        {
                            Header  = this.Header,
                            Content = LocalizationManager.GetString("Documents_FindReplaceDialog_FinishedSearching")
                        });
                    }));
                    this.ResetFindDialog();
                    this.passedThroughEnd = false;
                    this.Document.Selection.Clear();
                }
            }
            else
            {
                if (!passedThroughEnd)
                {
                    passedThroughEnd = true;
                    this.FindNext(new DocumentPosition(this.Document));
                }
                else
                {
                    string content;
                    if (this.selectReplaceStateService.IsLastFoundSuccessful)
                    {
                        content = LocalizationManager.GetString("Documents_FindReplaceDialog_FinishedSearching");
                    }
                    else
                    {
                        content = string.Format(LocalizationManager.GetString("Documents_FindReplaceDialog_SearchedTextNotFound"), this.tbFindText.Text);
                    }
                    Dispatcher.BeginInvoke(new Action(() => RadWindow.Alert(new DialogParameters()
                    {
                        Header  = this.Header,
                        Content = content
                    })));
                    this.Document.Selection.Clear();
                    this.ResetFindDialog();
                }
            }
        }
예제 #7
0
        public void FindNext(DocumentPosition fromPosition)
        {
            this.tbFindText.Focus();
            this.tbFindText.SelectAll();

            if (this.selectReplaceStateService.IsLastFoundSuccessful)
            {
                this.selectReplaceStateService.UnsubscribeFromDocumentEvents();
                this.selectReplaceStateService.SubscribeForDocumentEvents();
            }

            if (this.initialFindPosition == null)
            {
                this.initialFindPosition = new DocumentPosition(fromPosition);
            }

            DocumentTextSearch textSearch = new DocumentTextSearch(this.Document);
            TextRange find = textSearch.Find(this.GetSearchText(), fromPosition);

            if (find != null)
            {
                if (find.StartPosition >= this.initialFindPosition && !this.passedThroughEnd
                    || find.StartPosition < this.initialFindPosition && this.passedThroughEnd)
                {
                    this.selectReplaceStateService.SelectFoundRange(find);
                    this.richTextBox.ActiveEditorPresenter.UpdateScrollOffsetFromDocumentPosition(find.StartPosition);
                    this.RepositionDialog(find.StartPosition);
                }
                else
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        RadWindow.Alert(new DialogParameters()
                        {
                            Header = this.Header,
                            Content = LocalizationManager.GetString("Documents_FindReplaceDialog_FinishedSearching")
                        });
                    }));
                    this.ResetFindDialog();
                    this.passedThroughEnd = false;
                    this.Document.Selection.Clear();
                }
            }
            else
            {
                if (!passedThroughEnd)
                {
                    passedThroughEnd = true;
                    this.FindNext(new DocumentPosition(this.Document));
                }
                else
                {
                    string content;
                    if (this.selectReplaceStateService.IsLastFoundSuccessful)
                    {
                        content = LocalizationManager.GetString("Documents_FindReplaceDialog_FinishedSearching");
                    }
                    else
                    {
                        content = string.Format(LocalizationManager.GetString("Documents_FindReplaceDialog_SearchedTextNotFound"), this.tbFindText.Text);
                    }
                    Dispatcher.BeginInvoke(new Action(() => RadWindow.Alert(new DialogParameters()
                    {
                        Header = this.Header,
                        Content = content
                    })));
                    this.Document.Selection.Clear();
                    this.ResetFindDialog();
                }
            }
        }
예제 #8
0
        private void btnReplaceAll_Click(object sender, RoutedEventArgs e)
        {
            int foundCount = 0;

            this.richTextBox.SuspendUpdateLayout();
            this.Document.BeginUpdate();
            try
            {
                using (DocumentPosition startFindPosition = new DocumentPosition(this.Document.DocumentLayoutBox, true))
                {
                    var found = true;

                    while (found)
                    {
                        DocumentTextSearch textSearch = new DocumentTextSearch(this.Document);
                        TextRange find = textSearch.Find(this.GetSearchText(), startFindPosition);

                        found = find != null;

                        if (found)
                        {
                            startFindPosition.MoveToPosition(find.EndPosition);
                            startFindPosition.AnchorToNextFormattingSymbol();

                            //This is needed to update the current style for editing
                            this.Document.CaretPosition.MoveToPosition(find.StartPosition);
                            find.SetSelection(this.Document);
                            if (this.replaceCallback(this.tbReplaceText.Text))
                            {
                                foundCount++;
                            }
                            startFindPosition.RemoveAnchorFromNextFormattingSymbol();
                        }
                    }
                }
            }
            finally
            {
                this.Document.EndUpdate();
                this.richTextBox.ResumeUpdateLayout();
            }

            RadWindow.Alert(new DialogParameters()
            {
                Header = this.Header,
                Content = string.Format(LocalizationManager.GetString("Documents_FindReplaceDialog_MadeReplacements"), foundCount)
            });
        }