/// <summary> /// Copy worker. /// </summary> internal static void Copy(TextEditor This, bool userInitiated) { TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection != null && !This.Selection.IsEmpty) { // 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; } } } // Do not clear springload formatting }
/// <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(); } } } } }
/// <summary> /// Copy worker. /// </summary> internal static void Copy(TextEditor This, bool userInitiated) { if (userInitiated) { // Fail silently if the app explicitly denies clipboard access. try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); } catch (SecurityException) { return; } } else if (!SecurityHelper.CallerHasAllClipboardPermission()) { // Fail silently if we don't have clipboard permission. return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection != null && !This.Selection.IsEmpty) { // 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; } } } // Do not clear springload formatting }
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(); } } } } }
internal static void Copy(TextEditor This, bool userInitiated) { if (userInitiated) { try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); goto IL_1B; } catch (SecurityException) { return; } } if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } IL_1B: 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) { } } } }