Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppKit.NSMenuToolbarItem is missing identifier constructor in MacCatalyst #15069

Closed
praeclarum opened this issue May 19, 2022 · 0 comments · Fixed by #15087
Closed

AppKit.NSMenuToolbarItem is missing identifier constructor in MacCatalyst #15069

praeclarum opened this issue May 19, 2022 · 0 comments · Fixed by #15087
Assignees
Milestone

Comments

@praeclarum
Copy link
Contributor

The initializer initWithItemIdentifier: is needed to construct toolbar menu items. https://developer.apple.com/documentation/appkit/nstoolbaritem/1534084-initwithitemidentifier?language=objc

NSMenuToolbarItem does not have this initializer. NSToolbarItem does but it lacks the ItemMenu property so can't be used.

I think the confusion is because NSMenuToolbarItem doesn't declare the initializer itself but just piggy-backs on NSToolbarItem's.

When you init the NSMenuToolbarItem without the identifier, the OS complains in the Console. The default constructor on NSMenuToolbarItem should be removed.

Here is very hacky code I use now to work around this bug:

    override this.WillInsertItem (toolbar, itemIdentifier, willBeInserted) =
        match itemIdentifier with
        | "com.example.NeuralThings.menu" ->
            let item = new AppKit.NSMenuToolbarItem ()
            let ident = new NSString (itemIdentifier)
            let res = item.PerformSelector(new ObjCRuntime.Selector("initWithItemIdentifier:"), ident)
            item.Label <- "Menu"
            let image = AppKit.NSImage.GetSystemSymbol("cube", "Menu")
            item.Image <- image
            item.ToolTip <- "Show a menu."
            item.ItemMenu <- UIMenu.Create([||])
            item.ShowsIndicator <- true
            upcast item

Steps to Reproduce

  1. Try to create an NSMenuToolbarItem with an identifier

Expected Behavior

Create the item and populate its menu

Actual Behavior

Can't create the item

Environment

Version information ``` Visual Studio Enterprise 2022 for Mac Preview Version 17.0 Preview (17.0 build 8904) Installation UUID: 54dd163c-d9bf-4043-acf4-fa17e06cda78

Runtime
.NET 6.0.3 (64-bit)
Architecture: X64

Xamarin Designer
Version: 17.1.5.90
Hash: 53f47efde
Branch: remotes/origin/d17-0-vsmac
Build date: 2022-05-05 16:33:50 UTC

Roslyn (Language Service)
4.1.0-3.22075.3+592501cbb9c9394072a245c15b3458ff88155d85

NuGet
Version: 6.0.0.262

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/6.0.300/Sdks
SDK Versions:
6.0.300
6.0.101
6.0.100
5.0.408
5.0.407
5.0.404
5.0.403
5.0.302
5.0.203
5.0.202
5.0.201
5.0.200
5.0.102
5.0.100
3.1.419
3.1.418
3.1.416
3.1.415
3.1.411
3.1.409
3.1.408
3.1.407
3.1.405
3.1.403
3.1.402
3.1.300
3.1.200
3.1.102
3.1.101
3.1.100
3.0.100
2.2.203
2.2.103
2.1.302
2.0.3
MSBuild SDKs: /usr/local/share/dotnet/sdk/6.0.300/Sdks

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
6.0.5
6.0.1
6.0.0
5.0.17
5.0.16
5.0.13
5.0.12
5.0.3
3.1.25
3.1.24
3.1.22
3.1.21

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode 13.3 (20102)
Build 13E113

Xamarin.Mac
Version: 8.10.0.1 (Visual Studio Enterprise)
Hash: 568bdb2
Branch: d17-2
Build date: 2022-04-08 18:52:56-0400

Xamarin.iOS
Version: 15.10.0.1 (Visual Studio Enterprise)
Hash: 568bdb2
Branch: d17-2
Build date: 2022-04-08 18:52:57-0400

Xamarin.Android
Version: 12.3.0.3 (Visual Studio Enterprise)
Commit: xamarin-android/d17-2/bbba5a2
Android SDK: /Users/fak/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
8.0 (API level 26)
12.0 (API level 31)
4.4 (API level 19)
8.1 (API level 27)
11.0 (API level 30)
7.1 (API level 25)
9.0 (API level 28)
7.0 (API level 24)

SDK Command-line Tools Version: 5.0
SDK Platform Tools Version: 31.0.3
SDK Build Tools Version: 30.0.3

Build Information:
Mono: adf1bc4
Java.Interop: xamarin/java.interop/d17-2@9760f0a9
ProGuard: Guardsquare/proguard@912d149
SQLite: xamarin/sqlite@7b1e016
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-2@fc3c2ac

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.2.0.37
Hash: 7f5a6ef
Branch: remotes/origin/d17-2
Build date: 2022-05-05 16:33:55 UTC

Android Device Manager
Version: 0.0.0.1116
Hash: e47e6c8
Branch: remotes/origin/d17-2
Build date: 2022-05-05 16:33:55 UTC

Build Information
Release ID: 1700008904
Git revision: efb2e3cdea6d82dd2bdd17edd3b24d3e15beb630
Build date: 2022-05-05 16:32:15+00
Build branch: release-17.0
Build lane: release-17.0

Operating System
Mac OS X 12.2.1
Darwin 21.3.0 Darwin Kernel Version 21.3.0
Wed Jan 5 21:37:58 PST 2022
root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64

</details>

@chamons chamons self-assigned this May 20, 2022
@chamons chamons added this to the Future milestone May 20, 2022
chamons added a commit to chamons/xamarin-macios that referenced this issue May 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 23, 2022
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 a pull request may close this issue.

2 participants