Skip to content

Conversation

JeremyKuhne
Copy link
Member

@JeremyKuhne JeremyKuhne commented Feb 28, 2025

Adds a flush helper (this is a public API in WPF). Tweaks some code in WinFormsOleServices for better clarity and error state handling.

Also adds a helper to check if a given object is on the clipboard.

Microsoft Reviewers: Open in CodeFlow

Adds a flush helper (this is a public API in WPF). Tweaks some code in WinFormsOleServices for better clarity and error state handling.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR adds two new helper APIs to improve clipboard data handling: a new Flush method that flushes clipboard data and an IsObjectOnClipboard method that validates whether a given object is currently on the clipboard. It also updates TryGetData's accessibility and improves error-handling clarity in WinFormsOleServices.

  • Added Flush helper in ClipboardCore.cs.
  • Introduced IsObjectOnClipboard to check clipboard object equality.
  • Updated QueryGetData/GetData error handling in WinFormsOleServices.cs for better clarity.

Reviewed Changes

File Description
src/System.Private.Windows.Core/src/System/Private/Windows/Ole/ClipboardCore.cs Added Flush helper and IsObjectOnClipboard including retry logic
src/System.Windows.Forms/src/System/Windows/Forms/OLE/WinFormsOleServices.cs Refactored error handling in GetData to separate query and retrieval steps

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/System.Windows.Forms/src/System/Windows/Forms/OLE/WinFormsOleServices.cs:94

  • [nitpick] The variable 'result' is reused for both QueryGetData and GetData calls, which may reduce readability. Consider using a separate variable for the GetData call to enhance clarity.
result = dataObject->GetData(formatEtc, out STGMEDIUM medium);

@JeremyKuhne
Copy link
Member Author

InvokeItemsDialog_ShouldThrowException test took down the run because it hit an assert for a negative test.

Process terminated. Assertion failed.
Need PropertyDescriptor for ICollection property to associate collection editor with.
   at System.Windows.Forms.Design.EditorServiceContext..ctor(ComponentDesigner designer, PropertyDescriptor prop) in /_/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/EditorServiceContext.cs:line 34
   at System.Windows.Forms.Design.EditorServiceContext.EditValue(ComponentDesigner designer, Object objectToChange, String propName) in /_/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/EditorServiceContext.cs:line 48
   at System.Windows.Forms.Design.ListControlUnboundActionList.InvokeItemsDialog() in /_/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ListControlUnboundActionList.cs:line 20
   at FluentAssertions.Specialized.ActionAssertions.InvokeSubject()
   at FluentAssertions.Specialized.DelegateAssertions`2.InvokeSubjectWithInterception()
   at FluentAssertions.Specialized.DelegateAssertions`2.Throw[TException](String because, Object[] becauseArgs)
   at System.Windows.Forms.Design.Tests.ListControlUnboundActionListTests.InvokeItemsDialog_ShouldThrowException() in /_/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ListControlUnboundActionListTests.cs:line 49

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 21.87500% with 25 lines in your changes missing coverage. Please review.

Project coverage is 76.10266%. Comparing base (342d09f) to head (d3a2071).
Report is 1 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13049         +/-   ##
===================================================
- Coverage   76.10589%   76.10266%   -0.00324%     
===================================================
  Files           3275        3275                 
  Lines         643778      643804         +26     
  Branches       47441       47445          +4     
===================================================
- Hits          489953      489952          -1     
- Misses        150263      150291         +28     
+ Partials        3562        3561          -1     
Flag Coverage Δ
Debug 76.10266% <21.87500%> (-0.00324%) ⬇️
integration 18.04771% <0.00000%> (-0.00130%) ⬇️
production 50.13046% <21.87500%> (-0.00490%) ⬇️
test 96.95044% <ø> (ø)
unit 47.56166% <21.87500%> (-0.00640%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@JeremyKuhne JeremyKuhne enabled auto-merge (squash) February 28, 2025 23:25
@JeremyKuhne JeremyKuhne merged commit 1371a4f into dotnet:main Mar 1, 2025
8 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0 Preview3 milestone Mar 1, 2025
@JeremyKuhne JeremyKuhne deleted the flushole branch March 1, 2025 18:19
LeafShi1 pushed a commit to LeafShi1/winforms that referenced this pull request Mar 6, 2025
Adds a flush helper (this is a public API in WPF). Tweaks some code in WinFormsOleServices for better clarity and error state handling.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants