protected virtual void CreateItem(Ribbon ribbon, RibbonItemCollection collection, Type t) { IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null && collection != null && ribbon != null) { DesignerTransaction transaction = host.CreateTransaction("AddRibbonItem_" + Component.Site.Name); MemberDescriptor member = TypeDescriptor.GetProperties(Component)["Items"]; base.RaiseComponentChanging(member); RibbonItem item = host.CreateComponent(t) as RibbonItem; if (!(item is RibbonSeparator)) { item.Text = item.Site.Name; } collection.Add(item); ribbon.OnRegionsChanged(); base.RaiseComponentChanged(member, null, null); transaction.Commit(); } }
/// <summary> /// Catches the event of a component on the ribbon being removed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void changeService_ComponentRemoved(object sender, ComponentEventArgs e) { RibbonTab tab = e.Component as RibbonTab; RibbonPanel panel = e.Component as RibbonPanel; RibbonItem item = e.Component as RibbonItem; IDesignerHost designerService = GetService(typeof(IDesignerHost)) as IDesignerHost; if (tab != null) { Ribbon.Tabs.Remove(tab); } else if (panel != null) { panel.OwnerTab.Panels.Remove(panel); } else if (item != null) { if (item.Canvas is RibbonOrbDropDown) { Ribbon.OrbDropDown.HandleDesignerItemRemoved(item); } else if (item.OwnerItem is RibbonItemGroup) { (item.OwnerItem as RibbonItemGroup).Items.Remove(item); } else if (item.OwnerPanel != null) { item.OwnerPanel.Items.Remove(item); } else if (Ribbon.QuickAcessToolbar.Items.Contains(item)) { Ribbon.QuickAcessToolbar.Items.Remove(item); } } RemoveRecursive(e.Component as IContainsRibbonComponents, designerService); SelectedElement = null; Ribbon.OnRegionsChanged(); }