/// <summary> /// Helper method to allow awaiting a disposable. This way we can ensure if calling from outside a disposable we await everything currently using the actual group. /// </summary> /// <param name="group"></param> /// <param name="fromDisposable"></param> /// <returns></returns> private bool RemoveCommandGroup(ICommandGroup group, bool fromDisposable) { //TODO: Is this necessary? if (!fromDisposable) { RefCountDisposable holdIt; lock (_gate) holdIt = CommandGroups.GetValueOrDefault(group); if (holdIt == default) { return(false); } if (!holdIt.IsDisposed) { holdIt.Dispose(); } return(true); } lock (_gate) { if (!CommandGroups.ContainsKey(group)) { return(false); } for (; ;) { if (ImmutableInterlocked.Update(ref CommandGroups, (x, y) => x.Remove(y), group)) { break; } } return(true); } }
/* * 实现添加窗口的接口以便添加Command时可以调用,转发到SwAddin实现开实现委托方法 */ public int AddSWCommand(ICommandGroup cmdGroup, string guid, string name, int postion, string hint, string tooltip, int imageListIndex, int commandIndex, int menuOption) { var cmdCallbackFunc = $"{callbackMethodName}({guid})"; var cmdEnableFunc = $"{enableMethodName}({guid})"; return(cmdGroup.AddCommandItem2(name, postion, hint, tooltip, imageListIndex, cmdCallbackFunc, cmdEnableFunc, commandIndex, menuOption)); }
private void SetupUI() { int errors = 0; // gather up the icons string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location); // create command group ICommandGroup commandGroup = _cmdMgr.CreateCommandGroup2(_mainCmdGrpId, "Custom Addin", "My custom add-in", "", -1, true, ref errors); // set the icon lists commandGroup.IconList = new string[] { System.IO.Path.Combine(folder, "Icons", "icons.bmp") }; commandGroup.MainIconList = new string[] { System.IO.Path.Combine(folder, "Icons", "icons.bmp") }; // add the commands to the command group // this is just an example for demo purposes*** List <int> commandItems = new List <int>(); for (int i = 0; i < 10; i++) { // you wouldn't add your commands like this. // you would obviously create them one at a time // for example, in this demo, we're adding 10 commands, but they all call the same method ExucuteAction... that would be a dumb addin commandItems.Add(commandGroup.AddCommandItem2("Action " + i, -1, "Action " + i, "Action " + i, i, "ExecuteAction", "CanExecuteAction", _menuItemId1 + i, (int)swCommandItemType_e.swMenuItem | (int)swCommandItemType_e.swToolbarItem)); } // activate command group commandGroup.HasToolbar = true; commandGroup.HasMenu = true; commandGroup.Activate(); // create the command tab foreach (int docType in new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocPART, (int)swDocumentTypes_e.swDocDRAWING }) { ICommandTab commandTab = _cmdMgr.GetCommandTab(docType, "Custom Addin"); if (commandTab != null) { // recreate the command tab _cmdMgr.RemoveCommandTab((CommandTab)commandTab); commandTab = null; } // add the command tab commandTab = _cmdMgr.AddCommandTab(docType, "Custom Addin"); // create a command box ICommandTabBox commandTabBox = commandTab.AddCommandTabBox(); // add commands to command tab List <int> cmds = new List <int>(); List <int> textTypes = new List <int>(); foreach (var cmdItem in commandItems) { cmds.Add(commandGroup.CommandID[cmdItem]); textTypes.Add((int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow); } bool result = commandTabBox.AddCommands(cmds.ToArray(), textTypes.ToArray()); commandTab.AddSeparator((CommandTabBox)commandTabBox, cmds.First()); } }
public static void AddDemoCommandsForService(ICommandGroup group) { group.TryAdd( new VersaCommand.Builder() { Name = "lookcom", CallLine = "look", Description = "Have a look around.", }.UsingTransientClass <CommandDemoClass>(e => e.DoALook).Build() ); }
/// <summary> /// Get command group /// </summary> /// <param name="commandGroupName">Command group name</param> /// <returns>Command group</returns> public ICommandGroup GetCommandGroup(string commandGroupName) { ICommandGroup ret = miscellaneousCommandGroup; if (commandGroupName != null) { string key = commandGroupName.Trim().ToLower(); if (commandGroups.ContainsKey(key)) { ret = commandGroups[key]; } } return(ret); }
/// <summary> /// Add command group /// </summary> /// <param name="commandGroup">Command group</param> public void AddCommandGroup(ICommandGroup commandGroup) { if (commandGroup != null) { string key = commandGroup.Name.Trim().ToLower(); if (commands.ContainsKey(key)) { commandGroups[key] = commandGroup; } else { commandGroups.Add(key, commandGroup); } } }
/// <summary> /// Get commands from command group /// </summary> /// <param name="commandGroup">Command group</param> /// <returns>Commands from command group</returns> public ICommand[] FromCommandGroup(ICommandGroup commandGroup) { List <ICommand> result = new List <ICommand>(); ICommandGroup command_group = ((commandGroup == null) ? miscellaneousCommandGroup : commandGroup); if (commandGroup != null) { foreach (ICommand command in commands.Values) { if (GetCommandGroup(command.CommandGroup) == command_group) { result.Add(command); } } } ICommand[] ret = result.ToArray(); result.Clear(); return(ret); }
public IDisposable AddCommandGroup(ICommandGroup group) { lock (_gate) { if (!CommandGroups.ContainsKey(group)) { return(CommandGroups[group].GetDisposable()); } var newRefDisposable = new RefCountDisposable(Disposable.Create(() => RemoveCommandGroup(group, true))); for (;;) { if (ImmutableInterlocked.Update(ref CommandGroups, (x, y) => x.Add(y, newRefDisposable), group)) { break; } } return(CommandGroups[group].GetDisposable()); } }
private void AddCmdbox(List <Dictionary <int, KeyValuePair <CommandType, int> > > tabIdList, ref ICommandGroup cmdGroup, ref CommandTab cmdTab) { int index = 0; foreach (var boxIds in tabIdList) { List <int> cmdIDs = new List <int>(); List <int> TextType = new List <int>(); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); foreach (var cmdId in boxIds) { switch (cmdId.Value.Key) { case CommandType.Command: cmdIDs.Add(cmdGroup.get_CommandID(cmdId.Key)); break; case CommandType.FlyoutCommand: cmdIDs.Add(cmdId.Key); break; } TextType.Add(cmdId.Value.Value); index++; } bool result = cmdBox.AddCommands(cmdIDs.ToArray(), TextType.ToArray()); } }
public void AddCommandMgr() { if (iBmp == null) { iBmp = new BitmapHandler(); } Assembly thisAssembly; int cmdIndex0, cmdIndex1; string Title = "CAPP 插件", ToolTip = "CAPP 插件"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; //get the ID information stored in the registry bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs); int[] knownIDs = new int[1] { mainItemID1 }; // new int[2] { mainItemID1, mainItemID2 }; if (getDataResult) { if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup { ignorePrevious = true; } } cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("Kingdee.CAPP.Solidworks.RoutingPlugIn.MainIconSmall.bmp", thisAssembly); int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); //增加菜单 cmdIndex0 = cmdGroup.AddCommandItem2("关联零件到工艺路线", -1, "关联零件到工艺路线", "关联零件到工艺路线", 0, "Routing", "EnableRouting", mainItemID1, menuToolbarOption); cmdIndex1 = cmdGroup.AddCommandItem2("关联草图到工序", -1, "关联草图到工序", "关联草图到工序", 0, "SketchToProcess", "EnableRouting", mainItemID2, menuToolbarOption); //cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption); //cmdIndex1 = cmdGroup.AddCommandItem2("WinFormInFeatureMgr", -1, "Add Windows Form In FeatureManager", "WinFormInFeatureMgr", 2, "WinFormInFeatureMgr", "", mainItemID1, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; //FlyoutGroup flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", // cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable"); //flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1"); //flyGroup.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple; foreach (int type in docTypes) { CommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank { bool res = iCmdMgr.RemoveCommandTab(cmdTab); cmdTab = null; } //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs if (cmdTab == null) { cmdTab = iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[3]; int[] TextType = new int[3]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; //cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.ToolbarId; TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; //cmdIDs[0] = flyGroup.CmdID; TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdIDs[0]); } } thisAssembly = null; }
public bool RemoveCommandGroup(ICommandGroup @group) => RemoveCommandGroup(@group, false);
public ICommandGroupObject(ICommandGroup ICommandGroupinstance) { ICommandGroupInstance = ICommandGroupinstance; }
public int Compare(ICommandGroup x, ICommandGroup y) => Compare(x.Prefix, y.Prefix);
public static void RegisterCommandGroup(ICommandGroup commandGroup) { _commandGroups.Add(commandGroup.Name, commandGroup); foreach (string key in commandGroup.Commands.Keys) { _commands.Add(key, commandGroup.Commands[key]); } }
private IDisposable AddCommands() { const int mainCmdGroupId = 5; const int mainItemId1 = 0; const int mainItemId2 = 1; const string title = "C# Addin"; const string toolTip = "C# Addin"; int[] docTypes = { (int)swDocumentTypes_e.swDocPART }; var cmdGroupErr = 0; var ignorePrevious = false; object registryIDs; //get the ID information stored in the registry var getDataResult = CommandManager.GetGroupDataFromRegistry(mainCmdGroupId, out registryIDs); int[] knownIDs = { mainItemId1, mainItemId2 }; if (getDataResult) { if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup { ignorePrevious = true; } } ICommandGroup cmdGroup = CommandManager.CreateCommandGroup2(mainCmdGroupId, title, toolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = GetBitMap("SwCSharpAddinMF.Icons.ToolbarLarge.bmp"); cmdGroup.SmallIconList = GetBitMap("SwCSharpAddinMF.Icons.ToolbarSmall.bmp"); cmdGroup.LargeMainIcon = GetBitMap("SwCSharpAddinMF.Icons.MainIconLarge.bmp"); cmdGroup.SmallMainIcon = GetBitMap("SwCSharpAddinMF.Icons.MainIconSmall.bmp"); var menuToolbarOption = (int)swCommandItemType_e.swToolbarItem | (int)swCommandItemType_e.swMenuItem; var cmdIndex0 = cmdGroup.AddCommandItem2(nameof(CreateSampleMacroFeature), -1, "Alpha Split", "Alpha Split", 0, nameof(CreateSampleMacroFeature), "", mainItemId1, menuToolbarOption); var cmdIndex1 = cmdGroup.AddCommandItem2(nameof(CreateManipulatorSample), -1, "Manipulator", "Manipulator", 0, nameof(CreateManipulatorSample), "", mainItemId1, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); foreach (var type in docTypes) { var cmdTab = CommandManager.GetCommandTab(type, title); // if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. // Otherwise the ids won't matchup and the tab will be blank if (cmdTab != null & !getDataResult | ignorePrevious) { CommandManager.RemoveCommandTab(cmdTab); cmdTab = null; } //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs if (cmdTab == null) { cmdTab = CommandManager.AddCommandTab(type, title); var cmdBox = cmdTab.AddCommandTabBox(); var cmdIDs = new[] { cmdIndex0, cmdIndex1 } .Select(id => cmdGroup.CommandID[id]) .ToArray(); var textType = cmdIDs .Select(id => (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal) .ToArray(); cmdBox.AddCommands(cmdIDs, textType); } } return(Disposable.Create(() => CommandManager.RemoveCommandGroup(mainCmdGroupId))); }
/// <summary> /// Creates a menu item for a command. /// </summary> /// <param name="command">The command for which a menu item is to be created.</param> /// <param name="group">The group to which the command belongs.</param> /// <param name="requiresParentMenu">If <c>true</c>, must be placed in a submenu.</param> /// <param name="itemName">The name of the menu item.</param> /// <returns>The menu item for the command.</returns> public static NSMenuItem CreateMenuItemForCommand(this VisualRelayCommand command, ICommandGroup group, bool requiresParentMenu, string itemName) { NSMenuItem menuItem = command.MenuItem; if (((command.MenuParent != null) || !requiresParentMenu) && (menuItem == null)) { if (command.UniqueId == RootCommandGroup.MenuSeparatorCommand.UniqueId) { menuItem = NSMenuItem.SeparatorItem; } else if (!string.IsNullOrEmpty(command.Name)) { var name = itemName ?? command.MenuItemName; if (string.IsNullOrWhiteSpace(name)) { name = command.Name; } menuItem = new NSMenuItem(name); if (!string.IsNullOrWhiteSpace(command.KeyboardShortcutKey)) { // NOTE! InsertItem may reset key equivalent if another item already // exists with the same one! Bleargh! menuItem.KeyEquivalent = command.KeyboardShortcutKey; var modifiers = command.KeyboardShortcutModifiers; menuItem.KeyEquivalentModifierMask = (NSEventModifierMask)modifiers; } } if (menuItem != null) { menuItem.RepresentedObject = new NSObjectWrapper <ICommand>(command); menuItem.ToolTip = command.ToolTip; if (requiresParentMenu) { var menuCommand = (VisualRelayCommand)command.MenuParent; if (menuCommand.MenuItem.IsEmpty) { menuCommand.MenuItem = group.CreateMenuItemForCommand(menuCommand); } var menu = !menuCommand.MenuItem.IsEmpty ? menuCommand.MenuItem.NativeMenuItem.Submenu : null; if ((menu == null) && (menuCommand.UniqueId == RootCommandGroup.RootMenuCommand.UniqueId)) { menu = menuCommand.Visual as NSMenu; } if (menu == null) { var name = menuCommand.MenuItemName; if (string.IsNullOrWhiteSpace(name)) { name = menuCommand.Name; } menu = new NSMenu(name); menuCommand.MenuItem.NativeMenuItem.Submenu = menu; } if (menu.Delegate == null) { menu.Delegate = MenuDelegate.Instance; } var insertLocation = command.FindMenuInsertLocation(menu); menu.InsertItem(menuItem, insertLocation); // <<<< Might nuke key equivalent! } } } return(menuItem); }
/// <summary> /// 添加单个命令 /// </summary> /// <param name="scope"></param> /// <param name="type"></param> /// <param name="cmdGroup"></param> /// <param name="CommandIndex"></param> /// <returns></returns> private KeyValuePair <int, KeyValuePair <CommandType, int> > AddCommnad(ILifetimeScope scope, Type type, ref ICommandGroup cmdGroup, int CommandIndex) { var obj = scope.Resolve(type); var commandsAttr = type.GetCustomAttribute <SWCommandAttribute>(); var flyoutAttr = type.GetCustomAttribute <SWFlyoutCommandAttribute>(); if (commandsAttr == null && flyoutAttr == null) { throw new MissingMemberException($"The type :{nameof(type.FullName)} missing {nameof(SWCommandAttribute)} or {nameof(SWFlyoutCommandAttribute)}"); } if (commandsAttr != null && flyoutAttr != null) { throw new InvalidOperationException($"The type :{nameof(type.FullName)} cannot has {nameof(SWCommandAttribute)} and {nameof(SWFlyoutCommandAttribute)}"); } if (commandsAttr != null) //普通按钮 { int idIndex = _addinCommand.AddSWCommand(cmdGroup, commandsAttr.Guid, commandsAttr.Name, commandsAttr.Postion, commandsAttr.Hint, commandsAttr.ToolTip, commandsAttr.ImageListIndex == -1 ? CommandIndex : commandsAttr.ImageListIndex, CommandIndex, commandsAttr.MenuTBOption.SWToInt()); //CommandIndex++; if (!_addinCommand.CommandInstances.ContainsKey(commandsAttr.Guid)) { _addinCommand.CommandInstances.Add(commandsAttr.Guid, scope.Resolve(type)); } return(new KeyValuePair <int, KeyValuePair <CommandType, int> >(idIndex, new KeyValuePair <CommandType, int>(CommandType.Command, commandsAttr.TextType.SWToInt()))); } else //下拉按钮 { IFlyoutCommand flyoutCMD = default; //创建下拉组 var flyoutGroup = _addinCommand.CreatSWFlyoutGroup(CommandIndex, flyoutAttr.Guid, flyoutAttr.Title, flyoutAttr.ToolTip, flyoutAttr.Hint, cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList ); //CommandIndex++; if (!_addinCommand.CommandInstances.ContainsKey(flyoutAttr.Guid)) { var flyoutObj = scope.Resolve(type); flyoutCMD = flyoutObj as IFlyoutCommand; if (flyoutCMD != null) { flyoutCMD.FlyoutCMDId = flyoutGroup.CmdID; flyoutCMD.FlyoutGroup = flyoutGroup; } else { throw new NotImplementedException($"command:{type.FullName} not implemented interface:{nameof(IFlyoutCommand)}"); } _addinCommand.CommandInstances.Add(flyoutAttr.Guid, flyoutObj); } //下拉文档中的Commands var commands = flyoutAttr.Commands; if (commands != null && flyoutGroup != null) { foreach (var command in commands) { var flyoutCMDAttr = command.GetCustomAttribute <SWCommandAttribute>(); if (flyoutCMDAttr == null) { throw new MissingMemberException($"The type :{type.FullName}'s FlyoutCommandAttribute:{command.FullName} missing {nameof(SWCommandAttribute)} or {nameof(SWFlyoutCommandAttribute)}"); } _addinCommand.AddFlyoutCommand(flyoutGroup, flyoutCMDAttr.Guid, flyoutCMDAttr.Name, flyoutCMDAttr.Hint, flyoutCMDAttr.ImageListIndex == -1 ? CommandIndex : flyoutCMDAttr.ImageListIndex, command); } } else { throw new MissingMemberException($"flyoutCommand:{type.FullName} donot has commands"); } flyoutCMD?.Execute(null); //flyoutGroup.FlyoutType = flyoutAttr.FlyoutType.SWToInt(); return(new KeyValuePair <int, KeyValuePair <CommandType, int> >(flyoutGroup.CmdID, new KeyValuePair <CommandType, int>(CommandType.FlyoutCommand, flyoutAttr.TextType))); } }
/// <summary> /// The add command mgr. /// </summary> public void AddCommandMgr() { if (this.iBmp == null) { this.iBmp = new BitmapHandler(); } const string Title = "Save PDF"; const string ToolTip = "Save PDF"; int[] docTypes = { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; Assembly thisAssembly = Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; // get the ID information stored in the registry bool getDataResult = this.CmdMgr.GetGroupDataFromRegistry(MainCmdGroupId, out registryIDs); int[] knownIDs = { MainItemId1 }; if (getDataResult) { if (!this.CompareIDs((int[])registryIDs, knownIDs)) { // if the IDs don't match, reset the commandGroup ignorePrevious = true; } } ICommandGroup cmdGroup = this.CmdMgr.CreateCommandGroup2( MainCmdGroupId, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = this.iBmp.CreateFileFromResourceBitmap("SavePDF.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = this.iBmp.CreateFileFromResourceBitmap("SavePDF.ToolbarSmall.bmp", thisAssembly); const int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); int cmdIndex0 = cmdGroup.AddCommandItem2( "Save PDF", -1, "Save PDF Options", "Save PDF Options", 0, "ShowPMP", "EnablePMP", MainItemId1, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); foreach (int type in docTypes) { CommandTab cmdTab = this.CmdMgr.GetCommandTab(type, Title); if (cmdTab != null & !getDataResult | ignorePrevious) { // if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank bool res = this.CmdMgr.RemoveCommandTab(cmdTab); cmdTab = null; } // if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs if (cmdTab == null) { cmdTab = this.CmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); var cmdIDs = new int[1]; var textType = new int[1]; cmdIDs[0] = cmdGroup.CommandID[cmdIndex0]; textType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdBox.AddCommands(cmdIDs, textType); } } thisAssembly = null; }
public void AddCommandMgr() { BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; int cmdIndex0, cmdIndex1, cmdIndex2, cmdIndex3, cmdIndex4; string Title = "DotNetControlsDemo", ToolTip = "DotNetControlsDemo"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, "", -1); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.MainIconSmall.bmp", thisAssembly); cmdIndex0 = cmdGroup.AddCommandItem("WinFromInTaskPane", -1, "Add Windows Form In Task Pane", "WinFormInTaskPane", 0, "WinFormInTaskPane", "EnableWinFormInTaskPane", 0); cmdIndex1 = cmdGroup.AddCommandItem("UserControlInModelView", -1, "Add User Control In Model View", "UserControlInModelView", 1, "UserControlInModelView", "EnableUserControlInModelView", 1); cmdIndex2 = cmdGroup.AddCommandItem("WPFInModelView", -1, "Add WPF In ModelView", "WPFInModelView", 2, "WPFInModelView", "EnableWPFInModelView", 2); cmdIndex3 = cmdGroup.AddCommandItem("WinFormInFeatureMgr", -1, "Add Windows Form In FeatureManager", "WinFormInFeatureMgr", 3, "WinFormInFeatureMgr", "EnableWinFormInFeatureMgr", 3); cmdIndex4 = cmdGroup.AddCommandItem("Show PMP", -1, "Display PropertyManager with .NET Controls", "Show PMP", 4, "ShowPMP", "EnablePMP", 4); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; foreach (int type in docTypes) { ICommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab == null) { cmdTab = (ICommandTab)iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[6]; int[] TextType = new int[6]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex0).ToString()); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex1).ToString()); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex2); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex2).ToString()); TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[3] = cmdGroup.get_CommandID(cmdIndex3); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex3).ToString()); TextType[3] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[4] = cmdGroup.get_CommandID(cmdIndex4); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex4).ToString()); TextType[4] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[5] = cmdGroup.ToolbarId; System.Diagnostics.Debug.Print(cmdIDs[5].ToString()); TextType[5] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; cmdIDs[0] = cmdGroup.ToolbarId; TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdGroup.ToolbarId); } } thisAssembly = null; iBmp.Dispose(); }
/// <summary> /// Execute command /// </summary> /// <param name="commandArguments">Command arguments</param> /// <returns>Command result</returns> public ECommandResult Execute(ICommandArguments commandArguments) { ECommandResult ret = ECommandResult.Failed; ICommands[] commands_services = commandArguments.Bot.GetServices <ICommands>(); IChat[] chat_services = commandArguments.Bot.GetServices <IChat>(); HelpConfiguration help_configuration = commandArguments.Bot.GetService <HelpConfiguration>(); if ((commands_services != null) && (chat_services != null) && (help_configuration != null)) { List <Embed> embeds = new List <Embed>(); if (commandArguments.Arguments.Count > 0) { string command_string = commandArguments.Arguments[0]; List <KeyValuePair <ICommands, ICommand> > command_list = new List <KeyValuePair <ICommands, ICommand> >(); foreach (ICommands commands in commands_services) { ICommand command = commands.FindCommand(command_string); if (command != null) { command_list.Add(new KeyValuePair <ICommands, ICommand>(commands, command)); } } if (command_list.Count > 0) { foreach (KeyValuePair <ICommands, ICommand> command in command_list) { EmbedBuilder embed_builder = PrepareEmbedBuilder("Help topic for command \"" + command.Value.Name + "\""); embed_builder.AddField("Command", command.Value.Name, true); embed_builder.AddField("Description", command.Value.Description, true); embed_builder.AddField("Full description", command.Value.FullDescription); StringBuilder required_privileges = new StringBuilder(); foreach (KeyValuePair <string, uint> privilege in command.Value.ForceRequiredPrivileges) { required_privileges.Append("\""); required_privileges.Append(privilege.Key); required_privileges.Append("\" : "); required_privileges.Append(privilege.Value.ToString()); } if (required_privileges.Length > 0) { embed_builder.AddField("Required privileges", required_privileges); } ICommandGroup command_group = command.Key.GetCommandGroup(command.Value.CommandGroup); if (command_group != null) { StringBuilder more_commands = new StringBuilder(); bool first = true; foreach (ICommand command_group_command in command.Key.FromCommandGroup(command_group)) { if (first) { first = false; } else { more_commands.Append(", "); } more_commands.Append(command_group_command.Name); } if (first) { more_commands.Append("No commands?"); } embed_builder.AddField("More commands " + command_group.Icon, more_commands.ToString()); } embeds.Add(embed_builder.Build()); } } else { List <KeyValuePair <ICommands, ICommandGroup> > command_group_list = new List <KeyValuePair <ICommands, ICommandGroup> >(); string command_group_name_key = commandArguments.Arguments[0].Trim().ToLower(); foreach (ICommands commands in commands_services) { ICommandGroup command_group = commands.GetCommandGroup(command_string); if (command_group != null) { if (command_group.Name.Trim().ToLower() == command_group_name_key) { command_group_list.Add(new KeyValuePair <ICommands, ICommandGroup>(commands, command_group)); } } } if (command_group_list.Count > 0) { foreach (KeyValuePair <ICommands, ICommandGroup> command_group in command_group_list) { EmbedBuilder embed_builder = PrepareEmbedBuilder("Help topic for command group \"" + command_group.Value.Icon + " " + command_group.Value.Name + "\""); StringBuilder command_group_commands = new StringBuilder(); bool first = true; foreach (ICommand command_group_command in command_group.Key.FromCommandGroup(command_group.Value)) { if (first) { first = false; } else { command_group_commands.Append(", "); } command_group_commands.Append(command_group_command.Name); } if (first) { command_group_commands.Append("No commands?"); } embed_builder.AddField("Commands", command_group_commands.ToString()); command_group_commands.Clear(); embeds.Add(embed_builder.Build()); } } else { foreach (ICommands commands in commands_services) { EmbedBuilder embed_builder = PrepareEmbedBuilder(); embed_builder.WithTitle("Help topics similar to \"" + command_string + "\""); StringBuilder all_commands_groups = new StringBuilder(); bool first = true; foreach (ICommand command in commands.AvailableCommands) { if (Levenshtein.GetDistance(command_string, command.Name) <= help_configuration.Data.MaximumLevenshteinDistance) { if (first) { first = false; } else { all_commands_groups.Append(", "); } all_commands_groups.Append(command.Name); } } if (first) { all_commands_groups.Append("No similar commands found"); } embed_builder.AddField("Commands", all_commands_groups.ToString()); all_commands_groups.Clear(); first = true; foreach (ICommandGroup command_group in commands.AvailableCommandGroups) { if (Levenshtein.GetDistance(command_string, command_group.Name) <= help_configuration.Data.MaximumLevenshteinDistance) { if (first) { first = false; } else { all_commands_groups.Append(", "); } all_commands_groups.Append(command_group.Icon); all_commands_groups.Append(" "); all_commands_groups.Append(command_group.Name); } } if (first) { all_commands_groups.Append("No similar command groups found"); } embed_builder.AddField("Command groups", all_commands_groups.ToString()); embeds.Add(embed_builder.Build()); } } command_group_list.Clear(); } command_list.Clear(); } else { foreach (ICommands commands in commands_services) { EmbedBuilder embed_builder = PrepareEmbedBuilder("Help topics"); StringBuilder command_group_commands = new StringBuilder(); foreach (ICommandGroup command_group in commands.AvailableCommandGroups) { bool first = true; command_group_commands.Clear(); foreach (ICommand command_group_command in commands.FromCommandGroup(command_group)) { if (first) { first = false; } else { command_group_commands.Append(", "); } command_group_commands.Append(command_group_command.Name); } if (first) { command_group_commands.Append("No commands specified yet."); } embed_builder.AddField(command_group.Icon + " " + command_group.Name, command_group_commands.ToString()); } embeds.Add(embed_builder.Build()); } } foreach (IChat chat in chat_services) { foreach (Embed embed in embeds) { chat.SendEmbedAsync(embed, commandArguments.MessageChannel); } } embeds.Clear(); ret = ECommandResult.Successful; } return(ret); }
public void AddCommandMgr() { BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; int cmdIndex0, cmdIndex1, cmdIndex2, cmdIndex3, cmdIndex4; string Title = "DotNetControlsDemo", ToolTip = "DotNetControlsDemo"; int[] docTypes = new int[]{(int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART}; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, "", -1); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.MainIconSmall.bmp", thisAssembly); cmdIndex0 = cmdGroup.AddCommandItem("WinFromInTaskPane", -1, "Add Windows Form In Task Pane", "WinFormInTaskPane", 0, "WinFormInTaskPane", "EnableWinFormInTaskPane", 0); cmdIndex1 = cmdGroup.AddCommandItem("UserControlInModelView", -1, "Add User Control In Model View", "UserControlInModelView", 1, "UserControlInModelView", "EnableUserControlInModelView", 1); cmdIndex2 = cmdGroup.AddCommandItem("WPFInModelView", -1, "Add WPF In ModelView", "WPFInModelView", 2, "WPFInModelView", "EnableWPFInModelView", 2); cmdIndex3 = cmdGroup.AddCommandItem("WinFormInFeatureMgr", -1, "Add Windows Form In FeatureManager", "WinFormInFeatureMgr", 3, "WinFormInFeatureMgr", "EnableWinFormInFeatureMgr", 3); cmdIndex4 = cmdGroup.AddCommandItem("Show PMP", -1, "Display PropertyManager with .NET Controls", "Show PMP", 4, "ShowPMP", "EnablePMP", 4); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; foreach (int type in docTypes) { ICommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab == null) { cmdTab = (ICommandTab)iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[6]; int[] TextType = new int[6]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex0).ToString()); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex1).ToString()); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex2); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex2).ToString()); TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[3] = cmdGroup.get_CommandID(cmdIndex3); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex3).ToString()); TextType[3] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[4] = cmdGroup.get_CommandID(cmdIndex4); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex4).ToString()); TextType[4] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[5] = cmdGroup.ToolbarId; System.Diagnostics.Debug.Print(cmdIDs[5].ToString()); TextType[5] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; cmdIDs[0] = cmdGroup.ToolbarId; TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdGroup.ToolbarId); } } thisAssembly = null; iBmp.Dispose(); }