private void CreateIcons(CommandGroup cmdGroup, ICommandGroupSpec cmdBar, IIconsConverter iconsConv) { var mainIcon = cmdBar.Icon; CommandGroupIcon[] iconList = null; if (cmdBar.Commands != null) { iconList = cmdBar.Commands.Select(c => c.Icon).ToArray(); } //NOTE: if commands are not used, main icon will fail if toolbar commands image list is not specified, so it is required to specify it explicitly if (App.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.CommandManager)) { var iconsList = iconsConv.ConvertIcon(mainIcon, true); cmdGroup.MainIconList = iconsList; if (iconList != null && iconList.Any()) { cmdGroup.IconList = iconsConv.ConvertIconsGroup(iconList, true); } else { cmdGroup.IconList = iconsList; } } else { var mainIconPath = iconsConv.ConvertIcon(mainIcon, false); var smallIcon = mainIconPath[0]; var largeIcon = mainIconPath[1]; cmdGroup.SmallMainIcon = smallIcon; cmdGroup.LargeMainIcon = largeIcon; if (iconList != null && iconList.Any()) { var iconListPath = iconsConv.ConvertIconsGroup(iconList, true); var smallIconList = iconListPath[0]; var largeIconList = iconListPath[1]; cmdGroup.SmallIconList = smallIconList; cmdGroup.LargeIconList = largeIconList; } else { cmdGroup.SmallIconList = smallIcon; cmdGroup.LargeIconList = largeIcon; } } }
internal TaskPaneHandler(ISldWorks app, ITaskpaneView taskPaneView, Action <TCmdEnum> cmdHandler, IIconsConverter iconsConv, ILogger logger) { m_Logger = logger; m_TaskPaneView = taskPaneView; m_CmdHandler = cmdHandler; if (!typeof(TCmdEnum).IsEnum) { throw new ArgumentException($"{typeof(TCmdEnum)} must be an enumeration"); } if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e) && cmdHandler != null) { var enumValues = Enum.GetValues(typeof(TCmdEnum)); m_Commands = enumValues.Cast <TCmdEnum>().ToArray(); foreach (Enum cmdEnum in enumValues) { //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands var icon = DisplayInfoExtractor.ExtractCommandDisplayIcon <CommandIconAttribute, CommandGroupIcon>( cmdEnum, i => new MasterIcon(i), a => a.Icon); var tooltip = ""; if (!cmdEnum.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName)) { cmdEnum.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description); } if (!cmdEnum.TryGetAttribute <TaskPaneStandardButtonAttribute>(a => { if (!m_TaskPaneView.AddStandardButton((int)a.Icon, tooltip)) { throw new InvalidOperationException($"Failed to add standard button for {cmdEnum}"); } })) { if (app.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane)) { var imageList = iconsConv.ConvertIcon(icon, true); if (!m_TaskPaneView.AddCustomButton2(imageList, tooltip)) { throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum} with highres icon"); } } else { var imagePath = iconsConv.ConvertIcon(icon, false)[0]; if (!m_TaskPaneView.AddCustomButton(imagePath, tooltip)) { throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum}"); } } } } (m_TaskPaneView as TaskpaneView).TaskPaneToolbarButtonClicked += OnTaskPaneToolbarButtonClicked; } (m_TaskPaneView as TaskpaneView).TaskPaneDestroyNotify += OnTaskPaneDestroyNotify; }