Skip to content

Commit

Permalink
[AppKit] Improve bindings for NSPasteboard and NSPasteboardReading a …
Browse files Browse the repository at this point in the history
…bit. (#20643)

* Create strong enums for NSPasteboardType and NSPasteboardName.
* Bind the NSPasteboardReading constructor.

Ref: #14039
  • Loading branch information
rolfbjarne committed May 30, 2024
1 parent 36bc43f commit 13cec0c
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 38 deletions.
21 changes: 21 additions & 0 deletions src/AppKit/NSPasteboardReading.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#if !__MACCATALYST__

using System;

using Foundation;
using ObjCRuntime;

#nullable enable

#if NET
namespace AppKit {
public partial interface INSPasteboardReading {
[BindingImpl (BindingImplOptions.Optimizable)]
public unsafe static T? CreateInstance<T> (NSObject propertyList, NSPasteboardType type) where T: NSObject, INSPasteboardReading
{
return CreateInstance<T> (propertyList, type.GetConstant ()!);
}
}
}
#endif // NET
#endif // !__MACCATALYST__
153 changes: 151 additions & 2 deletions src/appkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11453,6 +11453,7 @@ partial interface NSPasteboard // NSPasteboard does _not_ implement NSPasteboard
[Export ("stringForType:")]
string GetStringForType (string dataType);

#if !XAMCORE_5_0
// Pasteboard data types

[Field ("NSStringPboardType")]
Expand Down Expand Up @@ -11487,6 +11488,7 @@ partial interface NSPasteboard // NSPasteboard does _not_ implement NSPasteboard
[Deprecated (PlatformName.MacOSX, 10, 14, message: "Use 'NSPasteboardTypeRuler' instead.")]
NSString NSRulerType { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSFileContentsPboardType")]
NSString NSFileContentsType { get; }

Expand All @@ -11503,6 +11505,7 @@ partial interface NSPasteboard // NSPasteboard does _not_ implement NSPasteboard
NSString NSHtmlType { get; }

[Field ("NSPICTPboardType")]
[Deprecated (PlatformName.MacOSX, 10, 6 /* Yes, 10.6 */, message: "Do not use, the PICT format was discontinued a long time ago.")]
NSString NSPictType { get; }

[Field ("NSURLPboardType")]
Expand Down Expand Up @@ -11547,77 +11550,219 @@ partial interface NSPasteboard // NSPasteboard does _not_ implement NSPasteboard
[Deprecated (PlatformName.MacOSX, 10, 13, message: "Use 'NSPasteboardNameDrag' instead.")]
NSString NSDragPasteboardName { get; }

[Obsolete ("Use the 'NSPasteboardName' enum instead.")]
[Field ("NSPasteboardNameGeneral")]
NSString NSPasteboardNameGeneral { get; }

[Obsolete ("Use the 'NSPasteboardName' enum instead.")]
[Field ("NSPasteboardNameFont")]
NSString NSPasteboardNameFont { get; }

[Obsolete ("Use the 'NSPasteboardName' enum instead.")]
[Field ("NSPasteboardNameRuler")]
NSString NSPasteboardNameRuler { get; }

[Obsolete ("Use the 'NSPasteboardName' enum instead.")]
[Field ("NSPasteboardNameFind")]
NSString NSPasteboardNameFind { get; }

[Obsolete ("Use the 'NSPasteboardName' enum instead.")]
[Field ("NSPasteboardNameDrag")]
NSString NSPasteboardNameDrag { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeString")]
NSString NSPasteboardTypeString { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypePDF")]
NSString NSPasteboardTypePDF { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeTIFF")]
NSString NSPasteboardTypeTIFF { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypePNG")]
NSString NSPasteboardTypePNG { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeRTF")]
NSString NSPasteboardTypeRTF { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeRTFD")]
NSString NSPasteboardTypeRTFD { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeHTML")]
NSString NSPasteboardTypeHTML { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeTabularText")]
NSString NSPasteboardTypeTabularText { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeFont")]
NSString NSPasteboardTypeFont { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeRuler")]
NSString NSPasteboardTypeRuler { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeColor")]
NSString NSPasteboardTypeColor { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeSound")]
NSString NSPasteboardTypeSound { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeMultipleTextSelection")]
NSString NSPasteboardTypeMultipleTextSelection { get; }

[Field ("NSPasteboardTypeFindPanelSearchOptions")]
[Deprecated (PlatformName.MacOSX, 10, 14, message: "Use 'NSPasteboardTypeTextFinderOptions' instead.")]
NSString NSPasteboardTypeFindPanelSearchOptions { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeTextFinderOptions")]
NSString PasteboardTypeTextFinderOptions { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeURL")]
NSString NSPasteboardTypeUrl { get; }

[Obsolete ("Use the 'NSPasteboardType' enum instead.")]
[Field ("NSPasteboardTypeFileURL")]
NSString NSPasteboardTypeFileUrl { get; }
#endif // !XAMCORE_5_0

[Export ("prepareForNewContentsWithOptions:")]
nint PrepareForNewContents (NSPasteboardContentsOptions options);
}

[NoMacCatalyst]
enum NSPasteboardName {
[Field ("NSPasteboardNameGeneral")]
General,

[Field ("NSPasteboardNameFont")]
Font,

[Field ("NSPasteboardNameRuler")]
Ruler,

[Field ("NSPasteboardNameFind")]
Find,

[Field ("NSPasteboardNameDrag")]
Drag,
}

[NoMacCatalyst]
enum NSPasteboardType {
[Field ("NSFileContentsPboardType")]
FileContents,

[Field ("NSPasteboardTypeString")]
String,

[Field ("NSPasteboardTypePDF")]
Pdf,

[Field ("NSPasteboardTypeTIFF")]
Tiff,

[Field ("NSPasteboardTypePNG")]
Png,

[Field ("NSPasteboardTypeRTF")]
Rtf,

[Field ("NSPasteboardTypeRTFD")]
Rtfd,

[Field ("NSPasteboardTypeHTML")]
Html,

[Field ("NSPasteboardTypeTabularText")]
TabularText,

[Field ("NSPasteboardTypeFont")]
Font,

[Field ("NSPasteboardTypeRuler")]
Ruler,

[Field ("NSPasteboardTypeColor")]
Color,

[Field ("NSPasteboardTypeSound")]
Sound,

[Field ("NSPasteboardTypeMultipleTextSelection")]
MultipleTextSelection,

[Field ("NSPasteboardTypeTextFinderOptions")]
TextFinderOptions,

[Field ("NSPasteboardTypeURL")]
Url,

[Field ("NSPasteboardTypeFileURL")]
FileUrl,

[Mac (13, 0)]
[Field ("NSPasteboardTypeCollaborationMetadata", "SharedWithYou")]
CollaborationMetadata,

[Field ("NSFindPanelSearchOptionsPboardType")]
FindPanelSearchOptions,

// Deprecated with replacement in all macOS versions we support, so we're not binding them:
// NSFilenamesPboardType
// NSFontPboardType
// NSColorPboardType
// NSHTMLPboardType
// NSMultipleTextSelectionPboardType
// NSPDFPboardType
// NSPICTPboardType (no replacement, just don't use)
// NSRTFDPboardType
// NSRTFDPboardType
// NSRulerPboardType
// NSStringPboardType
// NSTIFFPboardType
// NSTabularTextPboardType
// NSURLPboardType
// NSPasteboardTypeFindPanelSearchOptions
// NSFilesPromisePboardType
// NSInkTextPboardType
// NSPostScriptPboardType
// NSVCardPboardType
// NSGetFileType
// NSRTFPboardType
}

[NoMacCatalyst]
enum NSPasteboardTypeTextFinderOptionKey {
[Field ("NSTextFinderCaseInsensitiveKey")]
CaseInsensitiveKey,

[Field ("NSTextFinderMatchingTypeKey")]
MatchingTypeKey,
}

[NoMacCatalyst]
enum NSPasteboardTypeFindPanelSearchOptionKey {
[Field ("NSFindPanelCaseInsensitiveSearch")]
CaseInsensitiveSearch,

[Field ("NSFindPanelSubstringMatch")]
SubstringMatch,
}

[NoiOS]
[NoTV]
[NoMacCatalyst]
Expand Down Expand Up @@ -11725,9 +11870,13 @@ interface NSPasteboardReading {
[Export ("readingOptionsForType:pasteboard:")]
NSPasteboardReadingOptions GetReadingOptionsForType (string type, NSPasteboard pasteboard);

#if !NET
// This binding is just broken, it's an ObjC ctor (init*) bound as a normal method.
[Abstract]
#if NET
[Export ("initWithPasteboardPropertyList:ofType:")]
NativeHandle Constructor (NSObject propertyList, NSString type);

#else
// This binding is just broken, it's an ObjC ctor (init*) bound as a normal method.
[Export ("xamarinselector:removed:")]
[Obsolete ("It will never be called.")]
NSObject InitWithPasteboardPropertyList (NSObject propertyList, string type);
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ APPKIT_SOURCES = \
AppKit/NSDraggingSession.cs \
AppKit/NSDraggingItem.cs \
AppKit/NSPasteboard.cs \
AppKit/NSPasteboardReading.cs \
AppKit/NSSharingServiceDelegate.cs \
AppKit/NSDocument.cs \
AppKit/NSEnumsExtensions.cs \
Expand Down
56 changes: 34 additions & 22 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2234,10 +2234,38 @@ F:AppKit.NSPageControllerTransitionStyle.StackHistory
F:AppKit.NSPageLayoutResult.Cancelled
F:AppKit.NSPageLayoutResult.Changed
F:AppKit.NSPasteboardContentsOptions.CurrentHostOnly
F:AppKit.NSPasteboardName.Drag
F:AppKit.NSPasteboardName.Find
F:AppKit.NSPasteboardName.Font
F:AppKit.NSPasteboardName.General
F:AppKit.NSPasteboardName.Ruler
F:AppKit.NSPasteboardReadingOptions.AsData
F:AppKit.NSPasteboardReadingOptions.AsKeyedArchive
F:AppKit.NSPasteboardReadingOptions.AsPropertyList
F:AppKit.NSPasteboardReadingOptions.AsString
F:AppKit.NSPasteboardType.CollaborationMetadata
F:AppKit.NSPasteboardType.Color
F:AppKit.NSPasteboardType.FileContents
F:AppKit.NSPasteboardType.FileUrl
F:AppKit.NSPasteboardType.FindPanelSearchOptions
F:AppKit.NSPasteboardType.Font
F:AppKit.NSPasteboardType.Html
F:AppKit.NSPasteboardType.MultipleTextSelection
F:AppKit.NSPasteboardType.Pdf
F:AppKit.NSPasteboardType.Png
F:AppKit.NSPasteboardType.Rtf
F:AppKit.NSPasteboardType.Rtfd
F:AppKit.NSPasteboardType.Ruler
F:AppKit.NSPasteboardType.Sound
F:AppKit.NSPasteboardType.String
F:AppKit.NSPasteboardType.TabularText
F:AppKit.NSPasteboardType.TextFinderOptions
F:AppKit.NSPasteboardType.Tiff
F:AppKit.NSPasteboardType.Url
F:AppKit.NSPasteboardTypeFindPanelSearchOptionKey.CaseInsensitiveSearch
F:AppKit.NSPasteboardTypeFindPanelSearchOptionKey.SubstringMatch
F:AppKit.NSPasteboardTypeTextFinderOptionKey.CaseInsensitiveKey
F:AppKit.NSPasteboardTypeTextFinderOptionKey.MatchingTypeKey
F:AppKit.NSPasteboardWritingOptions.WritingPromised
F:AppKit.NSPathStyle.NavigationBar
F:AppKit.NSPathStyle.PopUp
Expand Down Expand Up @@ -21091,6 +21119,8 @@ M:AppKit.INSHapticFeedbackPerformer.PerformFeedback(AppKit.NSHapticFeedbackPatte
M:AppKit.INSMenuItemValidation.ValidateMenuItem(AppKit.NSMenuItem)
M:AppKit.INSMenuValidation.ValidateMenuItem(AppKit.NSMenuItem)
M:AppKit.INSPasteboardItemDataProvider.ProvideDataForType(AppKit.NSPasteboard,AppKit.NSPasteboardItem,System.String)
M:AppKit.INSPasteboardReading.CreateInstance``1(Foundation.NSObject,AppKit.NSPasteboardType)
M:AppKit.INSPasteboardReading.CreateInstance``1(Foundation.NSObject,Foundation.NSString)
M:AppKit.INSPasteboardTypeOwner.ProvideData(AppKit.NSPasteboard,System.String)
M:AppKit.INSPasteboardWriting.GetPasteboardPropertyListForType(System.String)
M:AppKit.INSPasteboardWriting.GetWritableTypesForPasteboard(AppKit.NSPasteboard)
Expand Down Expand Up @@ -47509,7 +47539,6 @@ P:AppKit.NSParagraphStyle.TextLists
P:AppKit.NSParagraphStyle.UsesDefaultHyphenation
P:AppKit.NSPasteboard.NSColorType
P:AppKit.NSPasteboard.NSDragPasteboardName
P:AppKit.NSPasteboard.NSFileContentsType
P:AppKit.NSPasteboard.NSFilenamesType
P:AppKit.NSPasteboard.NSFilesPromiseType
P:AppKit.NSPasteboard.NSFindPasteboardName
Expand All @@ -47518,27 +47547,7 @@ P:AppKit.NSPasteboard.NSFontType
P:AppKit.NSPasteboard.NSGeneralPasteboardName
P:AppKit.NSPasteboard.NSHtmlType
P:AppKit.NSPasteboard.NSMultipleTextSelectionType
P:AppKit.NSPasteboard.NSPasteboardNameDrag
P:AppKit.NSPasteboard.NSPasteboardNameFind
P:AppKit.NSPasteboard.NSPasteboardNameFont
P:AppKit.NSPasteboard.NSPasteboardNameGeneral
P:AppKit.NSPasteboard.NSPasteboardNameRuler
P:AppKit.NSPasteboard.NSPasteboardTypeColor
P:AppKit.NSPasteboard.NSPasteboardTypeFileUrl
P:AppKit.NSPasteboard.NSPasteboardTypeFindPanelSearchOptions
P:AppKit.NSPasteboard.NSPasteboardTypeFont
P:AppKit.NSPasteboard.NSPasteboardTypeHTML
P:AppKit.NSPasteboard.NSPasteboardTypeMultipleTextSelection
P:AppKit.NSPasteboard.NSPasteboardTypePDF
P:AppKit.NSPasteboard.NSPasteboardTypePNG
P:AppKit.NSPasteboard.NSPasteboardTypeRTF
P:AppKit.NSPasteboard.NSPasteboardTypeRTFD
P:AppKit.NSPasteboard.NSPasteboardTypeRuler
P:AppKit.NSPasteboard.NSPasteboardTypeSound
P:AppKit.NSPasteboard.NSPasteboardTypeString
P:AppKit.NSPasteboard.NSPasteboardTypeTabularText
P:AppKit.NSPasteboard.NSPasteboardTypeTIFF
P:AppKit.NSPasteboard.NSPasteboardTypeUrl
P:AppKit.NSPasteboard.NSPdfType
P:AppKit.NSPasteboard.NSPictType
P:AppKit.NSPasteboard.NSPostScriptType
Expand All @@ -47551,7 +47560,6 @@ P:AppKit.NSPasteboard.NSTabularTextType
P:AppKit.NSPasteboard.NSTiffType
P:AppKit.NSPasteboard.NSUrlType
P:AppKit.NSPasteboard.NSVCardType
P:AppKit.NSPasteboard.PasteboardTypeTextFinderOptions
P:AppKit.NSPasteboardItem.CollaborationMetadata
P:AppKit.NSPathCell.Delegate
P:AppKit.NSPathCellDisplayPanelEventArgs.OpenPanel
Expand Down Expand Up @@ -68389,7 +68397,11 @@ T:AppKit.NSPageLayoutResult
T:AppKit.NSParagraphStyle
T:AppKit.NSPasteboardContentsOptions
T:AppKit.NSPasteboardItemDataProvider
T:AppKit.NSPasteboardName
T:AppKit.NSPasteboardReadingOptions
T:AppKit.NSPasteboardType
T:AppKit.NSPasteboardTypeFindPanelSearchOptionKey
T:AppKit.NSPasteboardTypeTextFinderOptionKey
T:AppKit.NSPasteboardWritingOptions
T:AppKit.NSPathCellDelegate
T:AppKit.NSPathCellDisplayPanelEventArgs
Expand Down
Loading

12 comments on commit 13cec0c

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.