Hi Edhy,
Please find answers below:-
1) In order for you to hide a tab or group, in the RBS are you creating a Permission for each Tab and also each form?
Each form has a permission as does each tab. The groups don't have permissions but will be hidden if all of the tools within the group are hidden. Even though the tabs have permissions, the tabs will also be automatically hidden if all groups are hidden. The only reason I added a permission to each Tab was to give a quick and easy way of turning off the complete tab without having to individually turn off each tool - which could have been a big task if you use popup menu tools with many nested layers. Having a tab permission means I can turn it off with a single click.
2) At design, are you assigning the ToolItems to the Tabs?
Yes, I build the ribbon as normal at design time and all ToolItems are added to the correct tabs and groups. The only extra step at this stage is I use the tool.SharedProps.Tag property to store the form name that will be launched when a user clicks the tool. I have a small general purpose routine which simply checks the tag and calls the form rather than having a separate click method for each tool/form.
The Tag property is also used during the security check to determine if the tool is visible. I use a strict naming convention for form permissions:- "Is" + FormName + "Enabled". For example, a form called "Customer" would have a permission called "IsCustomerEnabled". A ToolItem which launches the customer form will have a Tag of "Customer" so this gives me both the form name and also allows me to work out the correct permission to check. I also have a special value for the Tag property if I don't want a security check for a specific tool and that is "NoSecurityCheck".
I wanted to have the option of having several tools which load the same form which is why I use the Tag property rather than assuming the ToolItem will be called the same name as the form.
3) At runtime, are you looping through the security RBS records to load the ToolItems, or are you looping all the ribbon Tabs and checking the security for each to load the ToolItems?
The ToolItems have already been loaded into the correct tabs and groups at designtime. I have a routine called CheckMenuRibbonSecurity which runs once during initialization and removes tools which are denied based on permissions. This method does the following:-
1. It checks the Tag property of all tools in the ultraToolbarsManager.Tools collection. If the tag is "NoSecurityCheck" then the tool is allowed to remain visible. If the tag contains a form name then I check the "Is" + FormName + "Enabled" permission. If disallowed, then the tool is hidden.
2. Hidden tools still appear in the Application Menu and Groups in a disabled state so they must still be removed. The routine scans through all tools in the ultraToolbarsManager.Ribbon.ApplicationMenu.ToolAreaLeft.Tools collection. Hidden controls are then removed by calling the ultraToolbarsManager.Ribbon.ApplicationMenu.ToolAreaLeft.Tools.Remove() method. Please note it is vital to scan through the tool collection from last to first to avoid the Remove command from confusing your scan, i.e. if you have 10 tools then check and remove the 10th before moving to the 9th and so on.
3. Each tab is checked. If it's permission is denied then the whole tab is hidden simply by setting the visible property. If the tab is allowed, then the routine will scan through all groups within the ultraToolbarsManager1.Ribbon.Tabs.Groups collection. For each group, the group's Tools collection is scanned and any hidden tools are removed using the same technique as in point 2. If all tools are removed from a group, then the group is removed using Remove(). If there are no groups within a tab because they have all been removed, then the tab is hidden. Again, it is vital to scan through the group and tool collections in reverse order. If not, then you will get some weird results
Please note that one side-effect of using the security system is an "Administrator" sees all tool items as an administrator always passes security checks.
In effect, I am simply setting up the ribbon at designtime and removing denied tools at runtime. Allowed tools don't require any additional action as they are already on the ribbon in a visible state.
Please let me know if you have any other questions.
Aaron