public override IMenuItemProxy[] GetChildren()
        {
            var itemList = new List <ToolStripItemProxy>();

            foreach (ToolStripItem item in menu.Items)
            {
                itemList.Add(ToolStripItemProxy.GetProxyFromCache(item));
            }
            return(itemList.ToArray());
        }
Exemple #2
0
        public static ToolStripItemProxy GetProxyFromCache(ToolStripItem item)
        {
            ToolStripItemProxy proxy;

            if (!mProxyCache.TryGetValue(item, out proxy))
            {
                proxy = new ToolStripItemProxy(item);
                mProxyCache.Add(item, proxy);
            }
            return(proxy);
        }
Exemple #3
0
 private void AddItemsToMenuItemList(ToolStripItemCollection items)
 {
     foreach (ToolStripItem item in items)
     {
         var itemProxy = ToolStripItemProxy.GetProxyFromCache(item);
         if (!mMenuItemList.Contains(itemProxy))
         {
             mMenuItemList.Add(itemProxy);
         }
         var dropDownItem = item as ToolStripDropDownItem;
         if (dropDownItem != null)
         {
             AddItemsToMenuItemList(dropDownItem.DropDownItems);
             dropDownItem.DropDown.ItemAdded += (sender, e) =>
             {
                 var addedItemProxy = ToolStripItemProxy.GetProxyFromCache(e.Item);
                 if (!mMenuItemList.Contains(addedItemProxy))
                 {
                     mMenuItemList.Add(addedItemProxy);
                 }
                 if (dropDownItem.DropDownItems.Count == 1)
                 {
                     OnItemPropertyChanged("children-display", addedItemProxy);
                 }
             };
             dropDownItem.DropDown.ItemRemoved += (sender, e) =>
             {
                 var addedItemProxy = ToolStripItemProxy.GetProxyFromCache(e.Item);
                 // set to null instead of removing because we are using the index
                 // as the id and we don't want to mess it up.
                 var itemIndex = mMenuItemList.IndexOf(addedItemProxy);
                 mMenuItemList[itemIndex] = null;
                 if (dropDownItem.DropDownItems.Count == 0)
                 {
                     OnItemPropertyChanged("children-display", addedItemProxy);
                 }
             };
             var menuItem      = dropDownItem as ToolStripMenuItem;
             var menuItemProxy = ToolStripItemProxy.GetProxyFromCache(item);
             if (menuItem != null)
             {
                 menuItem.CheckStateChanged += (sender, e) =>
                                               OnItemPropertyChanged("toggle-state", menuItemProxy);
             }
         }
         item.TextChanged += (sender, e) =>
                             OnItemPropertyChanged("label", itemProxy);
         item.EnabledChanged += (sender, e) =>
         {
             if (item.Image != null)
             {
                 OnItemPropertiesChanged(new string[] { "enabled", "icon-data" },
                                         itemProxy);
             }
             else
             {
                 OnItemPropertyChanged("enabled", itemProxy);
             }
         };
         item.AvailableChanged += (sender, e) =>
                                  OnItemPropertyChanged("visible", itemProxy);
     }
 }