private static void InitializeRibbonTab([NotNull] TabDefinition tab, MainWindow window, Func <string, ImageSource> getImage) { Assert.ArgumentNotNull(tab, nameof(tab)); var name = tab.Name; Assert.IsNotNull(name, nameof(name)); using (new ProfileSection("Initialize ribbon tab")) { ProfileSection.Argument("name", name); var tabName = name + "Tab"; var ribbonTab = window.FindName(tabName) as RibbonTabItem ?? CreateTab(window, name); Assert.IsNotNull(ribbonTab, "Cannot find RibbonTab with {0} name".FormatWith(tabName)); foreach (var group in tab.Groups) { Assert.IsNotNull(group, nameof(group)); // Get Ribbon Group to insert button to name = group.Name; var groupName = tabName + name + "Group"; var ribbonGroup = GetRibbonGroup(name, tabName, groupName, ribbonTab, window); Assert.IsNotNull(ribbonGroup, "Cannot find RibbonGroup with {0} name".FormatWith(groupName)); foreach (var button in group.Buttons) { InitializeRibbonButton(window, getImage, button, ribbonGroup); } } } }
private static void InitializeRibbonTab(XmlElement tabElement, MainWindow window, Func <string, ImageSource> getImage) { var name = tabElement.GetNonEmptyAttribute("name"); if (string.IsNullOrEmpty(name)) { Log.Error($"Ribbon tab doesn't have name: {tabElement.OuterXml}"); return; } using (new ProfileSection("Initialize ribbon tab")) { ProfileSection.Argument("name", name); var tabName = name + "Tab"; var ribbonTab = window.FindName(tabName) as RibbonTabItem ?? CreateTab(window, name); Assert.IsNotNull(ribbonTab, "Cannot find RibbonTab with {0} name".FormatWith(tabName)); var groups = SelectNonEmptyCollection(tabElement, "group"); foreach (XmlElement groupElement in groups) { InitializeRibbonGroup(name, tabName, groupElement, ribbonTab, window, getImage); } } }
private static RibbonGroupBox GetRibbonGroup(string name, string tabName, string groupName, RibbonTabItem ribbonTab, MainWindow window) { using (new ProfileSection("Get ribbon group")) { ProfileSection.Argument("name", name); ProfileSection.Argument("tabName", tabName); ProfileSection.Argument("groupName", groupName); ProfileSection.Argument("ribbonTab", ribbonTab); ProfileSection.Argument("window", window); var ribbonGroup = window.FindName(groupName) as RibbonGroupBox; if (ribbonGroup == null) { var ribbonTabItem = window.FindName(tabName) as RibbonTabItem; if (ribbonTabItem != null) { var ribbonGroupBoxs = ribbonTabItem.Groups; foreach ( var ribbonGroupBox in ribbonGroupBoxs.Where(ribbonGroupBox => ribbonGroupBox.Header.ToString() == name)) { ribbonGroup = ribbonGroupBox; break; } } if (ribbonGroup == null) { ribbonGroup = CreateGroup(ribbonTab, name); } } return(ribbonGroup); } }