Component Context Menu - Disable menu items?

I have been making use of the context menu to send message handlers where a function is performed. Under certain circumstances, the function shall not be carried out. To achieve that I have written a conditional statement that if the function was not allowed, an information popup is displayed to the user.

I would rather disable the menu item (not the entire context menu) but I don't know if and how this can be done. Is it possible?

Perspective in version 8.1.34

I have handled this by generating the menu items with a script, and simply not including the items that shouldn't be enabled.

But you could probably use the "style" element to make the item look disabled and then do nothing when its message is sent.