private void LoadButtons(ITaskpaneView taskPaneView, ISldWorks app) { if (Spec.Buttons?.Any() == true) { using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>()) { foreach (var btn in Spec.Buttons) { var tooltip = btn.Tooltip; if (string.IsNullOrEmpty(tooltip)) { tooltip = btn.Title; } if (btn.StandardIcon.HasValue) { if (!taskPaneView.AddStandardButton((int)btn.StandardIcon, tooltip)) { throw new InvalidOperationException($"Failed to add standard button for '{tooltip}'"); } } else { var icon = btn.Icon; if (icon == null) { icon = Defaults.Icon; } //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands if (app.SupportsHighResIcons(CompatibilityUtils.HighResIconsScope_e.TaskPane)) { var imageList = iconsConv.ConvertIcon(new CommandGroupHighResIcon(icon)); if (!taskPaneView.AddCustomButton2(imageList, tooltip)) { throw new InvalidOperationException($"Failed to create task pane button for '{tooltip}' with highres icon"); } } else { var imagePath = iconsConv.ConvertIcon(new CommandGroupIcon(icon)).First(); if (!taskPaneView.AddCustomButton(imagePath, tooltip)) { throw new InvalidOperationException($"Failed to create task pane button for {tooltip}"); } } } } } } }
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; }