示例#1
0
        private void CreateCommandTab(CommandGroup commandGroup, bool groupExistsInRegistry, bool ignorePrevious, Dictionary <int, int> commandsDictionary)
        {
            var docTypes = new int[] { (int)swDocumentTypes_e.swDocPART,
                                       (int)swDocumentTypes_e.swDocASSEMBLY,
                                       (int)swDocumentTypes_e.swDocDRAWING };

            foreach (var docType in docTypes)
            {
                var commandTab = CommandManager.GetCommandTab(docType, SolidWorksAddin.AddinTitle);

                if (commandTab != null && !groupExistsInRegistry || ignorePrevious)
                {
                    CommandManager.RemoveCommandTab(commandTab);
                    commandTab = null;
                }

                if (commandTab == null)
                {
                    commandTab = CommandManager.AddCommandTab(docType, SolidWorksAddin.AddinTitle);

                    var commandTabBoxDoc    = commandTab.AddCommandTabBox();
                    var commandDocIds       = new int[4];
                    var commandDocTextTypes = new int[4];

                    commandDocIds[0]       = commandGroup.get_CommandID(commandsDictionary[_generateNewIdCmdId]);
                    commandDocTextTypes[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

                    commandDocIds[1]       = commandGroup.get_CommandID(commandsDictionary[_saveWithNewIdCmdId]);
                    commandDocTextTypes[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

                    commandDocIds[2]       = commandGroup.get_CommandID(commandsDictionary[_saveWithNewIdAndUploadCmdId]);
                    commandDocTextTypes[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

                    commandDocIds[3]       = commandGroup.get_CommandID(commandsDictionary[_deleteDocument]);
                    commandDocTextTypes[3] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

                    commandTabBoxDoc.AddCommands(commandDocIds, commandDocTextTypes);

                    var commandTabBoxTransfer    = commandTab.AddCommandTabBox();
                    var commandTransferIds       = new int[2];
                    var commandTransferTextTypes = new int[2];

                    commandTransferIds[0]       = commandGroup.get_CommandID(commandsDictionary[_saveAndUploadToServerCmdId]);
                    commandTransferTextTypes[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

                    commandTransferIds[1]       = commandGroup.get_CommandID(commandsDictionary[_downloadFromServerCmdId]);
                    commandTransferTextTypes[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;

                    commandTabBoxTransfer.AddCommands(commandTransferIds, commandTransferTextTypes);
                }
            }
        }
示例#2
0
        public void CreerOnglet()
        {
            try
            {
                foreach (eTypeDoc T in Enum.GetValues(typeof(eTypeDoc)))
                {
                    var Liste = new List <List <Cmde> >();

                    // Liste les cmds à afficher dans cet onglet pour ce type de document
                    foreach (var listeCmd in ListeGrp)
                    {
                        var liste = new List <Cmde>();
                        foreach (var Cmd in listeCmd)
                        {
                            if (Cmd.Type.HasFlag(T))
                            {
                                liste.Add(Cmd);
                            }
                        }

                        if (liste.Count > 0)
                        {
                            Liste.Add(liste);
                        }
                    }

                    // Si la liste comprend des cmds
                    if (Liste.Count > 0)
                    {
                        CommandTab cmdTab = CmdMgr.GetCommandTab((int)Sw.eGetSwTypeDoc(T), Titre);
                        if (cmdTab.IsRef())
                        {
                            CmdMgr.RemoveCommandTab(cmdTab);
                        }

                        cmdTab = CmdMgr.AddCommandTab((int)Sw.eGetSwTypeDoc(T), Titre);

                        Boolean sep = false;

                        foreach (var ListeCmd in Liste)
                        {
                            var ListeId       = new List <int>();
                            var ListePosition = new List <int>();

                            // Liste les cmds, on recupère les Id et la position des textes
                            foreach (var Cmd in ListeCmd)
                            {
                                ListeId.Add(Cmd.CommandId);
                                ListePosition.Add((int)Cmd.PositionTexte);
                            }

                            // On ajoute les cmds
                            CommandTabBox cmdBox = cmdTab.AddCommandTabBox();
                            cmdBox.AddCommands(ListeId.ToArray(), ListePosition.ToArray());

                            // Si c'est le deuxième groupe, on ajoute un séparateur
                            // !!!! On ne peut ajouter un séparateur que devant un nouveau CommandTabBox
                            if (sep)
                            {
                                cmdTab.AddSeparator(cmdBox, ListeId[0]);
                            }

                            sep = true;
                        }
                    }
                }
            }
            catch (Exception e)
            { this.LogMethode(new Object[] { e }); }
        }
        private IDisposable AddCommands()
        {
            const int mainCmdGroupId = 5;
            const int mainItemId1    = 0;
            const int mainItemId2    = 1;

            const string title   = "Test execution";
            const string toolTip = "Test execution";


            int[] docTypes = { (int)swDocumentTypes_e.swDocPART };


            var cmdGroupErr    = 0;
            var ignorePrevious = false;

            object registryIDs;
            //get the ID information stored in the registry
            var getDataResult = CommandManager.GetGroupDataFromRegistry(mainCmdGroupId, out registryIDs);

            int[] knownIDs = { mainItemId1, mainItemId2 };

            if (getDataResult)
            {
                if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup
                {
                    ignorePrevious = true;
                }
            }

            var cmdGroup = CommandManager.CreateCommandGroup2(mainCmdGroupId, title, toolTip, "", -1, ignorePrevious,
                                                              ref cmdGroupErr);

            cmdGroup.LargeIconList = GetBitMap("SwCSharpAddinMF.Icons.ToolbarLarge.bmp");
            cmdGroup.SmallIconList = GetBitMap("SwCSharpAddinMF.Icons.ToolbarSmall.bmp");
            cmdGroup.LargeMainIcon = GetBitMap("SwCSharpAddinMF.Icons.MainIconLarge.bmp");
            cmdGroup.SmallMainIcon = GetBitMap("SwCSharpAddinMF.Icons.MainIconSmall.bmp");

            var menuToolbarOption = (int)swCommandItemType_e.swToolbarItem | (int)swCommandItemType_e.swMenuItem;
            var cmdIndex0         = cmdGroup.AddCommandItem2(nameof(ContinueTestExecution), -1,
                                                             "Continue execution of a currently paused test", "Continue test execution", 0, nameof(ContinueTestExecution),
                                                             nameof(CanContinueTestExecution), mainItemId1, menuToolbarOption);

            cmdGroup.HasToolbar = true;
            cmdGroup.HasMenu    = true;
            cmdGroup.Activate();


            foreach (var type in docTypes)
            {
                var cmdTab = CommandManager.GetCommandTab(type, title);

                // if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab.
                // Otherwise the ids won't matchup and the tab will be blank
                if (cmdTab != null & !getDataResult | ignorePrevious)
                {
                    CommandManager.RemoveCommandTab(cmdTab);
                    cmdTab = null;
                }

                //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs
                if (cmdTab != null)
                {
                    continue;
                }

                cmdTab = CommandManager.AddCommandTab(type, title);

                var cmdBox = cmdTab.AddCommandTabBox();

                var cmdIDs = new[] { cmdIndex0 }
                .Select(id => cmdGroup.CommandID[id])
                .ToArray();

                var textType = cmdIDs
                               .Select(id => (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal)
                               .ToArray();

                cmdBox.AddCommands(cmdIDs, textType);
            }

            return(Disposable.Create(() => CommandManager.RemoveCommandGroup(mainCmdGroupId)));
        }