P. Fonseca
P. Fonseca

Reputation: 549

Why doesn't running ClearAll["Global`*"] from a custom Palette update local variables colors?

I created a custom palette, with an ActionMenu that executes ClearAll["Global`*"]. It performs the desired action, but the frontend doesn't instantly update the colors from black to blue (standard), as it happens when ClearAll["Global`*"] is executed directly from a notebook cell (it only updates after something else has been executed). Is there a way to initiate a refresh of the frontend display status?

EDIT: Apparently, the same happens when I load a package from a palette (blue doesn’t immediately update to black).

Upvotes: 4

Views: 2778

Answers (1)

Rolf Mertig
Rolf Mertig

Reputation: 1362

Not exactly elegant, but it works (the main loop has to be called once after ClearAll):

ActionMenu["Clear", 
   {"Clear global variables" :> (ClearAll["Global`*"]; 
         Block[{nb}, nb = CreateDocument[ExpressionCell[42, "Input"], 
                Visible -> False]; SelectionMove[nb, All, Notebook]; 
            SelectionEvaluate[nb]; NotebookDelete[nb];])}]

Of course, one should use the new Mathematica 8 NotebookEvaluate function, but it seems not to work here (i.e.,

ActionMenu["Clear", 
   {"Clear global variables" :> (ClearAll["Global`*"]; 
         Block[{nb}, nb = CreateDocument[ExpressionCell[42, "Input"], 
                Visible -> False]; NotebookEvaluate[nb]; 
     NotebookDelete[nb];])}]

gives an error message

Could not process unknown packet "1".

Upvotes: 6

Related Questions