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...
Asked
Active
Viewed 98 times
1
bakerryd123
- 427
- 2
- 8
-
2related/possible duplicate: How to make a dynamic nested menu? – kglr May 15 '21 at 21:28
-
Agreed, this look like a solution to this question. – bakerryd123 May 19 '21 at 12:59
1 Answers
1
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.
Edmund
- 42,267
- 3
- 51
- 143
-
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. – bakerryd123 May 19 '21 at 12:58
