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 List <Tuple <DocumentPosition, string> > GetPreviousWords(DocumentPosition caretPosition, List <Tuple <DocumentPosition, string> > result = null) { if (result == null) { result = new List <Tuple <DocumentPosition, string> >(); } DocumentPosition pos = new DocumentPosition(richTextBox.Document); pos.MoveToPosition(caretPosition); pos.MoveToPreviousWordStart(); var text = pos.GetCurrentInlineBox().Text; if (text.Contains("_")) { pos.MoveToPreviousWordStart(); } var previousOfMainCaret = new DocumentPosition(pos); if (previousOfMainCaret != caretPosition) { result.Add(new Tuple <DocumentPosition, string>(previousOfMainCaret, text)); GetPreviousWords(previousOfMainCaret, result); } return(result); //////var word = GetText(previousOfMainCaret, caretPosition);// pos.Get //////return new Tuple<DocumentPosition, string>(previousOfMainCaret, word); }
private Tuple <DocumentPosition, string> GetPreviousWord(RadDocument radDocument, DocumentPosition caretPosition) { DocumentPosition pos = new DocumentPosition(richTextBox.Document); pos.MoveToPosition(caretPosition); pos.MoveToPreviousWordStart(); radDocument.Selection.SetSelectionStart(pos); radDocument.Selection.AddSelectionEnd(caretPosition); // var text = pos.GetCurrentInlineBox().Text; string text = radDocument.Selection.GetSelectedText();; // pos.GetCurrentWord(); if (text.Contains("_")) { pos.MoveToPreviousWordStart(); radDocument.Selection.SetSelectionStart(pos); radDocument.Selection.AddSelectionEnd(caretPosition); text = radDocument.Selection.GetSelectedText(); } if (text != null && text != "" && text != ".") { if (text.EndsWith(".")) { text = text.Substring(0, text.Length - 1); } } var previousOfMainCaret = new DocumentPosition(pos); radDocument.Selection.Clear(); return(new Tuple <DocumentPosition, string>(previousOfMainCaret, text)); //////var word = GetText(previousOfMainCaret, caretPosition);// pos.Get //////return new Tuple<DocumentPosition, string>(previousOfMainCaret, word); }
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 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(); } } }
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(); } } }
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 ExpressionEditor_KeyUp(object sender, KeyEventArgs e) { //bool showPropertyMethodList = false; //bool rightctrlSpace = false; bool ctrlSpace = false; bool dot = false; if (e.Key == Key.Space && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))) { ctrlSpace = true; } if (e.Key == Key.OemPeriod && (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))) { dot = true; } if (dot || ctrlSpace) { FormulaAutoCompleteKeyType keyType; string theWord = ""; if (ctrlSpace && ExpressionEditor.ExpressionText == "") { keyType = FormulaAutoCompleteKeyType.EmptyLeftCtrlSpace; } else { DocumentPosition pos = new DocumentPosition(richTextBox.Document); pos.MoveToPosition(richTextBox.Document.CaretPosition); pos.MoveToPrevious(); var str = (richTextBox.Document.CaretPosition.GetCurrentWord()); if (str == Environment.NewLine) { theWord = GetPreviousWord(richTextBox.Document, GetPreviousWord(richTextBox.Document, richTextBox.Document.CaretPosition).Item1).Item2; } else { theWord = GetPreviousWord(richTextBox.Document, richTextBox.Document.CaretPosition).Item2; } if (dot) { keyType = FormulaAutoCompleteKeyType.DotOnly; } else { //leftctrlSpace if (pos.GetCurrentWord() == ".") { keyType = FormulaAutoCompleteKeyType.AfterDotLeftCtrlSpace; } else { keyType = FormulaAutoCompleteKeyType.InTextLeftControlSpace; } } } ShowAutoComplete(keyType, theWord); } else if (e.Key != Key.LeftCtrl && e.Key != Key.LeftAlt) { //myPopup.IsOpen = false; } }
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) }); }