public static void AddContextMenuItem(Type wrapper, params ToolStripMenuItem[] items) { if (ContextMenuHooks.ContainsKey(wrapper)) { ContextMenuHooks[wrapper].Append(items); } else { ContextMenuHooks.Add(wrapper, items); } }
/// <summary> /// To be called by API, adds context menu items to a wrapper. /// /// This is kept for compatibility purposes, the second definition for this function offers far more extensibility. /// </summary> /// <param name="wrapper"> /// The wrapper which new items will be added to. /// </param> /// <param name="items"> /// One or more ToolStrip menu items that will be added to the context menu. /// These should be defined as much as possible in the script itself. /// </param> public static void AddContextMenuItem(Type wrapper, params ToolStripMenuItem[] items) { if (ContextMenuHooks.ContainsKey(wrapper)) { if (items.Length == 1 && items[0].HasDropDownItems) { // Combine same-named submenus for (int i = 0; i < ContextMenuHooks[wrapper].Length; i++) { ToolStripMenuItem item = ContextMenuHooks[wrapper][i]; if (!item.HasDropDownItems || item.Text != items[0].Text) { continue; } if (string.IsNullOrEmpty(item.ToolTipText)) { item.ToolTipText = items[0].ToolTipText; } for (int j = 0; j < items[0].DropDownItems.Count; j++) { ToolStripItem item2 = items[0].DropDownItems[j]; item.DropDownItems.Add(item2); } return; } } ContextMenuHooks[wrapper] = ContextMenuHooks[wrapper].Append(items); } else { ContextMenuHooks.Add(wrapper, items); } }