1
$\begingroup$

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...

$\endgroup$
2

1 Answer 1

1
$\begingroup$

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])
   }
  ]
 ]

enter image description here

Hope this helps.

$\endgroup$
1
  • $\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.