public SketchCommandItemInfoAttribute(bool hasMenu, bool hasToolbar,
                                       swWorkspaceTypes_e suppWorkspaces, Type baseHandlerType, Type handlerType)
     : base(hasMenu, hasToolbar, suppWorkspaces)
 {
     BaseHandlerType = baseHandlerType;
     HandlerType     = handlerType;
 }
 /// <inheritdoc cref="CommandItemInfoAttribute(bool, bool, swWorkspaceTypes_e)"/>
 /// <param name="showInCmdTabBox">Indicates that this command should be added to command tab box in command manager (ribbon)</param>
 /// <param name="textStyle">Text display type for command in command tab box as defined in <see href="https://help.solidworks.com/2012/English/api/swconst/SolidWorks.Interop.swconst~SolidWorks.Interop.swconst.swCommandTabButtonTextDisplay_e.html?id=3d6975f51c4648378ad4beaf4d3144ca">swCommandTabButtonTextDisplay_e Enumeration</see>.
 /// This option is applicable when 'showInCmdTabBox' is set to true</param>
 public CommandItemInfoAttribute(bool hasMenu, bool hasToolbar, swWorkspaceTypes_e suppWorkspaces,
                                 bool showInCmdTabBox, swCommandTabButtonTextDisplay_e textStyle = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow)
 {
     HasMenu                   = hasMenu;
     HasToolbar                = hasToolbar;
     SupportedWorkspaces       = suppWorkspaces;
     ShowInCommandTabBox       = showInCmdTabBox;
     CommandTabBoxDisplayStyle = textStyle;
 }
 /// <inheritdoc cref="CommandItemInfoAttribute(swWorkspaceTypes_e)"/>
 /// <param name="hasMenu">Indicates if this command should be displayed in the menu</param>
 /// <param name="hasToolbar">Indicates if this command should be displayed in the toolbar</param>
 public CommandItemInfoAttribute(bool hasMenu, bool hasToolbar, swWorkspaceTypes_e suppWorkspaces)
     : this(hasMenu, hasToolbar, suppWorkspaces, false)
 {
 }
 /// <summary>
 /// Constructor for specifying additional information about command item
 /// </summary>
 /// <param name="suppWorkspaces">Indicates the workspaces where this command is enabled. This information is used in the default command enable handler</param>
 public CommandItemInfoAttribute(swWorkspaceTypes_e suppWorkspaces)
     : this(true, true, suppWorkspaces)
 {
 }
Example #5
0
 public CommandItemInfoAttribute(bool hasMenu, bool hasToolbar, swWorkspaceTypes_e suppWorkspaces)
 {
     HasMenu             = hasMenu;
     HasToolbar          = hasToolbar;
     SupportedWorkspaces = suppWorkspaces;
 }
        private void CreateCommandItems(CommandGroup cmdGroup, int groupId, Enum[] cmds,
                                        Delegate callbackMethod, Delegate enableMethod)
        {
            var callbackMethodName = nameof(OnCommandClick);
            var enableMethodName   = nameof(OnCommandEnable);

            for (int i = 0; i < cmds.Length; i++)
            {
                var cmd = cmds[i];

                var cmdTitle   = "";
                var cmdToolTip = "";
                swCommandItemType_e menuToolbarOpts = 0;
                swWorkspaceTypes_e  suppWorkSpaces  = 0;

                if (!cmd.TryGetAttribute <DisplayNameAttribute>(
                        att => cmdTitle = att.DisplayName))
                {
                    cmdTitle = cmd.ToString();
                }

                if (!cmd.TryGetAttribute <DescriptionAttribute>(
                        att => cmdToolTip = att.Description))
                {
                    cmdToolTip = cmd.ToString();
                }

                if (!cmd.TryGetAttribute <CommandItemInfoAttribute>(
                        att =>
                {
                    if (att.HasMenu)
                    {
                        menuToolbarOpts |= swCommandItemType_e.swMenuItem;
                    }

                    if (att.HasToolbar)
                    {
                        menuToolbarOpts |= swCommandItemType_e.swToolbarItem;
                    }

                    suppWorkSpaces = att.SupportedWorkspaces;
                }))
                {
                    menuToolbarOpts = swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem;
                    suppWorkSpaces  = swWorkspaceTypes_e.All;
                }

                if (menuToolbarOpts == 0)
                {
                    throw new InvalidMenuToolbarOptionsException(cmd);
                }

                var cmdId = Convert.ToInt32(cmd);

                var cmdName = $"{groupId}.{cmdId}";

                m_CachedCmdsEnable.Add(cmdName, suppWorkSpaces);
                m_CallbacksParams.Add(cmdName, new Tuple <Delegate, Enum>(callbackMethod, cmd));

                if (enableMethod != null)
                {
                    m_EnableParams.Add(cmdName, new Tuple <Delegate, Enum>(enableMethod, cmd));
                }

                var callbackFunc = $"{callbackMethodName}({cmdName})";
                var enableFunc   = $"{enableMethodName}({cmdName})";

                cmdGroup.AddCommandItem2(cmdTitle, -1, cmdToolTip,
                                         cmdTitle, i, callbackFunc, enableFunc, cmdId,
                                         (int)menuToolbarOpts);
            }
        }