ActionMenu with blank entries until mouseover
I'll provide two approaches
Cleaner
My guess is this is an issue with the nasty syntax for using boxes in strings. A better approach is probably to write the boxes directly. Here's one that works for me:
CurrentValue[EvaluationNotebook[], {InputAliases, "ch"}] =
ActionMenuBox[
DynamicBox[
FEPrivate`Part[
FEPrivate`ObjectContents[
FrontEnd`ParentBox[FrontEnd`EvaluationBox[]]],
2, 1, 1
]
],
MapThread[
# :> NotebookWrite[EvaluationBox[], #2] &,
Transpose@{
{SubscriptBox[ToBoxes@"C", ToBoxes@"6"], C6},
{
RowBox[{
SubscriptBox[ToBoxes@"H", "2"],
AdjustmentBox[ToBoxes@"O", BoxMargins -> {{-.5, 0}, {0, 0}}]
}],
WaterVapor
}
}
],
Appearance -> "PopupMenu",
AutoAction -> True,
BaseStyle -> {
ShowStringCharacters -> False,
FontWeight -> Plain,
FontFamily -> "Times"
}
];
I also added some fun tweaks, like making it automatically populate itself with the first label passed and changing up the BaseStyle
so you can make it look different.
No mouse
This one doesn't require the mouse at all, but you'll need to do more work to make it nice:
moveTo[tag_, i_, ntags_] :=
FrontEnd`BoxReferenceFind[
FE`BoxReference[
#,
{tag <> "_" <> ToString[Mod[i, ntags, 1]]},
FE`SearchStart -> "StartFromBeginning"
]
] &
chooseMeBox[(label_ :> value_), func_, tag_, i_, ntags_] :=
TagBox[
PanelBox[
ToBoxes@Pane[label, ImageSize -> {100, Automatic}],
Appearance -> {
"Default" ->
FrontEnd`FileName[{"Popups", "CodeCompletion"},
"CARectBG.9.png"],
"Hover" ->
FrontEnd`FileName[{"Popups", "CodeCompletion"},
"row_hover.9.png"],
"Pressed" ->
FrontEnd`FileName[{"Popups", "CodeCompletion"},
"row_hover.9.png"],
FEPrivate`If[
FEPrivate`SameQ[
FrontEnd`CurrentValue[FrontEnd`EvaluationBox[],
"SelectionOver"],
True
],
"Pressed",
Automatic
]
},
BoxID -> tag <> "_" <> ToString[i]
],
With[{d = moveTo[tag, i + 1, ntags], u = moveTo[tag, i - 1, ntags]},
EventHandlerTag[
{
"ReturnKeyDown" :> func[value],
"DownArrowKeyDown" :> FrontEndExecute[d[EvaluationNotebook[]]],
"UpArrowKeyDown" :> FrontEndExecute[d[EvaluationNotebook[]]],
Method -> "Preemptive",
PassEventsDown -> False,
PassEventsUp -> False
}
]
]
];
chooserBox[label_, rules_, tag_] :=
With[{ntags = Length@rules},
PanelBox[
GridBox[
Prepend[
{
TagBox[
PanelBox[
ToBoxes@Pane[label, ImageSize -> {100, Automatic}],
Appearance -> {
"Default" ->
FrontEnd`FileName[{"Popups", "CodeCompletion"},
"CARectBG.9.png"]
}
],
With[{d = moveTo[tag, 1, ntags],
u = moveTo[tag, ntags, ntags]},
EventHandlerTag[
{
"DownArrowKeyDown" :>
FrontEndExecute@d[EvaluationNotebook[]],
"UpArrowKeyDown" :> FrontEndExecute@u[EvaluationNotebook[]],
Method -> "Preemptive",
PassEventsDown -> False,
PassEventsUp -> False
}
]
]
]
}
]@
MapIndexed[
{
chooseMeBox[
#,
NotebookWrite[
Nest[ParentBox, EvaluationBox[], 3], #] &,
tag, #2[[1]], ntags
]
} &,
rules
],
GridBoxSpacings -> {"Rows" -> {{0}}}
],
Appearance -> {"Default" ->
FrontEnd`FileName[{"Popups", "CodeCompletion"},
"top_left.9.png"]},
BoxID -> tag
]
]
Then:
CurrentValue[EvaluationNotebook[], {InputAliases, "ch"}] =
With[
{
baseBox =
chooserBox[
"ChemTemplates",
{
RawBoxes@SubscriptBox[ToBoxes@"C", ToBoxes@"6"] :> C6,
RawBoxes@
RowBox[{SubscriptBox[ToBoxes@"H", "2"],
AdjustmentBox[ToBoxes@"O",
BoxMargins -> {{-.5, 0}, {0, 0}}]}] :> WaterVapor
},
"ChemTemplates"
]
},
DynamicBox[
baseBox
]
];