/// <summary>
		/// Assert that the strip has no menu item with the specified text.
		/// </summary>
		/// <param name="items"></param>
		/// <param name="text"></param>
		/// <returns></returns>
		private static void AssertHasNoMenuWithText(ToolStripItemCollection items, string text)
		{
			if (items.Cast<ToolStripItem>().Any(item => item is ToolStripMenuItem && (item as ToolStripMenuItem).Text == text))
			{
				Assert.Fail("item " + text + " was unexpectedly found in a context menu");
			}
		}
Exemple #2
0
 private IEnumerable<ToolStripItem> ActualItems(ToolStripItemCollection items)
 {
     return items.Cast<ToolStripItem>().Where(item => !(item is ToolStripSeparator));
 }
 private List<ToolStripItem> CloneItems(ToolStripItemCollection collection)
 {
     var list = new List<ToolStripItem>();
     if (collection != null)
     {
         list.Add(new ToolStripSeparator());
         var enumerable = collection.Cast<ToolStripItem>();
         foreach (var toolStripItem in enumerable)
         {
             if (toolStripItem is ToolStripSeparator)
             {
                 list.Add(new ToolStripSeparator());
             }
             else
             {
                 var toolStripMenuItem = toolStripItem as ToolStripMenuItem;
                 if (toolStripMenuItem != null)
                 {
                     var item = new ToolStripMenuItem
                     {
                         Name = toolStripMenuItem.Name,
                         Size = toolStripMenuItem.Size,
                         Text = toolStripMenuItem.Text,
                         ToolTipText = toolStripMenuItem.ToolTipText,
                         ShortcutKeys = toolStripMenuItem.ShortcutKeys,
                         ShortcutKeyDisplayString = toolStripMenuItem.ShortcutKeyDisplayString,
                         ShowShortcutKeys = toolStripMenuItem.ShowShortcutKeys
                     };
                     var events = (EventHandlerList)eventsPropertyInfo.GetValue(toolStripMenuItem, null);
                     var secret = eventClickFieldInfo.GetValue(null);
                     var handlers = events[secret];
                     events = (EventHandlerList)eventsPropertyInfo.GetValue(item, null);
                     events.AddHandler(secret, handlers);
                     list.Add(item);
                 }
             }
         }
     }
     return list;
 }
Exemple #4
0
        private static ToolStripMenuItem FindOrCreateAlgoMenuItem(ToolStripItemCollection parent, string algorithm)
        {
            ToolStripMenuItem algoItem = parent.Cast<ToolStripMenuItem>().FirstOrDefault(item => item.Text.Equals(algorithm));

            if (algoItem == null)
            {
                algoItem = new ToolStripMenuItem()
                {
                    Text = algorithm
                };
                parent.Add(algoItem);
            }

            return algoItem;
        }