4

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).

Sjoerd C. de Vries
  • 16,122
  • 3
  • 42
  • 94
P. Fonseca
  • 549
  • 4
  • 12
  • 2
    I think that the notebook can't check the status of symbols all the time - so it only does it when it knows it's in use, like when you move the cursor. Is this issue a big problem for you? (Aside: all SO posts are automatically signed with your name in the bottom-right corner, so it's preferred if you don't add it to the post.) – Simon Aug 11 '11 at 08:26
  • Not an enormous problem, but I sometime use the ClearAll to find instances of my functions, and so this palette would simplify my actions, but not greatly if I need to do something else to get the different color. reRemoved my signature (I thought I was losing my mind when you first removed because I was certain I had putted it there…) – P. Fonseca Aug 11 '11 at 09:14

1 Answers1

6

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".
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
Rolf Mertig
  • 1,360
  • 8
  • 22
  • Rolf, welcome to StackOverflow! Always good to get another knowledgeable Mathematica user in our community. Hope you'll enjoy it here. As to your answer: I get the same error for the second piece. The first one works, but also generates messages: "ClearAll::clloc: Cannot clear local variable result. >>" – Sjoerd C. de Vries Aug 11 '11 at 10:21