Exemple #1
0
        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);
        }
Exemple #2
0
        public static RibbonPanelSource AddRibbonPanel(string tabAlias, string panelAlias, string panelText)
        {
            var        fileName   = Application.GetSystemVariable("MENUNAME") as string;
            var        custSect   = new CustomizationSection(fileName);
            RibbonRoot ribbonRoot = custSect.MenuGroup.RibbonRoot;

            RibbonPanelSource ribbonPanel = ribbonRoot.FindPanelWithAlias(panelAlias);

            if (ribbonPanel != null)
            {
                return(null);
            }

            ribbonPanel = new RibbonPanelSource(ribbonRoot);
            ribbonPanel.Aliases.Add(panelAlias);
            ribbonPanel.Name = panelAlias;
            ribbonPanel.Text = panelText;
            ribbonPanel.Items.Clear();
            ribbonRoot.RibbonPanelSources.Add(ribbonPanel);

            RibbonTabSource tab      = ribbonRoot.FindTabWithAlias(tabAlias);
            var             panelRef = new RibbonPanelSourceReference(tab);

            panelRef.PanelId = ribbonPanel.ElementID;
            tab.Items.Add(panelRef);

            return(ribbonPanel);
        }
Exemple #3
0
        public static bool RemoveRibbonPanel(string tabAlias, string panelAlias, PluginCommandButton[] buttons)
        {
            var        fileName    = Application.GetSystemVariable("MENUNAME") as string;
            var        custSection = new CustomizationSection(fileName);
            RibbonRoot ribbonRoot  = custSection.MenuGroup.RibbonRoot;

            RibbonPanelSource ribbonPanel = ribbonRoot.FindPanelWithAlias(panelAlias);

            if (ribbonPanel == null)
            {
                return(false);
            }

            // Remove command and split buttons,  and panel row
            var row         = ribbonPanel.Items[0] as RibbonRow;
            var splitButton = row.Items[0] as RibbonSplitButton;

            splitButton.Items.Clear();
            splitButton.SetIsModified();

            row.Items.Clear();
            row.SetIsModified();

            ribbonPanel.Items.Clear();
            ribbonPanel.SetIsModified();

            // Remove the reference to panel from Add-ins tab
            RibbonTabSource tab = ribbonRoot.FindTabWithAlias(tabAlias);

            RemoveRibbonPanelSourceReference(tab, ribbonPanel.ElementID);

            RemoveMacrosOfCommandButtons(custSection, buttons);

            ribbonRoot.RibbonPanelSources.Remove(ribbonPanel);
            ribbonRoot.SetIsModified();

            custSection.Save();

            return(true);
        }
Exemple #4
0
        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);
        }