Пример #1
0
        private void VisibilityChanged(object sender, EventArgs e)
        {
            RibbonCommandButton cmd    = (RibbonCommandButton)sender;
            RibbonButton        button = (RibbonButton)cmd.Tag;

            SetVisibiblity(button, cmd);
        }
Пример #2
0
        private void EnabledChanged(object sender, EventArgs e)
        {
            RibbonCommandButton cmd    = (RibbonCommandButton)sender;
            RibbonButton        button = (RibbonButton)cmd.Tag;

            SetEnabled(button, cmd);
        }
Пример #3
0
        public static void AddRibbonBigButtons_Method()
        {
            Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                CustomizationSection cs = new CustomizationSection((string)MgdAcApplication.GetSystemVariable("MENUNAME"));
                string curWorkspace     = (string)MgdAcApplication.GetSystemVariable("WSCURRENT");

                RibbonPanelSource panelSrc = AddRibbonPanelToTab(cs, "ANAW", "AcadNetAddinWizard2");
                MacroGroup        macGroup = cs.MenuGroup.MacroGroups[0];

                RibbonRow row = new RibbonRow();
                panelSrc.Items.Add((RibbonItem)row);

                RibbonCommandButton button1 = new RibbonCommandButton(row);
                button1.Text = "Button 1";
                MenuMacro menuMac1 = macGroup.CreateMenuMacro("Button1_Macro", "^C^CButton1_Command ", "Button1_Tag", "Button1_Help",
                                                              MacroType.Any, "ANAW_16x16.bmp", "ANAW_32x32.bmp", "Button1_Label_Id");
                button1.MacroID      = menuMac1.ElementID;
                button1.ButtonStyle  = RibbonButtonStyle.LargeWithText;
                button1.KeyTip       = "Button1 Key Tip";
                button1.TooltipTitle = "Button1 Tooltip Title!";
                row.Items.Add((RibbonItem)button1);

                RibbonCommandButton button2 = new RibbonCommandButton(row);
                button2.Text = "Button 2";
                MenuMacro menuMac2 = macGroup.CreateMenuMacro("Button2_Macro", "^C^CButton2_Command ", "Button2_Tag", "Button2_Help",
                                                              MacroType.Any, "ANAW_16x16.bmp", "ANAW_32x32.bmp", "Button2_Label_Id");
                button2.MacroID      = menuMac2.ElementID;
                button2.ButtonStyle  = RibbonButtonStyle.LargeWithText;
                button2.KeyTip       = "Button2 Key Tip";
                button2.TooltipTitle = "Button2 Tooltip Title!";
                row.Items.Add((RibbonItem)button2);

                RibbonCommandButton button3 = new RibbonCommandButton(row);
                button3.Text = "Button 3";
                MenuMacro menuMac3 = macGroup.CreateMenuMacro("Button3_Macro", "^C^CButton3_Command ", "Button3_Tag", "Button3_Help",
                                                              MacroType.Any, "ANAW_16x16.bmp", "ANAW_32x32.bmp", "Button3_Label_Id");
                button3.MacroID      = menuMac3.ElementID;
                button3.ButtonStyle  = RibbonButtonStyle.LargeWithText;
                button3.KeyTip       = "Button3 Key Tip";
                button3.TooltipTitle = "Button3 Tooltip Title!";
                row.Items.Add((RibbonItem)button3);

                cs.Save();
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(Environment.NewLine + ex.Message);
            }
        }
Пример #4
0
        public static RibbonCommandButton AddNewButton(
            this RibbonRow instance,
            string text,
            string commandFriendlyName,
            string command,
            string commandDescription,
            string smallImagePath,
            string largeImagePath,
            RibbonButtonStyle style)
        {
            var customizationSection = instance.CustomizationSection;
            var macroGroups          = customizationSection.MenuGroup.MacroGroups;

            MacroGroup macroGroup;

            if (macroGroups.Count == 0)
            {
                macroGroup = new MacroGroup("MacroGroup", customizationSection.MenuGroup);
            }
            else
            {
                macroGroup = macroGroups[0];
            }

            var button = new RibbonCommandButton(instance);

            button.Text = text;

            var commandMacro = "^C^C_" + command;
            var commandId    = "ID_" + command;
            var buttonId     = "btn" + command;
            var labelId      = "lbl" + command;

            var menuMacro = macroGroup.CreateMenuMacro(commandFriendlyName,
                                                       commandMacro,
                                                       commandId,
                                                       commandDescription,
                                                       MacroType.Any,
                                                       smallImagePath,
                                                       largeImagePath,
                                                       labelId);
            var macro = menuMacro.macro;

            /*Associate custom command to ribbonbutton macro*/
            macro.CLICommand = command;

            button.MacroID     = menuMacro.ElementID;
            button.ButtonStyle = style;
            instance.Items.Add(button);

            return(button);
        }
Пример #5
0
 private void ExecuteRibbonCommandButton(RibbonCommandButton cmd, bool parmReq)
 {
     if (cmd != null && cmd.CanExecute(null))
     {
         if (parmReq)
         {
             cmd.Execute(_invoiceView);
         }
         else
         {
             cmd.Execute(null);
         }
     }
 }
Пример #6
0
        public static void AddCommandButtonToRibbonSplitButton(MacroGroup macroGroup, RibbonSplitButton splitButton, string buttonText, string command, string smallBitmapPath, string largeBitmapPath, string toolTip)
        {
            MenuMacro menuMacro = macroGroup.CreateMenuMacro(command + "_Macro", "^C^C" + command, command + "_Tag", command + "_Help", MacroType.Any, smallBitmapPath, largeBitmapPath, command + "_Label_Id");

            var button = new RibbonCommandButton(splitButton);

            button.MacroID      = menuMacro.ElementID;
            button.Text         = buttonText;
            button.ButtonStyle  = RibbonButtonStyle.SmallWithoutText;
            button.KeyTip       = buttonText + " Key Tip";
            button.TooltipTitle = toolTip;

            splitButton.Items.Add(button);
        }
Пример #7
0
        private void RegisterCommand(RibbonButton button, RibbonCommandButton cmd, bool parmRequ = false)
        {
            string msg = "Registering: " + button.Name + ", visible=" + button.Visible + ", parent=" + button.Parent.Name;

            Log.TraceWrite(CallerInfo.Create(), msg);

            _ribbonCommands.Add(button.Id, new RibbonCommandBinding()
            {
                Button           = button,
                Command          = cmd,
                Id               = button.Id,
                PropagateInvoice = parmRequ
            });
            button.Click          += button_Click;
            cmd.CanExecuteChanged += EnabledChanged;
            cmd.Tag = button;
            cmd.VisibilityChanged += VisibilityChanged;
            button.Enabled         = cmd.CanExecute(null);
        }
Пример #8
0
 private void SetVisibiblity(RibbonButton button, RibbonCommandButton cmd)
 {
     button.Visible = cmd.IsVisible(null);
 }
Пример #9
0
 private void SetEnabled(RibbonButton button, RibbonCommandButton cmd)
 {
     button.Enabled = cmd.CanExecute(null);
 }
Пример #10
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);
        }