Using Style with the option ContextMenu or AttachedCell it is possible to create context menus in Mathematica user interfaces. Both of these are undocumented, but shown in other answers on this site, see e.g. here or here and actually work well since several versions. But I recently detected that both do not work as expected when used in CDF Player or CDF Player Pro (I have tested this in version 10.4.1 and would actually need this to work in that version, but the problem persists with newer versions). The easiest way to test this is using the menu entry File -> CDF Preview.
The ContextMenu option seems to be ignored in CDF Player and the Attached cell is not closed when selecting an entry as it does in Mathematica (most probably because NotebookDelete does not work in the players).
Does anyone know if there is some "magic" option setting that will make either of them work in the Player versions or another workaround which would allow to define (right click) context menus so that they work in CDF Player and/or CDF Player Pro?
Here is some example code to show what it is that I am trying to get working:
Using the ContextMenu option (prefered):
Style[
Panel@Pane["Pane with context menu", {200, 200}],
ContextMenu -> {
MenuItem["One", KernelExecute@MessageDialog@"One",
MenuEvaluator -> Automatic, Method -> "Queued"],
MenuItem["Two", KernelExecute@MessageDialog@"Two",
MenuEvaluator -> Automatic, Method -> "Queued"]
}
]
or using attached cells:
EventHandler[
Panel@Pane["Pane with context menu", {200, 200}],
{
{"MouseClicked", 2} :> MathLink`CallFrontEnd[
FrontEnd`AttachCell[
EvaluationBox[],
Cell[BoxData@ToBoxes@Grid[{{
Button["One",
NotebookDelete@EvaluationCell[];MessageDialog@"One",
Appearance -> "Palette", Alignment -> Left
]
}, {
Button["Two",
NotebookDelete@EvaluationCell[] MessageDialog@"Two",
Appearance -> "Palette", Alignment -> Left
]
}},
Spacings -> {0, 0}, BaseStyle -> "Panel"
]],
{Automatic, {Center, Top}},
{Left, Top},
"ClosingActions" -> {"OutsideMouseClick", "EvaluatorQuit"}
]
]
}
]

System\`` context? e.gSystem``ContextMenu? If the explicit context is needed the reason it is not working is probably because theSystemcontext gets stripped off. I have encountered this before and had to edit the file in a text editor to add it back, e.g. forSystem\MenuConfigurationThis will work for a.nbbut may lead to problems with.cdf` – Mike Honeychurch Jan 06 '19 at 22:24