private CommandGroup GetRootCommandGroup(ICommandGroupSpec cmdBar) { var root = cmdBar; while (root.Parent != null) { root = root.Parent; } return(m_CommandGroups[root]); }
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; } } }
private string GetMenuPath(ICommandGroupSpec cmdBar) { var title = new StringBuilder(); var parent = cmdBar.Parent; while (parent != null) { title.Insert(0, parent.Title + SUB_GROUP_SEPARATOR); parent = parent.Parent; } title.Append(cmdBar.Title); return(title.ToString()); }
private CommandGroup AddCommandGroupOrContextMenu(ICommandGroupSpec cmdBar, bool isContextMenu, swSelectType_e contextMenuSelectType) { Logger.Log($"Creating command group: {cmdBar.Id}"); if (m_CommandGroups.Keys.FirstOrDefault(g => g.Id == cmdBar.Id) != null) { throw new GroupIdAlreadyExistsException(cmdBar); } var title = GetMenuPath(cmdBar); var cmdGroup = CreateCommandGroup(cmdBar.Id, title, cmdBar.Tooltip, cmdBar.Commands.Select(c => c.UserId).ToArray(), isContextMenu, contextMenuSelectType); m_CommandGroups.Add(cmdBar, cmdGroup); using (var iconsConv = new IconsConverter()) { CreateIcons(cmdGroup, cmdBar, iconsConv); var createdCmds = CreateCommandItems(cmdGroup, cmdBar.Id, cmdBar.Commands); var tabGroup = GetRootCommandGroup(cmdBar); try { CreateCommandTabBox(tabGroup, createdCmds); } catch (Exception ex) { Logger.Log(ex); //not critical error - continue operation } } return(cmdGroup); }
public CommandGroup AddContextMenu(ICommandGroupSpec cmdBar, swSelectType_e contextMenuSelectType = swSelectType_e.swSelEVERYTHING) { return(AddCommandGroupOrContextMenu( cmdBar, true, contextMenuSelectType)); }
public CommandGroup AddCommandGroup(ICommandGroupSpec cmdBar) { return(AddCommandGroupOrContextMenu( cmdBar, false, 0)); }
internal GroupIdAlreadyExistsException(ICommandGroupSpec cmdBar) : base($"Group {cmdBar.Title} id ({cmdBar.Id}) already exists. Make sure that all group enumerators decorated with {typeof(CommandGroupInfoAttribute)} have unique values for id") { }