private void SetupUI()
        {
            int errors = 0;
            // gather up the icons
            string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
            // create command group
            ICommandGroup commandGroup = _cmdMgr.CreateCommandGroup2(_mainCmdGrpId, "Custom Addin", "My custom add-in", "", -1, true, ref errors);

            // set the icon lists
            commandGroup.IconList     = new string[] { System.IO.Path.Combine(folder, "Icons", "icons.bmp") };
            commandGroup.MainIconList = new string[] { System.IO.Path.Combine(folder, "Icons", "icons.bmp") };

            // add the commands to the command group
            // this is just an example for demo purposes***
            List <int> commandItems = new List <int>();

            for (int i = 0; i < 10; i++)
            {
                // you wouldn't add your commands like this.
                // you would obviously create them one at a time
                // for example, in this demo, we're adding 10 commands, but they all call the same method ExucuteAction... that would be a dumb addin
                commandItems.Add(commandGroup.AddCommandItem2("Action " + i, -1, "Action " + i, "Action " + i, i, "ExecuteAction", "CanExecuteAction", _menuItemId1 + i, (int)swCommandItemType_e.swMenuItem | (int)swCommandItemType_e.swToolbarItem));
            }

            // activate command group
            commandGroup.HasToolbar = true;
            commandGroup.HasMenu    = true;
            commandGroup.Activate();

            // create the command tab
            foreach (int docType in new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocPART, (int)swDocumentTypes_e.swDocDRAWING })
            {
                ICommandTab commandTab = _cmdMgr.GetCommandTab(docType, "Custom Addin");

                if (commandTab != null)
                {
                    // recreate the command tab
                    _cmdMgr.RemoveCommandTab((CommandTab)commandTab);
                    commandTab = null;
                }

                // add the command tab
                commandTab = _cmdMgr.AddCommandTab(docType, "Custom Addin");
                // create a command box
                ICommandTabBox commandTabBox = commandTab.AddCommandTabBox();
                // add commands to command tab
                List <int> cmds      = new List <int>();
                List <int> textTypes = new List <int>();
                foreach (var cmdItem in commandItems)
                {
                    cmds.Add(commandGroup.CommandID[cmdItem]);
                    textTypes.Add((int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow);
                }
                bool result = commandTabBox.AddCommands(cmds.ToArray(), textTypes.ToArray());

                commandTab.AddSeparator((CommandTabBox)commandTabBox, cmds.First());
            }
        }
Esempio n. 2
0
        private bool IsCommandTabContainingGroups(ICommandTab cmdTab, TabCommandGroupInfo[] tabGroups)
        {
            var tabBoxes = (object[])cmdTab.CommandTabBoxes();

            if (tabBoxes != null && tabBoxes.Length == tabGroups.Length)
            {
                for (int i = 0; i < tabBoxes.Length; i++)
                {
                    if (!IsCommandTabBoxMatchingGroup((ICommandTabBox)tabBoxes[i], tabGroups[i]))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        private CommandTabBox TryFindCommandTabBox(ICommandTab cmdTab, int[] cmdIds)
        {
            var cmdBoxesArr = cmdTab.CommandTabBoxes() as object[];

            if (cmdBoxesArr != null)
            {
                var cmdBoxes = cmdBoxesArr.Cast <CommandTabBox>().ToArray();

                var cmdBoxGroup = cmdBoxes.GroupBy(b =>
                {
                    object existingCmds;
                    object existingTextStyles;
                    b.GetCommands(out existingCmds, out existingTextStyles);

                    if (existingCmds is int[])
                    {
                        return(((int[])existingCmds).Intersect(cmdIds).Count());
                    }
                    else
                    {
                        return(0);
                    }
                }).OrderByDescending(g => g.Key).FirstOrDefault();

                if (cmdBoxGroup != null)
                {
                    if (cmdBoxGroup.Key > 0)
                    {
                        return(cmdBoxGroup.FirstOrDefault());
                    }
                }

                return(null);
            }

            return(null);
        }