Example #1
0
        public static void ResolveState(this CommandState state, WorkspaceTypes_e ws, IXApplication app)
        {
            var curSpace = WorkspaceTypes_e.NoDocuments;

            var activeDoc = app.Documents.Active;

            if (activeDoc == null)
            {
                curSpace = WorkspaceTypes_e.NoDocuments;
            }
            else
            {
                if (activeDoc is IXPart)
                {
                    curSpace = WorkspaceTypes_e.Part;
                }
                else if (activeDoc is IXAssembly)
                {
                    curSpace = WorkspaceTypes_e.Assembly;
                }
                else if (activeDoc is IXDrawing)
                {
                    curSpace = WorkspaceTypes_e.Drawing;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            state.Enabled = ws.HasFlag(curSpace);
        }
Example #2
0
        private WorkspaceTypes_e GetWorkspace(MacroScope_e scope)
        {
            WorkspaceTypes_e workspace = 0;

            if (scope.HasFlag(MacroScope_e.Application))
            {
                workspace |= WorkspaceTypes_e.NoDocuments;
            }

            if (scope.HasFlag(MacroScope_e.Part))
            {
                workspace |= WorkspaceTypes_e.Part;
            }

            if (scope.HasFlag(MacroScope_e.Assembly))
            {
                workspace |= WorkspaceTypes_e.Assembly;
            }

            if (scope.HasFlag(MacroScope_e.Drawing))
            {
                workspace |= WorkspaceTypes_e.Drawing;
            }

            return(workspace);
        }
Example #3
0
        private CommandTab GetTab(string tabName, WorkspaceTypes_e workspace, TabCommandGroupInfo[] tabGroups, out bool matches)
        {
            swDocumentTypes_e docType;

            switch (workspace)
            {
            case WorkspaceTypes_e.Part:
                docType = swDocumentTypes_e.swDocPART;
                break;

            case WorkspaceTypes_e.Assembly:
                docType = swDocumentTypes_e.swDocASSEMBLY;
                break;

            case WorkspaceTypes_e.Drawing:
                docType = swDocumentTypes_e.swDocDRAWING;
                break;

            default:
                throw new NotSupportedException();
            }

            var cmdTab = CmdMgr.GetCommandTab((int)docType, tabName);

            if (cmdTab != null)
            {
                if (!IsCommandTabContainingGroups(cmdTab, tabGroups))
                {
                    m_Logger.Log($"Tab '{tabName}' in {workspace} is changed", LoggerMessageSeverity_e.Debug);

                    if (!TryClearTab(tabName, docType, ref cmdTab))
                    {
                        throw new Exception($"Failed to remove tab '{tabName}' in {workspace}");
                    }

                    matches = false;
                }
                else
                {
                    m_Logger.Log($"Tab '{tabName}' in {workspace} is not changed", LoggerMessageSeverity_e.Debug);

                    matches = true;
                }
            }
            else
            {
                m_Logger.Log($"Tab '{tabName}' in {workspace} does not exist", LoggerMessageSeverity_e.Debug);

                matches = false;
                cmdTab  = CmdMgr.AddCommandTab((int)docType, tabName);
            }

            if (cmdTab == null)
            {
                throw new Exception($"Failed to create tab '{tabName}' in {workspace}");
            }

            return(cmdTab);
        }
 /// <inheritdoc cref="CommandItemInfoAttribute(bool, bool, WorkspaceTypes_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</see>.
 /// This option is applicable when 'showInCmdTabBox' is set to true</param>
 public CommandItemInfoAttribute(bool hasMenu, bool hasToolbar, WorkspaceTypes_e suppWorkspaces,
                                 bool showInCmdTabBox, RibbonTabTextDisplay_e textStyle = RibbonTabTextDisplay_e.TextBelow)
 {
     HasMenu                   = hasMenu;
     HasToolbar                = hasToolbar;
     SupportedWorkspaces       = suppWorkspaces;
     ShowInCommandTabBox       = showInCmdTabBox;
     CommandTabBoxDisplayStyle = textStyle;
 }
Example #5
0
        private void CreateTabInWorkspace(string tabName, WorkspaceTypes_e workspace, TabCommandGroupInfo[] tabGroups)
        {
            var cmdTab = GetTab(tabName, workspace, tabGroups, out bool matches);

            if (!matches)
            {
                foreach (var tabGroup in tabGroups)
                {
                    var tabBox = cmdTab.AddCommandTabBox();

                    var cmdIds   = tabGroup.Commands.Select(c => c.CommandId).ToArray();
                    var txtTypes = tabGroup.Commands.Select(c => (int)ConvertTextDisplay(c.TextStyle)).ToArray();

                    if (!tabBox.AddCommands(cmdIds, txtTypes))
                    {
                        m_Logger.Log($"Failed to add commands to commands tab box {tabName} for document type {workspace}", LoggerMessageSeverity_e.Error);
                    }
                }
            }
        }
 /// <inheritdoc cref="CommandItemInfoAttribute(WorkspaceTypes_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, WorkspaceTypes_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(WorkspaceTypes_e suppWorkspaces)
     : this(true, true, suppWorkspaces)
 {
 }