/// ------------------------------------------------------------------------------------ /// <summary> /// Remove all the items from the view menu that correspond to the sidebar tabs. /// </summary> /// ------------------------------------------------------------------------------------ private void RemoveOurViewMenuItems() { // Iterate through the collection of menu items we've previously added // to the view menu. foreach (MenuItem menuItem in m_mnuViewCollection) { // Find the menu item in the view menu's menu item collection and // remove that menu item from the view menu. foreach (MenuItem mnuTabItem in ViewMenu.MenuItems) { // Have we found one of our items in the view menu? if (menuItem == mnuTabItem) { // Does our view menu item have sub items? if (mnuTabItem.MenuItems.Count > 0) { // Clear the sub items from the menu extender. foreach (MenuItem mnuButtonItem in mnuTabItem.MenuItems) { MenuExtender.ClearMenuItem(mnuButtonItem); } } // Remove our view menu item from the view menu. ViewMenu.MenuItems.Remove(mnuTabItem); break; } } } m_mnuViewCollection = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This will trap clicks on the info. bar buttons and build a context menu containing /// one item for each side bar button in the corresponding sidebar tab. It will also /// add a title item with the corresponding tab's title. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// ------------------------------------------------------------------------------------ private void infoButton_Click(object sender, EventArgs e) { InformationBarButton button = sender as InformationBarButton; if (button == null || button.Tag == null) { return; } SideBarTab tab = button.Tag as SideBarTab; if (tab == null) { return; } if (m_cmnuInfoBarButton == null) { m_cmnuInfoBarButton = new ContextMenu(); } else { // Clear the menus items so that we start fresh the next time the // user clicks on the information bar button. foreach (MenuItem menuItem in m_cmnuInfoBarButton.MenuItems) { MenuExtender.ClearMenuItem(menuItem); } m_cmnuInfoBarButton.MenuItems.Clear(); } // Load the context menu m_cmnuInfoBarButton.MenuItems.Add(new LabelMenuItem(tab.Title)); m_cmnuInfoBarButton.MenuItems.AddRange(BuildMenusForSideBarTab(tab)); MenuExtender.AddContextMenu(m_cmnuInfoBarButton); // Popup the loaded ContextMenu just below the button. m_cmnuInfoBarButton.Show(button, new Point(0, button.Bottom)); }