Hi, all -
We are currently building an MDI-based app, and the MDI container's toolbar manager has tools for File menu, Window menu, etc. And then the MDI children add a couple of their own, which are document-specific - Edit menu is a good example.
But then we are loading custom controls into the MDI children, things that the main MDI container will have virtually no knowledge of. (That said, there are a couple of custom events that we use to communicate.) We load them based on application.settings keys and DLLs in the app's folder.
I would like to have available a custom menu (or menus), specific to each custom control. Ideally, the custom DLL would load, and any popup menus or toolbars that are specific to that control would show up in the main app's toolbar, alongside the file/edit/window menus - that is, merge them the way MDI children merge with their parents.
The best I've been able to do is make a floatable toolbar attached to the custom control, but of course it stays.. well.. attached to the control. I can't dock it at the top of the screen.
I had the idea of using a custom event to let the main app know when a control has been created or updated, and hand it the toolbars that I'd like merged in the main window, but it's getting uppity with me and telling me I can't insert the custom control's menus into the main window's toolbarmanager. The nerve...
So - is there any way for me to do this? If you need clarification, I'd be happy to make it happen...
Thanks!Rob Russell
The toolbars manager does not support merging multiple child managers, but you can submit a feature request for this: http://devcenter.infragistics.com/Protected/RequestFeature.aspx.
Other than that, you would need to implement this manually. There are a few ways you could do this. You can recreate the menus and tools on the child toolbars manager, then call RefreshMerge() on either the parent or child managers to see those new tools in the merged parent manager. You could also recreate the menus and tools on the parent manager. It sounds like this is what you were trying to do when you were told you couldn't do it though. If you were trying to take the tools which exist in the custom control's manager and add them directly to one of the other managers, this is not supported. Tools can only exist in one manager. However, if you were creating copies, it should have worked. If it didn't, it could be a bug and I would recommend submitting it to the support group: http://ko.infragistics.com/gethelp.
Hi, Mike -
I was trying to do it w/out making copies. Can you give me the syntax for that? I've scanned the Tool methods for things like GetCopy or GetClone etc, but came up empty.
My question if we go that route, then, is where do the events for this tool get handled? Can I still handle events from the copied tool in the embedded custom control? Or would I have to trap them in the MDI manager and pass them off somehow?
Rob
rprussell said:I was trying to do it w/out making copies. Can you give me the syntax for that? I've scanned the Tool methods for things like GetCopy or GetClone etc, but came up empty.
There is no way to accomplish this without making copies. There is no method on ToolBase to clone or copy the tool. This will need to be done manually by creating new tools of the same type and copying over any relevant properties.
rprussell said:My question if we go that route, then, is where do the events for this tool get handled? Can I still handle events from the copied tool in the embedded custom control? Or would I have to trap them in the MDI manager and pass them off somehow?
It depends where the tools are defined. If you take the approach where you add the tools to the child and call RefreshMerge(), the events will be fired on the child. If you add the tools to the parent, the events will be called don the parent. The events cannot be automatically routed to the custom control, you would need to manually trap them and pass them off. I would recommend giving the copied tool's keys a prefix or suffix which indicates which custom control the events should be routed to. The manager which initially handles the event could examine the tool's key for this prefix or suffix and pass it off to the corresponding custom control.
Hi Mike,
Feature: Merge a module (mode) toolbar manager's menus and buttons to the mainform's menu and toolbar. We access the module through the IUserCommand interface.
Steps:
1. Drop down menus is actually a tree relationship. Since calling toolbarmange.clear will clear all the menu tree info, I need to keep the menu tree info before it was cleared. I create a treeview class then attach tool's key to the nodes.
2. Get module toolbar manage’s tool, then call manager’s clear methods, this will set all the manger property to null. That way we will be able to add the tools into mainform manager.
3. Attach each tool to the tree node’s tag property, that match the key.
4. Rebuild the menu tree
5. Add the rebuild menu tree to the mainform toolbar manager.
6. Merge toolbar tools, add tool bar tools to a new toolbar, then add the new toolbar to the mainform manager.
Here is the code
I wasn't saying that the toolbars having the same keys was preventing the tools from being shown, I was saying that the only relationship the two toolbars have to each other is they have the same key. There is nothing in your code that will cause the new toolbar to show or even know about the tools from the original toolbar. The manager.Toolbars.AddToolbar method call creates an entirely new and blank toolbar with the key passed to the method.
However, if you are only merging two managers together at one time, like you say you are, you don't need to create new toolbars manually anyway. Set MdiMergeable on both managers to False. At runtime, when you want to merge in a module's toolbars manager, Set the ActiveMdiChilManager of the parent manager to the manager on the module.
It is not same key that prevent tools shown. Now I created 2 tools, making sure no duplicating keys. The message box show 2 tools before and 0 tools after adding the toolbar into the manager. Here is the code.
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new ButtonTool("Metx1");
buttonTool1.SharedProps.Caption = "MetX1";
buttonTool1.Key = "MetX1 key";
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new ButtonTool("Metx2");
buttonTool2.SharedProps.Caption = "MetX2";
buttonTool2.Key = "MetX2 key";
Infragistics.Win.UltraWinToolbars.ButtonTool[ tools = { buttonTool1, buttonTool2 };
manager.Tools .AddRange(tools);
Infragistics.Win.UltraWinToolbars.UltraToolbar newToolbar = new UltraToolbar("newToolbar");
newToolbar.NonInheritedTools.AddRange(tools);
MessageBox.Show(newToolbar.ToString() + " has " + newToolbar.Tools.Count.ToString() + " tools before adding to manager");
manager.Toolbars.AddToolbar(newToolbar.Key);
manager.RefreshMerge();
MessageBox.Show(manager.Toolbars[2].ToString() + " has " + manager.Toolbars[2].Tools.Count.ToString() + " tools after adding to manager");
manager.Toolbars[2] is hard coded for testing as I know manager has two toolbar before adding the new toolbar.
My feature requires me dynamically switching modules. The toolbars merge happens each time the module is switched to be active. I need to remove the previous merged tools then merge new tools. But each merge only two toolbar managers involved.
In my prototyped stage I want to test if I can add newly created tools into parent form toolbar manager dynamically, and then test if I can pass the newly created tools events from parent form to customer controls.
Julie
The reason the tools are not appearing is because you are just adding new toolbars to the main manager which just happen to have the same key as the toolbars from the module. They have no relationship or reference to one another, so the new toolbar cannot know which tools it should be populated with.
If you are only trying to merge in one user control, you can use the normal merging logic built in to the toolbars manager (set MdiMergeable to False on both managers and set the user control manager as the ActiveMdiChildManager of the main form manager). If you have to merge in multiple user controls, you will have to manually recreate the tools in the parent and add them to the new toolbars. You can also submit a feature request for multiple merging to allow the merging of many child managers into a parent manager: http://devcenter.infragistics.com/Protected/RequestFeature.aspx.
I had similar scenario: merge toolbars and their tools. I had a parent form (not a MDI form), which has a toolbar manager, and a customer user control which has its own toolbar and tools, managed by its own toolbar manager. I need to merge the toolbars of customer tot he parent form toolbar, which I did in the Microsoft Window Forms. In my parent form I was able to get customer toolbars, merged and displayed in the parent form. But the tools that were in the customer toolbar were not been carried over. Here is the code snip
foreach (UltraToolbar toolbar in toolbars) //toolbars is the customer toolbars getting from customer toolbar manager.
{
string key = toolbar.Key;
manager.Toolbars.AddToolbar(key); //manager is parent form toolbar manager.
}
Before calling AddToolbar,I could see that tools is in the toolbar (not merged yet), but after the call, I debug into the manager, zero tool in the merged toolbar.
After rading the forum I undersatand that I need to recreate the tools in order to merge the toolbars. In our case recreate the tools has to be the modules responsibility since module is responsible to handle the tool’s events, and quit often the modules are developed in the different site of organization. The way the module developer will do is recreate the toolbars and its tools, hook the event handler to the tools then pass the toobars to the host form. But no simple clone or copy of tools, as described in the forum, put the greate burden on the module developers, as tools can be buttons, combobox, ect. Is there a way we can dettach the customer toolbar from the customer toolbar manager, then pass over to the parent form manager?