/// <summary> /// Tracks the command. /// </summary> /// <param name="items">The items.</param> /// <param name="command">The command.</param> public static void BindCommand(this ToolStripItemCollection items, Command command) { foreach (var item in items.OfType <ToolStripMenuItem>()) { new ToolStripMenuItemHandler(item, command); } }
private static void TrackItemsState(ToolStripItemCollection items) { foreach (var item in items.OfType <ToolStripDropDownItem>()) { item.DropDownOpening += DropDownDropDownOpening; } }
public static void UpdateCheckedState(ToolStripItemCollection items, Enum value) { foreach (EnumToolStripMenuItem item in items.OfType <EnumToolStripMenuItem>()) { item.UpdateCheckedState(value); } }
/// <summary> /// Finds all contained <see cref="ToolStripItem"/>s recursively. /// </summary> /// <param name="inCollection">The collection whose contents are sought.</param> /// <returns>A list of controls.</returns> public static IEnumerable <ToolStripItem> GetAllChildren(this ToolStripItemCollection inCollection) { var children = inCollection.OfType <ToolStripItem>(); return(children.OfType <ToolStripDropDownItem>() .SelectMany(dropDownItem => dropDownItem.DropDownItems.GetAllChildren()) .Concat(children)); }
private void CloseDropDowns(ToolStripItemCollection menuItems) { foreach (ToolStripDropDownItem dropDownItem in menuItems.OfType <ToolStripDropDownItem>()) { dropDownItem.HideDropDown(); CloseDropDowns(dropDownItem.DropDownItems); } }
/// <summary> /// Recusively retrieves all menu items from the input collection /// </summary> public static IEnumerable <ToolStripMenuItem> GetAllMenuItems(this ToolStripItemCollection items) { var allItems = new List <ToolStripMenuItem>(); foreach (var item in items.OfType <ToolStripMenuItem>()) { allItems.Add(item); allItems.AddRange(GetAllMenuItems(item.DropDownItems)); } return(allItems); }
private ToolStripMenuItem LookupParentMenuForTag(ToolStripItemCollection items, Guid?id) { if (!id.HasValue) { return(null); } var result = items.OfType <ToolStripMenuItem>() .FirstOrDefault(t => t.Tag is Guid && (Guid)t.Tag == id.Value); return(result); }
private static void InvalidateEnabled(ToolStripItemCollection items) { foreach (var item in items.OfType <ToolStripItem>()) { var binding = GetBinding(item); if (binding == null || binding.Command == null) { continue; } var parameter = binding.ParameterSource == null ? item.Tag : binding.ParameterSource(); item.Enabled = binding.Command.CanExecute(parameter, item); } }
public static void DisposeItems(this ToolStripItemCollection items) { foreach (IDisposable disposable in items.OfType <IDisposable>().ToArray()) { if (disposable is ToolStripMenuItem menuItem) { menuItem.DropDownItems.DisposeItems(); } if (disposable is ToolStripItem item && item.Tag is ToolStripItemTag tag && tag.ClickEventHandler != null) { item.Click -= tag.ClickEventHandler; } disposable.Dispose(); } }
private ToolStripMenuItem GetMenuItem(ToolStripItemCollection collection, string name) { return(collection.OfType <ToolStripMenuItem>().FirstOrDefault(item => item.Text.Replace("&", "") == name)); }
public static IEnumerable <Controls.ToolStripHintMenuItem> FlattenMenu(this ToolStripItemCollection coll) { return(coll.OfType <Controls.ToolStripHintMenuItem>().Concat(coll.OfType <Controls.ToolStripHintMenuItem>().SelectMany(x => FlattenMenu(x.DropDownItems)))); }