Consider the following minimal example package:
BeginPackage["Test`"];
DuplicateNotebook::usage = "Makes a copy of the notebook";
Begin["`Private`"];
DuplicateNotebook[] :=
NotebookPut @ NotebookGet[EvaluationNotebook[]];
ex2 =
Grid[{{Item[ButtonBar[{
Style["Duplicate", 10] :> DuplicateNotebook[],
Style["Quit Kernel", 10] :> FrontEndTokenExecute["EvaluatorQuit"]}],
Alignment -> {Right, Top}]}}];
SetOptions[EvaluationNotebook[],
DockedCells -> Cell[BoxData[ToBoxes[ex2]], "SystemDockedCell"]];
End[];
EndPackage[];
So what's happening?
The function DuplicateNotebook[] defined in the package doesn't get called when the button is clicked, but calls of type FrontEndTokenExecute["EvaluatorQuit"] work.
What's more, this code was working perfectely well in Mathematica V9, but now in Mathematica V10, I can't get it working without putting the function body directly into DockedCells, which of course is a very messy solution. Therefore I'm looking for better workarounds.
This seems to be a problem with DockedCells context, because putting the cell in the notebook (not in DockedCells) works. However adding context information to the call didn't work (I've tried Test`DuplicateNotebook[])
Zipped version of the test package http://cl.ly/2C3U2O2n0y21
bugstag for suspected bugs. It is reserved for marking *confirmed* bugs. – m_goldberg Aug 19 '14 at 12:45Print[DownValues[DuplicateNotebook]], it strangely prints{}. – Szabolcs Aug 19 '14 at 13:08