8
$\begingroup$

Please follow those steps to get the idea about the problem:

  1. 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}
    ];
    
  2. And save it to users palettes directory.

    palettePath = FileNameJoin[{$UserBaseDirectory, "SystemFiles", 
        "FrontEnd", "Palettes", "TESTPalette.nb"}];
    
    NotebookSave[  nb,   palettePath   ];
    NotebookClose @ nb;
    
  3. Reset menus to show it there:

    MathLink`CallFrontEnd[ FrontEnd`ResetMenusPacket[{Automatic, Automatic}]]
    

    enter image description here

  4. Click on the item or run FrontEndTokenExecute["OpenFromPalettesMenu", FileNameTake @ palettePath] and we have it working:

    enter image description here

  5. Close the palette and delete it.

    DeleteFile @ palettePath
    
  6. 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...

enter image description here

  • But the file is saved correctly:

    FilePrint @ palettePath
    

    shows that there is "A" inside TaggingRules. 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?

$\endgroup$
  • 1
    $\begingroup$ I think the caching is documented in reference.wolfram.com/language/tutorial/… $\endgroup$ – ilian Apr 8 '16 at 22:45
  • $\begingroup$ @ilian I think that's it, been there forgot that. Yet I'm surprised that there is a difference in using Preemprive or Main link. Do you want to answer? should I answer the support about finding the issue? Moreover, I don't like all those exceptions that are trying to make my life easier, it's usually the oposite :) $\endgroup$ – Kuba Apr 9 '16 at 7:43
  • $\begingroup$ Support has been made aware of that tutorial. It was actually new to me so I'd leave writing the answer to the more knowledgeable about the FE (perhaps you should self-answer!) $\endgroup$ – ilian Apr 11 '16 at 0:22
3
$\begingroup$

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] -> _
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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