public static RibbonPanelSource AddRibbonPanelToTab(CustomizationSection cs, string tabName, string panelName) { RibbonRoot root = cs.MenuGroup.RibbonRoot; RibbonPanelSourceCollection panels = root.RibbonPanelSources; foreach (RibbonTabSource rts in root.RibbonTabSources) { if (rts.Name == tabName) { //Create the ribbon panel source and add it to the ribbon panel source collection RibbonPanelSource panelSrc = new RibbonPanelSource(root); panelSrc.Text = panelSrc.Name = panelName; panelSrc.ElementID = panelSrc.Id = panelName + "_PanelSourceID"; panels.Add(panelSrc); //Create the ribbon panel source reference and add it to the ribbon panel source reference collection RibbonPanelSourceReference ribPanelSourceRef = new RibbonPanelSourceReference(rts); ribPanelSourceRef.PanelId = panelSrc.ElementID; rts.Items.Add(ribPanelSourceRef); return(panelSrc); } } return(null); }
public static void CreateRibbonTabAndPanel(CustomizationSection cs, string toWorkspace, string tabName, string panelName) { RibbonRoot root = cs.MenuGroup.RibbonRoot; RibbonPanelSourceCollection panels = root.RibbonPanelSources; //Create The Ribbon Button MacroGroup macroGroup = new MacroGroup("MM19macroGroup", cs.MenuGroup); MenuMacro macroLine = macroGroup.CreateMenuMacro("TestLine", "^C^C_Line", "ID_MyLineCmd", "My Line help", MacroType.Any, "RCDATA_16_LINE", "RCDATA_32_LINE", "My Test Line"); //Create the ribbon panel source and add it to the ribbon panel source collection RibbonPanelSource panelSrc = new RibbonPanelSource(root); panelSrc.Text = panelSrc.Name = panelName; panelSrc.ElementID = panelSrc.Id = panelName + "_PanelSourceID"; panels.Add(panelSrc); //Create the ribbon tab source and add it to the ribbon tab source collection RibbonTabSource tabSrc = new RibbonTabSource(root); tabSrc.Name = tabSrc.Text = tabName; tabSrc.ElementID = tabSrc.Id = tabName + "_TabSourceID"; root.RibbonTabSources.Add(tabSrc); //Create the ribbon panel source reference and add it to the ribbon panel source reference collection RibbonPanelSourceReference ribPanelSourceRef = new RibbonPanelSourceReference(tabSrc) { PanelId = panelSrc.ElementID }; tabSrc.Items.Add(ribPanelSourceRef); // Create a ribbon row RibbonRow ribRow = new RibbonRow(ribPanelSourceRef); panelSrc.Items.Add(ribRow); //Create a Ribbon Command Button RibbonCommandButton ribCommandButton = new RibbonCommandButton(ribRow) { Text = "MyTestLineButton", MacroID = macroLine.ElementID, }; ribCommandButton.ButtonStyle = RibbonButtonStyle.LargeWithText; ribRow.Items.Add(ribCommandButton); //Create the workspace ribbon tab source reference WSRibbonTabSourceReference tabSrcRef = WSRibbonTabSourceReference.Create(tabSrc); //Get the ribbon root of the workspace int curWsIndex = cs.Workspaces.IndexOfWorkspaceName(toWorkspace); WSRibbonRoot wsRibbonRoot = cs.Workspaces[curWsIndex].WorkspaceRibbonRoot; //Set the owner of the ribbon tab source reference and add it to the workspace ribbon tab collection tabSrcRef.SetParent(wsRibbonRoot); wsRibbonRoot.WorkspaceTabs.Add(tabSrcRef); }