How can I remove or add an entry to the WorldMenu in Pharo at run time?
For example I have a menu option that loads extra tools for working with web tools. Running the code setting up these tools would include adding items to the menu to stop and start the web service. I don't want these stop and start items in normal use but the code setting up the items would be in the image.
I have seen and used the method in this question However this adds the item when the code is loaded.
Let me clarify what @Peter and I mean
Choose any class, and in the class side add your
#menuCommandOn:method on the lines ofThis way, even though the method would be invoked every time the world menu is about to pop up, it will add the menu item only if the logic behind
#showsItemenables it. Notice that the dynamic nature of the menu doesn't require you to remove menu items, instead you simply do not add them. In your case such a logic should reflect the availability of the web service.The
#itemTokenmessage send is a placeholder for theSymbolyou want to use to identify the item. In other words, you would probably want to inline it as a literal rather than sending the#itemTokenmessage. ThisSymbolwill be used as the itemlabel.For further optional configuration features take a look at other implementors of
#menuCommandOn:.