private void ExtractCommandGroupInfo(Type cmdGroupType, ISldWorks app, Action <TCmdEnum> callback, EnableMethodDelegate <TCmdEnum> enable, int nextGroupId, IEnumerable <ICommandGroupSpec> groups) { CommandGroupInfoAttribute grpInfoAtt; if (cmdGroupType.TryGetAttribute(out grpInfoAtt)) { if (grpInfoAtt.UserId != -1) { Id = grpInfoAtt.UserId; } else { Id = nextGroupId; } if (grpInfoAtt.ParentGroupType != null) { var parentGrpSpec = groups.OfType <EnumCommandGroupSpecBase>() .FirstOrDefault(g => g.CmdGrpEnumType == grpInfoAtt.ParentGroupType); if (parentGrpSpec == null) { //TODO: create a specific exception throw new NullReferenceException("Parent group is not created"); } if (grpInfoAtt.ParentGroupType == cmdGroupType) { throw new InvalidOperationException("Group cannot be a parent of itself"); } Parent = parentGrpSpec; } } else { Id = nextGroupId; } Icon = DisplayInfoExtractor.ExtractCommandDisplayIcon <CommandIconAttribute, CommandGroupIcon>( cmdGroupType, i => new MasterIcon(i), a => a.Icon); if (!cmdGroupType.TryGetAttribute <DisplayNameAttribute>(a => Title = a.DisplayName)) { Title = cmdGroupType.ToString(); } if (!cmdGroupType.TryGetAttribute <DescriptionAttribute>(a => Tooltip = a.Description)) { Tooltip = cmdGroupType.ToString(); } Commands = Enum.GetValues(cmdGroupType).Cast <TCmdEnum>().Select( c => new EnumCommandSpec <TCmdEnum>(app, c, callback, enable)).ToArray(); }
private void ExtractCommandInfo(TCmdEnum cmd) { var cmdEnum = cmd as Enum; UserId = Convert.ToInt32(cmdEnum); if (!cmdEnum.TryGetAttribute <CommandItemInfoAttribute>( att => { HasMenu = att.HasMenu; HasToolbar = att.HasToolbar; SupportedWorkspace = att.SupportedWorkspaces; HasTabBox = att.ShowInCommandTabBox; TabBoxStyle = att.CommandTabBoxDisplayStyle; })) { HasMenu = true; HasToolbar = true; SupportedWorkspace = swWorkspaceTypes_e.All; HasTabBox = false; TabBoxStyle = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow; } HasSpacer = cmdEnum.TryGetAttribute <CommandSpacerAttribute>() != null; if (!cmdEnum.TryGetAttribute <DisplayNameAttribute>( att => Title = att.DisplayName)) { Title = cmd.ToString(); } if (!cmdEnum.TryGetAttribute <DescriptionAttribute>( att => Tooltip = att.Description)) { Tooltip = cmd.ToString(); } Icon = DisplayInfoExtractor.ExtractCommandDisplayIcon <CommandIconAttribute, CommandGroupIcon>( cmdEnum, i => new MasterIcon(i), a => a.Icon); }
/// <inheritdoc/> public ITaskpaneView CreateTaskPane <TControl, TCmdEnum>(Action <TCmdEnum> cmdHandler, out TControl ctrl) where TControl : UserControl, new() where TCmdEnum : IComparable, IFormattable, IConvertible { var tooltip = ""; CommandGroupIcon taskPaneIcon = null; var getTaskPaneDisplayData = new Action <Type, bool>((t, d) => { if (taskPaneIcon == null) { taskPaneIcon = DisplayInfoExtractor.ExtractCommandDisplayIcon <TaskPaneIconAttribute, CommandGroupIcon>( t, i => new TaskPaneMasterIcon(i), a => a.Icon, d); } if (string.IsNullOrEmpty(tooltip)) { if (!t.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName)) { t.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description); } } }); if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e)) { getTaskPaneDisplayData.Invoke(typeof(TCmdEnum), false); } getTaskPaneDisplayData.Invoke(typeof(TControl), true); ITaskpaneView taskPaneView = null; ITaskPaneHandler taskPaneHandler = null; m_Logger.Log($"Creating task pane for {typeof(TControl).FullName} type"); using (var iconConv = new IconsConverter()) { if (App.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane)) { var taskPaneIconImages = iconConv.ConvertIcon(taskPaneIcon, true); taskPaneView = App.CreateTaskpaneView3(taskPaneIconImages, tooltip); } else { var taskPaneIconImage = iconConv.ConvertIcon(taskPaneIcon, false)[0]; taskPaneView = App.CreateTaskpaneView2(taskPaneIconImage, tooltip); } taskPaneHandler = new TaskPaneHandler <TCmdEnum>(App, taskPaneView, cmdHandler, iconConv, m_Logger); } if (typeof(TControl).IsComVisible()) { var progId = typeof(TControl).GetProgId(); ctrl = taskPaneView.AddControl(progId, "") as TControl; if (ctrl == null) { throw new NullReferenceException( $"Failed to create COM control from {progId}. Make sure that COM component is properly registered"); } } else { ctrl = new TControl(); ctrl.CreateControl(); var handle = ctrl.Handle; if (!taskPaneView.DisplayWindowFromHandle(handle.ToInt32())) { throw new NullReferenceException($"Failed to host .NET control (handle {handle}) in task pane"); } } taskPaneHandler.Disposed += OnTaskPaneHandlerDisposed; m_TaskPanes.Add(taskPaneHandler); return(taskPaneView); }