/// ------------------------------------------------------------------------------------ /// <summary> /// Reads the commands section of a definition file. /// </summary> /// <param name="node"></param> /// ------------------------------------------------------------------------------------ protected void ReadCommands(XmlNode node) { XmlNode commandNode = node.FirstChild; while (commandNode != null) { string cmd = GetAttributeValue(commandNode, "id"); if (cmd == null) continue; CommandInfo cmdInfo = new CommandInfo(); cmdInfo.TextId = GetAttributeValue(commandNode, "text"); cmdInfo.TextAltId = GetAttributeValue(commandNode, "textalt"); cmdInfo.ContextMenuTextId = GetAttributeValue(commandNode, "contextmenutext"); cmdInfo.CategoryId = GetAttributeValue(commandNode, "category"); cmdInfo.ToolTipId = GetAttributeValue(commandNode, "tooltip"); cmdInfo.StatusMsgId = GetAttributeValue(commandNode, "statusmsg"); cmdInfo.Message = GetAttributeValue(commandNode, "message"); string shortcut = GetAttributeValue(commandNode, "shortcutkey"); string imageLabel = GetAttributeValue(commandNode, "image"); if (cmdInfo.TextId != null) cmdInfo.Text = GetStringFromResource(cmdInfo.TextId); if (cmdInfo.TextAltId != null) cmdInfo.TextAlt = GetStringFromResource(cmdInfo.TextAltId); if (cmdInfo.ContextMenuTextId != null) cmdInfo.ContextMenuText = GetStringFromResource(cmdInfo.ContextMenuTextId); if (cmdInfo.CategoryId != null) cmdInfo.Category = GetStringFromResource(cmdInfo.CategoryId); if (cmdInfo.ToolTipId != null) cmdInfo.ToolTip = GetStringFromResource(cmdInfo.ToolTipId); if (cmdInfo.StatusMsgId != null) cmdInfo.StatusMsg = GetStringFromResource(cmdInfo.ToolTipId); if (cmdInfo.StatusMsg == null || cmdInfo.StatusMsg == string.Empty) cmdInfo.StatusMsg = GetStringFromResource("kstidDefaultStatusBarMsg"); cmdInfo.ShortcutKey = ParseShortcutKeyString(shortcut); // If the command doesn't have an explicit image label, then use // the command id as the image label. if (imageLabel == null) imageLabel = cmd; Image img; if (m_images.TryGetValue(imageLabel, out img)) cmdInfo.Image = img; m_commandInfo[cmd] = cmdInfo; commandNode = ReadOverJunk(commandNode.NextSibling); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a new submenu item to the menu specified by parentItemName and inserts it /// before the item specified by insertBeforeItem. If insertBeforeItem is null, then /// the new submenu item is added to the end of parentItemName's menu collection. /// </summary> /// <param name="itemProps">Properties of the new menu item.</param> /// <param name="parentItemName">Name of the menu item that will be added to.</param> /// <param name="insertBeforeItem">Name of the submenu item before which the new /// menu item will be added.</param> /// ------------------------------------------------------------------------------------ public void AddMenuItem(TMItemProperties itemProps, string parentItemName, string insertBeforeItem) { // Check if the specified command Id is in our dictionary of commands. // If not, we need to add one for this item. if (!m_commandInfo.ContainsKey(itemProps.CommandId)) { // If there is no command Id, then assign a unique one. if (string.IsNullOrEmpty(itemProps.CommandId)) itemProps.CommandId = Guid.NewGuid().ToString(); CommandInfo ci = new CommandInfo(); ci.Image = itemProps.Image; ci.Message = itemProps.Message; ci.Text = itemProps.Text; ci.ToolTip = itemProps.Tooltip; ci.Category = itemProps.Category; m_commandInfo[itemProps.CommandId] = ci; } ToolStripMenuItem item = ToolStripItemExtender.CreateMenuItem(); item.Name = itemProps.Name; item.Tag = itemProps.CommandId; item.Click += HandleItemClicks; item.DropDown.Opening += HandleMenuOpening; item.DropDown.Opened += HandleMenuOpened; itemProps.Update = true; SetItemProps(item, itemProps); m_tmItems[item.Name] = item; // If an item to insert before isn't specified, then add the item to the // specified parent item. Otherwise, insert before "insertBeforeItem". if (insertBeforeItem == null || insertBeforeItem.Trim() == string.Empty) AddMenuItem(item, parentItemName); else InsertMenuItem(item, insertBeforeItem); }