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