Both DefaultButton and CancelButton are very convenient, in that they allow one to use FEPrivate`FindAndClickDefaultButton and FEPrivate`FindAndClickCancelButton. Unfortunately DefaultButton doesn't allow me to use custom appearances. How can I get that behavior?
Asked
Active
Viewed 100 times
1 Answers
3
The trick is in the Appearance list. I found this here:
FileNameJoin@{
PacletFind["CloudObject"][[1]]["Location"],
"Kernel",
"Dialogs.m"
}
The appearances use listed default / hover / pressed / disabled appearances a la this question. There's another appearance option called "ButtonType" which can be set to "Cancel" or "Default" to get the desired behavior. e.g.:
Append[
FrontEndResource["NotebookTemplatingExpressions",
"ButtonDefaultAppearance"],
"ButtonType" -> "Default"
]
I use this, for example, here
This works, of course, because CreateDialog sticks this into a dialog by default:
NotebookEventActions -> {"ReturnKeyDown" :>
FE`Evaluate[FEPrivate`FindAndClickDefaultButton[]], {"MenuCommand",
"EvaluateCells"} :>
FE`Evaluate[FEPrivate`FindAndClickDefaultButton[]], {"MenuCommand",
"HandleShiftReturn"} :>
FE`Evaluate[FEPrivate`FindAndClickDefaultButton[]], {"MenuCommand",
"EvaluateNextCell"} :>
FE`Evaluate[FEPrivate`FindAndClickDefaultButton[]],
"EscapeKeyDown" :> (FE`Evaluate[
FEPrivate`FindAndClickCancelButton[]]; DialogReturn[$Failed]),
"WindowClose" :> (FE`Evaluate[FEPrivate`FindAndClickCancelButton[]];
DialogReturn[$Failed])}
And then we can imitate that like so:
CreateDocument[
{
Hyperlink["Home Page",
"https://www.wolframcloud.com/objects/b3m2a1/home/main.html",
Appearance ->
{
"Default" -> None,
"ButtonType" -> "Default"
}
],
Hyperlink["Cancel Page", "https://mathematica.stackexchange.com",
Appearance ->
{
"Default" -> None,
"ButtonType" -> "Cancel"
}
]
},
NotebookEventActions -> {"ReturnKeyDown" :>
FE`Evaluate[
FEPrivate`FindAndClickDefaultButton[]], {"MenuCommand",
"EvaluateCells"} :>
FE`Evaluate[
FEPrivate`FindAndClickDefaultButton[]], {"MenuCommand",
"HandleShiftReturn"} :>
FE`Evaluate[
FEPrivate`FindAndClickDefaultButton[]], {"MenuCommand",
"EvaluateNextCell"} :>
FE`Evaluate[FEPrivate`FindAndClickDefaultButton[]],
"EscapeKeyDown" :> (FE`Evaluate[
FEPrivate`FindAndClickCancelButton[]]; DialogReturn[$Failed]),
"WindowClose" :> (FE`Evaluate[
FEPrivate`FindAndClickCancelButton[]]; DialogReturn[$Failed])}
]
Where just pressing Enter or Cancel presses those Hyperlinks.
b3m2a1
- 46,870
- 3
- 92
- 239
DefaultButtonshould have the same options asButton. It seems that theAppearanceoption should work. You should report to WRI to see if it is a bug. – Edmund Aug 08 '17 at 21:10