// Token: 0x060085BD RID: 34237 RVA: 0x0024AA08 File Offset: 0x00248C08 private ITextPointer GetDropPosition(Visual target, Point point) { Invariant.Assert(target != null); Invariant.Assert(this._textEditor.TextView.IsValid); if (target != this._textEditor.TextView.RenderScope && target != null && this._textEditor.TextView.RenderScope.IsAncestorOf(target)) { GeneralTransform generalTransform = target.TransformToAncestor(this._textEditor.TextView.RenderScope); generalTransform.TryTransform(point, out point); } ITextPointer textPointer = this.TextView.GetTextPositionFromPoint(point, true); if (textPointer != null) { textPointer = textPointer.GetInsertionPosition(textPointer.LogicalDirection); if (this._textEditor.AcceptsRichContent) { TextSegment normalizedLineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, textPointer); if (!normalizedLineRange.IsNull && textPointer.CompareTo(normalizedLineRange.End) < 0 && !TextPointerBase.IsAtWordBoundary(textPointer, LogicalDirection.Forward) && this._dragSourceTextRange != null && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.Start, LogicalDirection.Forward) && TextPointerBase.IsAtWordBoundary(this._dragSourceTextRange.End, LogicalDirection.Forward)) { TextSegment wordRange = TextPointerBase.GetWordRange(textPointer); string textInternal = TextRangeBase.GetTextInternal(wordRange.Start, wordRange.End); int offsetToPosition = wordRange.Start.GetOffsetToPosition(textPointer); textPointer = ((offsetToPosition < textInternal.Length / 2) ? wordRange.Start : wordRange.End); } } } return(textPointer); }
// Token: 0x06003836 RID: 14390 RVA: 0x000FAA28 File Offset: 0x000F8C28 private static void OnResetFormat(object target, ExecutedRoutedEventArgs args) { TextEditor textEditor = TextEditor._GetTextEditor(target); if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection.Start is TextPointer)) { return; } TextEditorTyping._FlushPendingInputItems(textEditor); using (textEditor.Selection.DeclareChangeBlock()) { TextPointer start = (TextPointer)textEditor.Selection.Start; TextPointer end = (TextPointer)textEditor.Selection.End; if (textEditor.Selection.IsEmpty) { TextSegment autoWord = TextRangeBase.GetAutoWord(textEditor.Selection); if (autoWord.IsNull) { ((TextSelection)textEditor.Selection).ClearSpringloadFormatting(); return; } start = (TextPointer)autoWord.Start; end = (TextPointer)autoWord.End; } TextEditorSelection._ClearSuggestedX(textEditor); TextRangeEdit.CharacterResetFormatting(start, end); } }
internal static void _OnApplyProperty(TextEditor This, DependencyProperty formattingProperty, object propertyValue, bool applyToParagraphs, PropertyValueAction propertyValueAction) { if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection)) { return; } // Check whether the property is known if (!TextSchema.IsParagraphProperty(formattingProperty) && !TextSchema.IsCharacterProperty(formattingProperty)) { Invariant.Assert(false, "The property '" + formattingProperty.Name + "' is unknown to TextEditor"); return; } TextSelection selection = (TextSelection)This.Selection; if (TextSchema.IsStructuralCharacterProperty(formattingProperty) && !TextRangeEdit.CanApplyStructuralInlineProperty(selection.Start, selection.End)) { // Ignore structural commands fires in inappropriate context. return; } TextEditorTyping._FlushPendingInputItems(This); // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Break merged typing sequence TextEditorTyping._BreakTypingSequence(This); // Apply property selection.ApplyPropertyValue(formattingProperty, propertyValue, applyToParagraphs, propertyValueAction); }
/// <summary> /// Cut worker. /// </summary> internal static void Cut(TextEditor This, bool userInitiated) { if (userInitiated) { // Fail silently if the app explicitly denies clipboard access. try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); } catch (SecurityException) { return; } } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection != null && !This.Selection.IsEmpty) { // Copy content onto the clipboard // Note: _CreateDataObject raises a public event which might throw a recoverable exception. DataObject dataObject = TextEditorCopyPaste._CreateDataObject(This, /*isDragDrop:*/ false); if (dataObject != null) { try { // The copy command was not terminated by application // One of reason should be the opening fail of Clipboard by the destroyed hwnd. Clipboard.CriticalSetDataObject(dataObject, true); } catch (ExternalException) when(!FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure) { // Clipboard is failed to set the data object. return; } // Delete selected content using (This.Selection.DeclareChangeBlock()) { // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); This.Selection.Text = String.Empty; // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods // Sets the caret in response to a mouse down or mouse up event. internal static void SetCaretPositionOnMouseEvent(TextEditor This, Point mouseDownPoint, MouseButton changedButton, int clickCount) { // Get the character position of the mouse event. ITextPointer cursorPosition = This.TextView.GetTextPositionFromPoint(mouseDownPoint, /*snapToText:*/ true); if (cursorPosition == null) { // Cursor is between pages in a document viewer. MoveFocusToUiScope(This); return; } // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Discard typing undo unit merging TextEditorTyping._BreakTypingSequence(This); // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } // Clear flags for forcing word and paragraphexpansion // (which should be true only in case of doubleClick+drag or tripleClick+drag) This._forceWordSelection = false; This._forceParagraphSelection = false; if (changedButton == MouseButton.Right || clickCount == 1) { // If mouse clicked within selection enter dragging mode, otherwise start building a selection if (changedButton != MouseButton.Left || !This._dragDropProcess.SourceOnMouseLeftButtonDown(mouseDownPoint)) { // Mouse down happend outside of current selection // so position the selection at the clicked location. This.Selection.SetSelectionByMouse(cursorPosition, mouseDownPoint); } } else if (clickCount == 2 && (Keyboard.Modifiers & ModifierKeys.Shift) == 0 && This.Selection.IsEmpty) { // Double click only works when Shift is not pressed This._forceWordSelection = true; This._forceParagraphSelection = false; This.Selection.SelectWord(cursorPosition); } else if (clickCount == 3 && (Keyboard.Modifiers & ModifierKeys.Shift) == 0) { // Triple click only works when Shift is not pressed if (This.AcceptsRichContent) { This._forceParagraphSelection = true; This._forceWordSelection = false; This.Selection.SelectParagraph(cursorPosition); } } }
// Common handler for all list editing commands private static void OnListCommand(object target, ExecutedRoutedEventArgs args) { TextEditor This = TextEditor._GetTextEditor(target); if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(This); if (!TextRangeEditLists.IsListOperationApplicable((TextSelection)This.Selection)) { return; } using (This.Selection.DeclareChangeBlock()) { TextSelection thisSelection = (TextSelection)This.Selection; ListItem parentListItem = TextPointerBase.GetListItem(thisSelection.Start); ListItem immediateListItem = TextPointerBase.GetImmediateListItem(thisSelection.Start); List list = parentListItem == null ? null : (List)parentListItem.Parent; // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Execute the command if (args.Command == EditingCommands.ToggleBullets) { ToggleBullets(thisSelection, parentListItem, immediateListItem, list); } else if (args.Command == EditingCommands.ToggleNumbering) { ToggleNumbering(thisSelection, parentListItem, immediateListItem, list); } else if (args.Command == EditingCommands.RemoveListMarkers) { TextRangeEditLists.ConvertListItemsToParagraphs(thisSelection); } else if (args.Command == EditingCommands.IncreaseIndentation) { IncreaseIndentation(thisSelection, parentListItem, immediateListItem); } else if (args.Command == EditingCommands.DecreaseIndentation) { DecreaseIndentation(thisSelection, parentListItem, immediateListItem); } else { Invariant.Assert(false); } } }
// Token: 0x06003874 RID: 14452 RVA: 0x000FCCBC File Offset: 0x000FAEBC private static void OnListCommand(object target, ExecutedRoutedEventArgs args) { TextEditor textEditor = TextEditor._GetTextEditor(target); if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(textEditor); if (!TextRangeEditLists.IsListOperationApplicable((TextSelection)textEditor.Selection)) { return; } using (textEditor.Selection.DeclareChangeBlock()) { TextSelection textSelection = (TextSelection)textEditor.Selection; ListItem listItem = TextPointerBase.GetListItem(textSelection.Start); ListItem immediateListItem = TextPointerBase.GetImmediateListItem(textSelection.Start); List list = (listItem == null) ? null : ((List)listItem.Parent); TextEditorSelection._ClearSuggestedX(textEditor); if (args.Command == EditingCommands.ToggleBullets) { TextEditorLists.ToggleBullets(textSelection, listItem, immediateListItem, list); } else if (args.Command == EditingCommands.ToggleNumbering) { TextEditorLists.ToggleNumbering(textSelection, listItem, immediateListItem, list); } else if (args.Command == EditingCommands.RemoveListMarkers) { TextRangeEditLists.ConvertListItemsToParagraphs(textSelection); } else if (args.Command == EditingCommands.IncreaseIndentation) { TextEditorLists.IncreaseIndentation(textSelection, listItem, immediateListItem); } else if (args.Command == EditingCommands.DecreaseIndentation) { TextEditorLists.DecreaseIndentation(textSelection, listItem, immediateListItem); } else { Invariant.Assert(false); } } }
internal static void Cut(TextEditor This, bool userInitiated) { if (userInitiated) { try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); goto IL_1E; } catch (SecurityException) { return; } } if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } IL_1E: TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection != null && !This.Selection.IsEmpty) { DataObject dataObject = TextEditorCopyPaste._CreateDataObject(This, false); if (dataObject != null) { try { Clipboard.CriticalSetDataObject(dataObject, true); } catch (ExternalException obj) when(!FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure) { return; } using (This.Selection.DeclareChangeBlock()) { TextEditorSelection._ClearSuggestedX(This); This.Selection.Text = string.Empty; if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } } }
/// <summary> /// Calculates a TextPointer indended for dropping the text. /// </summary> /// <param name="target"></param> /// <param name="point"></param> /// <returns> /// ITextPointer intended for dropping the selected text. /// Adjusts the dropping point to a word boundary (beginning of word) /// in case if source range contains whole words. /// The position returned is oriented towards a character /// under the mouse pointer. /// </returns> private ITextPointer GetDropPosition(Visual target, Point point) { Invariant.Assert(target != null); Invariant.Assert(_textEditor.TextView.IsValid); // caller must guarantee this. // Convert point to RenderScope if (target != _textEditor.TextView.RenderScope && target != null && (_textEditor.TextView.RenderScope).IsAncestorOf(target)) { GeneralTransform transform = target.TransformToAncestor(_textEditor.TextView.RenderScope); transform.TryTransform(point, out point); } ITextPointer dropPosition = this.TextView.GetTextPositionFromPoint(point, /*snapToText:*/ true); // For rich text content we adjust drop position to word boundary if (dropPosition != null) { // Normalize drop position dropPosition = dropPosition.GetInsertionPosition(dropPosition.LogicalDirection); if (_textEditor.AcceptsRichContent) { TextSegment lineRange = TextEditorSelection.GetNormalizedLineRange(this.TextView, dropPosition); if (!lineRange.IsNull && // The drop position must be before of end of line dropPosition.CompareTo(lineRange.End) < 0 && // We check if we are not at word boundary already: !TextPointerBase.IsAtWordBoundary(dropPosition, /*insideWordDirection:*/ LogicalDirection.Forward) && // We do not do it if the source range was not on word boundaries from both ends _dragSourceTextRange != null && // TextPointerBase.IsAtWordBoundary(_dragSourceTextRange.Start, LogicalDirection.Forward) && // TextPointerBase.IsAtWordBoundary(_dragSourceTextRange.End, LogicalDirection.Forward)) { // Move to word boundary. Select closest one to a dropPosition. TextSegment wordSegment = TextPointerBase.GetWordRange(dropPosition); string wordText = TextRangeBase.GetTextInternal(wordSegment.Start, wordSegment.End); int indexInWord = wordSegment.Start.GetOffsetToPosition(dropPosition); dropPosition = (indexInWord < (wordText.Length / 2)) ? wordSegment.Start : wordSegment.End; } } } return(dropPosition); }
// Token: 0x060038DF RID: 14559 RVA: 0x001011BC File Offset: 0x000FF3BC private static void OnTableCommand(object target, ExecutedRoutedEventArgs args) { TextEditor textEditor = TextEditor._GetTextEditor(target); if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(textEditor); TextEditorSelection._ClearSuggestedX(textEditor); if (args.Command == EditingCommands.InsertTable) { ((TextSelection)textEditor.Selection).InsertTable(4, 4); return; } if (args.Command == EditingCommands.InsertRows) { ((TextSelection)textEditor.Selection).InsertRows(1); return; } if (args.Command == EditingCommands.InsertColumns) { ((TextSelection)textEditor.Selection).InsertColumns(1); return; } if (args.Command == EditingCommands.DeleteRows) { ((TextSelection)textEditor.Selection).DeleteRows(); return; } if (args.Command == EditingCommands.DeleteColumns) { ((TextSelection)textEditor.Selection).DeleteColumns(); return; } if (args.Command == EditingCommands.MergeCells) { ((TextSelection)textEditor.Selection).MergeCells(); return; } if (args.Command == EditingCommands.SplitCell) { ((TextSelection)textEditor.Selection).SplitCell(1000, 1000); } }
internal static void Paste(TextEditor This) { if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } if (This.Selection.IsTableCellRange) { return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); IDataObject dataObject; try { dataObject = Clipboard.GetDataObject(); } catch (ExternalException) { dataObject = null; } bool coversEntireContent = This.Selection.CoversEntireContent; if (dataObject != null) { using (This.Selection.DeclareChangeBlock()) { TextEditorSelection._ClearSuggestedX(This); if (TextEditorCopyPaste._DoPaste(This, dataObject, false)) { This.Selection.SetCaretToPosition(This.Selection.End, LogicalDirection.Backward, false, true); if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } } if (coversEntireContent) { This.Selection.ValidateLayout(); } }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods private static void OnTableCommand(object target, ExecutedRoutedEventArgs args) { TextEditor This = TextEditor._GetTextEditor(target); if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(This); // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Execute the command if (args.Command == EditingCommands.InsertTable) { ((TextSelection)This.Selection).InsertTable(/*rowCount:*/ 4, /*columnCount:*/ 4); } else if (args.Command == EditingCommands.InsertRows) { ((TextSelection)This.Selection).InsertRows(+1); } else if (args.Command == EditingCommands.InsertColumns) { ((TextSelection)This.Selection).InsertColumns(+1); } else if (args.Command == EditingCommands.DeleteRows) { ((TextSelection)This.Selection).DeleteRows(); } else if (args.Command == EditingCommands.DeleteColumns) { ((TextSelection)This.Selection).DeleteColumns(); } else if (args.Command == EditingCommands.MergeCells) { ((TextSelection)This.Selection).MergeCells(); } else if (args.Command == EditingCommands.SplitCell) { ((TextSelection)This.Selection).SplitCell(1000, 1000); // Split all ways to possible maximum } }
// Token: 0x0600387D RID: 14461 RVA: 0x000FD1BC File Offset: 0x000FB3BC internal static void SetCaretPositionOnMouseEvent(TextEditor This, Point mouseDownPoint, MouseButton changedButton, int clickCount) { ITextPointer textPositionFromPoint = This.TextView.GetTextPositionFromPoint(mouseDownPoint, true); if (textPositionFromPoint == null) { TextEditorMouse.MoveFocusToUiScope(This); return; } TextEditorSelection._ClearSuggestedX(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } This._forceWordSelection = false; This._forceParagraphSelection = false; if (changedButton == MouseButton.Right || clickCount == 1) { if (changedButton != MouseButton.Left || !This._dragDropProcess.SourceOnMouseLeftButtonDown(mouseDownPoint)) { This.Selection.SetSelectionByMouse(textPositionFromPoint, mouseDownPoint); return; } } else { if (clickCount == 2 && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.None && This.Selection.IsEmpty) { This._forceWordSelection = true; This._forceParagraphSelection = false; This.Selection.SelectWord(textPositionFromPoint); return; } if (clickCount == 3 && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.None && This.AcceptsRichContent) { This._forceParagraphSelection = true; This._forceWordSelection = false; This.Selection.SelectParagraph(textPositionFromPoint); } } }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods // ................................................................ // // Editing Commands: Character Editing // // ................................................................ private static void OnResetFormat(object target, ExecutedRoutedEventArgs args) { TextEditor This = TextEditor._GetTextEditor(target); if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection.Start is TextPointer)) { return; } TextEditorTyping._FlushPendingInputItems(This); using (This.Selection.DeclareChangeBlock()) { // Positions to clear all inline formatting properties TextPointer startResetFormatPosition = (TextPointer)This.Selection.Start; TextPointer endResetFormatPosition = (TextPointer)This.Selection.End; if (This.Selection.IsEmpty) { TextSegment autoWordRange = TextRangeBase.GetAutoWord(This.Selection); if (autoWordRange.IsNull) { // Clear springloaded formatting ((TextSelection)This.Selection).ClearSpringloadFormatting(); return; } else { // If we have a word, apply reset format to it startResetFormatPosition = (TextPointer)autoWordRange.Start; endResetFormatPosition = (TextPointer)autoWordRange.End; } } // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Clear all inline formattings TextRangeEdit.CharacterResetFormatting(startResetFormatPosition, endResetFormatPosition); } }
// Token: 0x06003835 RID: 14389 RVA: 0x000FA980 File Offset: 0x000F8B80 internal static void _OnApplyProperty(TextEditor This, DependencyProperty formattingProperty, object propertyValue, bool applyToParagraphs, PropertyValueAction propertyValueAction) { if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection)) { return; } if (!TextSchema.IsParagraphProperty(formattingProperty) && !TextSchema.IsCharacterProperty(formattingProperty)) { Invariant.Assert(false, "The property '" + formattingProperty.Name + "' is unknown to TextEditor"); return; } TextSelection textSelection = (TextSelection)This.Selection; if (TextSchema.IsStructuralCharacterProperty(formattingProperty) && !TextRangeEdit.CanApplyStructuralInlineProperty(textSelection.Start, textSelection.End)) { return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorSelection._ClearSuggestedX(This); TextEditorTyping._BreakTypingSequence(This); textSelection.ApplyPropertyValue(formattingProperty, propertyValue, applyToParagraphs, propertyValueAction); }
/// <summary> /// Paste worker. /// </summary> internal static void Paste(TextEditor This) { if (This.Selection.IsTableCellRange) { // We do not support clipboard for table selection so far // Word behavior: When source range is text segment then this segment is pasted // into each table cell overriding its current content. // If source range is table range then it is repeated on target - // cell by cell in circular manner. return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); // Get DataObject from the Clipboard IDataObject dataObject; try { dataObject = Clipboard.GetDataObject(); } catch (ExternalException) { // Clipboard is failed to get the data object. // One of reason should be the opening fail of Clipboard by the destroyed hwnd. dataObject = null; // must re-throw ??? } bool forceLayoutUpdate = This.Selection.CoversEntireContent; if (dataObject != null) { using (This.Selection.DeclareChangeBlock()) { // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // _DoPaste raises a public event -- could raise recoverable exception. if (TextEditorCopyPaste._DoPaste(This, dataObject, /*isDragDrop:*/ false)) { // Collapse selection to the end // Use backward direction to stay oriented towards pasted content This.Selection.SetCaretToPosition(This.Selection.End, LogicalDirection.Backward, /*allowStopAtLineEnd:*/ false, /*allowStopNearSpace:*/ true); // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } // PUBLIC EVENT RAISED HERE AS CHANGEBLOCK CLOSES! } // If we replaced the entire document content, background layout will // kick in. Force it to complete now. if (forceLayoutUpdate) { This.Selection.ValidateLayout(); } }
internal static void Paste(TextEditor This) { // Don't try anything if the caller doesn't have the rights to read from the clipboard... if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } if (This.Selection.IsTableCellRange) { // return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); // Get DataObject from the Clipboard IDataObject dataObject; try { dataObject = Clipboard.GetDataObject(); } catch (ExternalException) { // Clipboard is failed to get the data object. // One of reason should be the opening fail of Clipboard by the destroyed hwnd. dataObject = null; // } bool forceLayoutUpdate = This.Selection.CoversEntireContent; if (dataObject != null) { using (This.Selection.DeclareChangeBlock()) { // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // _DoPaste raises a public event -- could raise recoverable exception. if (TextEditorCopyPaste._DoPaste(This, dataObject, /*isDragDrop:*/ false)) { // Collapse selection to the end // Use backward direction to stay oriented towards pasted content This.Selection.SetCaretToPosition(This.Selection.End, LogicalDirection.Backward, /*allowStopAtLineEnd:*/ false, /*allowStopNearSpace:*/ true); // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } // PUBLIC EVENT RAISED HERE AS CHANGEBLOCK CLOSES! } // If we replaced the entire document content, background layout will // kick in. Force it to complete now. if (forceLayoutUpdate) { This.Selection.ValidateLayout(); } }
private void ChangeCase(bool upper) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; // Specifically select an MText object var peo = new PromptEntityOptions(string.Format("\nSelect MText to change to {0}case: ", upper ? "upper" : "lower")); peo.SetRejectMessage("\nObject must be MText."); peo.AddAllowedClass(typeof(MText), false); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { // We only need our MText open for read DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead, false); MText mt = obj as MText; if (mt == null) { return; } // Create a text editor object for the MText TextEditor te = TextEditor.CreateTextEditor(mt); if (te == null) { return; } // Select the entire contents of the MText te.SelectAll(); TextEditorSelection sel = te.Selection; if (sel == null) { return; } // Check whether we can change the selection's // case, and then do so if (sel.CanChangeCase) { if (upper) { sel.ChangeToUppercase(); } else { sel.ChangeToLowercase(); } } // Be sure to save the results from the editor te.Close(TextEditor.ExitStatus.ExitSave); tr.Commit(); } }