I am trying to build a multi-level ActionMenu. A single level ActionMenu is easy following the documents, such as ActionMenu["Single Level", {"1" :> Print[1], "2" :> Print[2], "3" :> Print[3]}]
However, I don't know how to expand this to multi-level selection. A naive code such as ActionMenu["Multi-Level", {"1" :> ActionMenu["Level 2", {"a" :> Print[a], "b" :> Print[b]}], "2" :> Print[2], "3" :> Print[3]}]
didn't work. Please help...
-
2$\begingroup$ related/possible duplicate: How to make a dynamic nested menu? $\endgroup$– kglrMay 15, 2021 at 21:28
-
$\begingroup$ Agreed, this look like a solution to this question. $\endgroup$– bakerryd123May 19, 2021 at 12:59
1 Answer
You may use AttachCell
with EvaluationBox
. AttachCell
is an experimental function in version 12.2 so behaviour may change.
I AttachCell
a new ActionMenu
below the evaluating ActionMenu
using EvaluationBox
. The attached menu deletes itself and performs the action. The other options also delete the attached menu before performing their actions.
Module[
{acell}
, ActionMenu[
"Multi-Level"
, {
"1" :> (
NotebookDelete[acell]
; acell =
AttachCell[
EvaluationBox[]
, ActionMenu[
"Level 2"
, {
"a" :> (NotebookDelete[acell]; Print[a])
, "b" :> (NotebookDelete[acell]; Print[b])
}
]
, {Left, Bottom}, Automatic, {Left, Top}
]
)
, "2" :> (NotebookDelete[acell]; Print[2])
, "3" :> (NotebookDelete[acell]; Print[3])
}
]
]
Hope this helps.
-
$\begingroup$ Thanks for the suggestion, this is a cool solution. I didn't know the AttachCell function previously, seems like a pretty new function. However, I am trying to implement this on a palettes, not sure how it will work out. $\endgroup$ May 19, 2021 at 12:58