Hello,
I have a toolbar manager with context menu tools dynamically generated based on the item under the mouse for right click. When the context menu has processed, I dispose these dynamically generated tools and associated tag data. Typically, when the popup menu closes I inspect the tools for an active tool, if no active tool, I dispose the tools in the ToolbarManager AfterToolCloseUp event else use the subsequent ToolClick event to clean up the tools.
If the user uses the arrow keys to move through the menu and then presses return, the CloseUp event fires with no ActiveTool on the menu. Then the ToolClick event fires. With the current implementation the tool click won't process as the required info has already been cleared.
I'm looking for some reliable trigger to use to remove the dynamically added tools. Is there a property or method that will detect whether a ToolClick event will follow the ToolCloseUp event? Or some way to know that the tool processing has finished?
Thanks for any suggestions,
Wendy
You could use this event in order to populate (modify) your list of tools.
Please let me now if you have any further questions.
Hello Hristo,
I've reviewed the sample. I can refactor to the approach where previous dynamic tools are removed then new dynamic tools added before the menu is shown.
In the current implementation, controls set their context menu usually with OnLoad override. The ToolbarMgr will then handle the right click and show the popup menu. This context menu is updated, adding tools and adjusting state, with the BeforeToolDropDown event where the event args provide the sourceCtl for the popupMenu. Multiple controls re-use a base context menu, which has common tools added to the UltraToolbarsManager at design time.
Your reply states "it is not a good practice to remove or dispose tools while UltraToolbarsManager works with them". Does this caution also apply to the BeforeToolDropDown event or can this event be used to add/remove tools from a base menu rather than the right click used in the sample? If not, any other suggestions on how to change a context menu re-used by multiple controls, e.g. 5 text editors, one base context menu with dynamic tools specific to each editor?
Thank you for the assistance.
ToolClick event will occurs only if user clicks on tool (click with mouse or uses keyboard ), so if the user press “Escape” button or just click outside of PopupMenuTool, ToolClick event will not be fired. Also you will not be able and it is not a good practice to remove or dispose tools while UltraToolbarsManager works with them. As far as I understand you are populating your tool collection on RightClick of the form, so the correctly place where you could remove your dynamically added tools is in this event. You should first remove all dynamically added tools (if there are any of them), and then to add new. I have implemented my suggestion in a simple sample. I hope that this will helps you.
Please el tem know if you have any further questions.