public void MergeOnlyOneClickEventSubscribed() { using (MessageTest messageTest = new MessageTest()) { messageTest.m_nFirstOneClicked = 0; messageTest.m_nSecondOneClicked = 0; MenuExtender menuExtender = new MenuExtender(); menuExtender.MessageMediator = new Mediator(); menuExtender.MessageMediator.AddColleague(messageTest); MainMenu first = new MainMenu(); MenuItem firstOne = new MenuItem("FirstOne"); first.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, "First", null, null, null, new MenuItem[] { firstOne })); menuExtender.SetCommandId(firstOne, "FirstOne"); MainMenu second = new MainMenu(); MenuItem secondOne = new MenuItem("SecondOne"); second.MenuItems.Add(new MenuItem(MenuMerge.MergeItems, 0, Shortcut.None, "Second", null, null, null, new MenuItem[] { secondOne })); menuExtender.SetCommandId(secondOne, "SecondOne"); MainMenu result = menuExtender.MergeMenus(first, second); result.MenuItems[0].MenuItems[0].PerformClick(); result.MenuItems[0].MenuItems[1].PerformClick(); Assert.AreEqual(1, messageTest.m_nFirstOneClicked); Assert.AreEqual(1, messageTest.m_nSecondOneClicked); // Clean up the mess now. menuExtender.MessageMediator.RemoveColleague(messageTest); menuExtender.MessageMediator.Dispose(); menuExtender.MessageMediator = null; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Builds a menu collection for the specified sidebar tab. The collection contains a /// menu item for each button plus a configure item at the end. /// </summary> /// <param name="tab">given sidebar tab</param> /// <returns>array of menu items from sidebar tab</returns> /// ------------------------------------------------------------------------------------ public MenuItem[] BuildMenusForSideBarTab(SideBarTab tab) { List <MenuItem> mnuList = new List <MenuItem>(); // Create a menu item for each button on the sidebar tab. foreach (SideBarButton button in tab.Buttons) { MenuItem menuItem = new MenuItem(button.Text); MenuExtender.AddMenuItem(menuItem); MenuExtender.SetTag(menuItem, button); MenuExtender.SetCommandId(menuItem, "SideBarButtonMenu"); mnuList.Add(menuItem); } // Create the separator MenuItem mnuSepr = new MenuItem("-"); MenuExtender.AddMenuItem(mnuSepr); MenuExtender.SetCommandId(mnuSepr, tab.ConfigureMenuCommandId); MenuExtender.SetTag(mnuSepr, tab); mnuList.Add(mnuSepr); // Create the configure menu item. MenuItem cfgMenuItem = new MenuItem(tab.ConfigureMenuText); MenuExtender.AddMenuItem(cfgMenuItem); MenuExtender.SetCommandId(cfgMenuItem, tab.ConfigureMenuCommandId); MenuExtender.SetImageList(cfgMenuItem, tab.ConfigureMenuImageList); MenuExtender.SetImageIndex(cfgMenuItem, tab.ConfigureMenuImageIndex); MenuExtender.SetTag(cfgMenuItem, tab); mnuList.Add(cfgMenuItem); return(mnuList.ToArray()); }