Please follow those steps to get the idea about the problem:
Let's create a palette:
nb = CreatePalette[
DynamicModule[{},
Panel["Hello you!", ImageSize -> 500, Alignment -> Center]
,
SynchronousInitialization -> False,
Initialization :> (
CreateDocument@CurrentValue[EvaluationNotebook[], TaggingRules]
)
],
WindowTitle -> "Palette B ",
TaggingRules -> {"B" -> 1123}
];And save it to users palettes directory.
palettePath = FileNameJoin[{$UserBaseDirectory, "SystemFiles",
"FrontEnd", "Palettes", "TESTPalette.nb"}];
NotebookSave[ nb, palettePath ];
NotebookClose @ nb;Reset menus to show it there:
MathLink`CallFrontEnd[ FrontEnd`ResetMenusPacket[{Automatic, Automatic}]]
Click on the item or run
FrontEndTokenExecute["OpenFromPalettesMenu", FileNameTake @ palettePath]
and we have it working:Close the palette and delete it.
DeleteFile @ palettePath
Repeat steps 1-4 with different
TaggingRules
WindowTitle -> "Palette A",
TaggingRules -> {"A" -> 1112}
The problem
Now there is a new Palette's Menu item - "Palette A" - and that notebook is opened when clicked, yet the old TaggingRules with "B"
are prompted...
But the file is saved correctly:
FilePrint @ palettePath
shows that there is
"A"
insideTaggingRules
. So"B"
was somehow, cached somewhere.Also, when one opens the notebook manually or with
NotebookOpen @ paletePath
it works well...The problem remains after restarting Mathematica.
The
SynchronousInitialization
option is necessary, I wasn't able to reproduce the problem without it.
What is going on and how to deal with this?
Answer
As noted by ilian, this behaviour is explained in StoringAndTrackingPaletteStates tutorial.
Shortly, CurrentValue[$FrontEnd, System`PalettesMenuSettings]
keeps those values cached.
In order to achieve what I described in the question we have to drop an entry that coresponds to our palette.
It doesn't really matter when it's done. Just do it before you need it to work :)
CurrentValue[$FrontEnd, System`PalettesMenuSettings] = DeleteCases[
CurrentValue[$FrontEnd, System`PalettesMenuSettings],
FileNameTake[palettePath] -> _
]
Comments
Post a Comment