Пример #1
0
 private void addChild(MenuItem associatedMenuItem)
 {
     // UNSAFE: separators?
     System.Windows.Forms.ToolStripItem myChild = new CustomToolStripMenuItem(associatedMenuItem);
     Items.Insert(dynamicChildrenInsertPosition + dynamicChildren, myChild);
     dynamicChildren++;
 }
Пример #2
0
        private void addChild(MenuItem associatedMenuItem)
        {
            Func <System.Windows.Forms.ToolStripItem, bool> lastBeforeLookupFunction = (toolStripItem) =>
            {
                CustomToolStripMenuItem toolStripItemCasted = toolStripItem as CustomToolStripMenuItem;
                if (toolStripItemCasted == null)
                {
                    return(false);
                }
                MenuItem menuItem = toolStripItemCasted.AssociatedMenuItem;
                return((menuItem.ParentGroup.Weight <= associatedMenuItem.ParentGroup.Weight) && (menuItem.Weight <= associatedMenuItem.Weight));
            };

            // Separator before
            System.Windows.Forms.ToolStripItem lastBefore = guiElement.DropDownItems.Cast <System.Windows.Forms.ToolStripItem>().Where(lastBeforeLookupFunction).LastOrDefault();
            int position = guiElement.StartPosition;

            if (lastBefore != null)
            {
                position = guiElement.DropDownItems.IndexOf(lastBefore) + 1;
                if (!(lastBefore is System.Windows.Forms.ToolStripSeparator))
                {
                    CustomToolStripMenuItem lastBeforeCasted = lastBefore as CustomToolStripMenuItem;
                    MenuItemGroup           groupBefore      = lastBeforeCasted?.AssociatedMenuItem.ParentGroup;
                    if ((groupBefore != associatedMenuItem.ParentGroup) && (groupBefore != null))
                    {
                        guiElement.DropDownItems.Insert(position++, new System.Windows.Forms.ToolStripSeparator());
                    }
                }
            }
            // Menu item
            System.Windows.Forms.ToolStripItem myChild = new CustomToolStripMenuItem(associatedMenuItem);
            guiElement.DropDownItems.Insert(position++, myChild);
            // Separator after
            if (guiElement.DropDownItems.Count > position)
            {
                System.Windows.Forms.ToolStripItem firstAfter = guiElement.DropDownItems[position];
                if (firstAfter != null)
                {
                    CustomToolStripMenuItem firstAfterCasted = firstAfter as CustomToolStripMenuItem;
                    MenuItemGroup           groupAfter       = firstAfterCasted?.AssociatedMenuItem.ParentGroup;
                    // Add if next is another group
                    if (!(firstAfter is System.Windows.Forms.ToolStripSeparator) && (groupAfter != associatedMenuItem.ParentGroup) && (groupAfter != null))
                    {
                        guiElement.DropDownItems.Insert(position++, new System.Windows.Forms.ToolStripSeparator());
                    }
                    // Remove is next is same group
                    if ((firstAfter is System.Windows.Forms.ToolStripSeparator) && (groupAfter == associatedMenuItem.ParentGroup) && (groupAfter != null))
                    {
                        guiElement.DropDownItems.Remove(firstAfter);
                    }
                }
            }
        }
Пример #3
0
 private void removeChild(MenuItem associatedMenuItem)
 {
     for (int i = guiElement.DropDownItems.Count - 1; i >= 0; i--)
     {
         CustomToolStripMenuItem customMenuItem = guiElement.DropDownItems[i] as CustomToolStripMenuItem;
         if ((customMenuItem != null) && (customMenuItem.AssociatedMenuItem == associatedMenuItem))
         {
             guiElement.DropDownItems.RemoveAt(i);
         }
     }
 }
Пример #4
0
 private void removeDynamicChildren()
 {
     for (int i = guiElement.DropDownItems.Count - 1; i >= 0; i--)
     {
         CustomToolStripMenuItem customMenuItem = guiElement.DropDownItems[i] as CustomToolStripMenuItem;
         if (customMenuItem != null)
         {
             guiElement.DropDownItems.RemoveAt(i);
         }
     }
 }
Пример #5
0
 private void addChild(MenuItem associatedMenuItem)
 {
     System.Windows.Forms.ToolStripItem myChild;
     if (associatedMenuItem is SeparatorMenuItem)
     {
         myChild = new System.Windows.Forms.ToolStripSeparator();
     }
     else
     {
         myChild = new CustomToolStripMenuItem(associatedMenuItem);
     }
     DropDownItems.Add(myChild);
 }