private void OnClearGroups(object sender, EventArgs e)
{
if ((_ribbonTab != null) &&
(_ribbonTab.Ribbon != null) &&
_ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab))
{
// Use a transaction to support undo/redo actions
DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab ClearGroups");
try
{
// Get access to the Groups property
MemberDescriptor propertyGroups = TypeDescriptor.GetProperties(_ribbonTab)["Groups"];
RaiseComponentChanging(propertyGroups);
// Need access to host in order to delete a component
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
// We need to remove all the groups from the tab
for (int i = _ribbonTab.Groups.Count - 1; i >= 0; i--)
{
KryptonRibbonGroup group = _ribbonTab.Groups[i];
_ribbonTab.Groups.Remove(group);
host.DestroyComponent(group);
}
RaiseComponentChanged(propertyGroups, null, null);
}
finally
{
// If we managed to create the transaction, then do it
if (transaction != null)
transaction.Commit();
}
}
}