Status bar menu for Mac Catalyst in .NET MAUI - maui

I have been working on an .NET MAUI app that needs to have a status bar icon and when clicked, menu to be shown. I know it is a platform specific issue and I have been folowing this tutorial from Microsoft. They have image button implemented to be shown in the status menu bar in the TrayService.
This runtime binding and creating objects are diffucult to me. The idea is to create NSMenu object, assign it to the NSStatusBar object, then create NSMenu Items with appropriate click events and assign them to the NSMenu object.
I am struggling since I don't know how to create the NSMenu object, and NSMenuItem objects with Title property for example.
NSMenu have many constructors, properties, methods to use and I don't know how to use them.
I will be very greatful with explanation or example on how to start.
_statusBarMenu = Runtime.GetNSObject(Class.GetHandle("NSMenu"));
IntPtr_objc_msgSend_String(_statusBarMenu.Handle, Selector.GetHandle("initWithTitle:"), "Quit");
void_objc_msgSend_IntPtr(_statusBarItem.Handle, Selector.GetHandle("setMenu:"), _statusBarMenu.Handle);
This compiles fine, but I don't know if IntPtr_objc_msgSend_String method exist because I added it myself at the top. However, nothing shows up in the tray.

It should be noted that Mac Catalyst is used in Maui, NSMenu and NSMenuItem are in Macos, and are not supported in Maui. For the Mac Catalyst creation menu in Maui you can refer to:
Menubar
Adding Menus and Shortcuts to the Menu Bar and User Interface | Apple Developer

Related

Search/Text Field in OSX Menu Bar Application

I have seen this example in Obj-C development for OSX, but I was wondering if it is possible to insert a Search Field or a Text Field into a Menu Bar application using Swift.
Here is an example of an application, but in Obj-C
S/S Example App
Yes,follow along this tutorial. It shows how to use NSPopover. You can use NSPopover's view outlet to customize your user interface, which is a NSTextField in your case.

How to programmatically present the WebKit inspector for a WKWebView?

Is there a way to programmatically present the WebKit inspector for a WKWebView? I am aware of how to enable the inspector for a WKWebView but what I would like to do is, similar to what is described here for a WebView, to be able to also directly pop it up on the screen programmatically from my own code. Use of private APIs and other hacks are naturally OK for me to accomplish, as this is only for debugging purposes.
The use case I have for this in my debugging flow is a WKWebView in my desktop based app where the right-click events that would usually allow for a context menu to be used for something else app specific.
As a workaround, would be happy with any means not involving right-clicking in the web view itself to bring up the inspector.
Reclaiming the right-click, eh? Interesting.
I had to plumb a large portion of WKWebKit2 C API headers into my swift app's build.
Roughly, to pull up the JS console:
WKInspectorShowConsole(WKPageGetInspector((wkwebview.subviews.first as! WKView).pageRef))
The gory details:
https://github.com/kfix/MacPin/commit/5fed6cb01ab88170f1387122748f8c4ae9e2cab5#diff-c5ffd49d5bf2cde5e056621f9ab14545R426
You need to pull in WKBase.h and WKView+Privates.h

Change menus and menu items programmatically in Eclipse E4

I am having trouble removing existing menus from the model, in a running app.
For example:
MMenu menu = modelService.findElements(app, "idMenuFoo", MMenu.class,
Collections.<String>emptyList(), EModelService.IN_MAIN_MENU).get(0);
menu.setLabel("X");
menu.setVisible(false);
menu.setToBeRendered(false);
After this code gets executed:
The label has been changed to 'X'
But the menu entry is still visible/rendered
If I start the app without clearPersistedState, then restart it, the menu has disappeared. This leads me to be believe the the visibility and rendering attributes were set in the first place, but not applied to the model (unlike the label attribute).
How can I programmatically trigger a main menu bar "refresh" after such changes?
As a Greg in the comment above posted, there is an open bug filed to address this issue. An easy to implement a workaround involves manually refreshing the underlying SWT menu. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=365724#c9 for details. In a gist:
// retrieve the main menu, containing the top-level menu element that needs to be refreshed
MMenu mainMenu = ...
// org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer
MenuManagerRender renderer = (MenuManagerRenderer)mainMenu.getRenderer();
renderer.getManager(mainMenu).update(true);

How to create Android app WITHOUTH action bar?

I can not create an android app with an SDK < 14 (4.0) because all of the templates (including the so-called "Blank") include the "Action Bar", which is a 14+ feature.
How do I create an app WITHOUT an action bar? Does somebody have an old template for Blank without an Action Bar?
You can instantiate the Action Bar object and using the method hide() you will be able to hide it.
final ActionBar bar = getActionBar();
And from the documentation:
Instead of calling this function directly, you can also cause an
ActionBar using the overlay feature to hide through
View.SYSTEM_UI_FLAG_FULLSCREEN. Hiding the ActionBar through this
system UI flag allows you to more seamlessly hide it in conjunction
with other screen decorations
Hope it helps

Where is 'Class Actions' in the 'Object Identity' panel in Interface Builder?

I thought I was fairly experienced at iPhone development, but I'm tripping up on the Stanford iPhone course on the very first video.
(38 mins in)
The teacher, drags an NSObject into the MainWindow.xib. And when he inspects the Object in the Identity Inspector (Cmd-4), there are Class Actions and Class Outlets sections.
However, these don't appear for me, just Class Identity and Interface Builder Identity... Where have they gone?
Interface Builder has gone through some changes recently. Go to classes in the library panel, select the object from the top half you wish to inspect and the lower half of the screen has tabs for Lineage, Definitions, Outlets and Actions.
In the library panel find the Segmented-Button, Click on classes. Find NSObject or any other class you would like to subclass. Right click and "New subclass...", Name it something useful in the pop up like controller/AppController. Find your newly named Class in the class list. Now add all your actions/outlets in the Bottom of the library panel.
Thanks to Convolution I would never have found this. (Just thought I'd expand on the above tip).
I finally solve my issue as the same as you. Before , I used a earlier version of IB, that's 3.1. And I can access "Class Actions and Class Outlets sections" on Tools-> Identity Inspector Panel. But after I choose another macbook (which IB is upgraded to version 3.2.1), I must access the corresponding section Library panel->Classes Tab->choose the specified object, then go to the panel's lower part(as illustrated by Convolution).