/// <summary> /// Computes menu items corresponding to a given list of definitions /// </summary> /// <param name="list">List<> containing the elements to be transformed into the menu items</param> /// <returns>A list of menu items resulting from the array list</returns> // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert private MenuItem[] GetItems(List <object> list) // Issue 10 - End { MenuItem[] items = new MenuItem[list.Count]; for (int i = 0; i < items.Length; i++) { object o = list[i]; if (o is MenuCommand) { items[i] = new BoxMenuItem(o as MenuCommand); (items[i] as BoxMenuItem).SendCommand += new SendCommandEventHandler(MenuDef_SendCommand); } else if (o is GenericNode) { GenericNode node = o as GenericNode; items[i] = new MenuItem(node.Name); items[i].MenuItems.AddRange(GetItems(node.Elements)); } } return(items); }
/// <summary> /// Computes menu items corresponding to a given list of definitions /// </summary> /// <param name="list">List<> containing the elements to be transformed into the menu items</param> /// <returns>A list of menu items resulting from the array list</returns> // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert private MenuItem[] GetItems( List<object> list ) // Issue 10 - End { MenuItem[] items = new MenuItem[ list.Count ]; for ( int i = 0; i < items.Length; i++ ) { object o = list[ i ]; if ( o is MenuCommand ) { items[ i ] = new BoxMenuItem( o as MenuCommand ); ( items[ i ] as BoxMenuItem ).SendCommand += new SendCommandEventHandler(MenuDef_SendCommand); } else if ( o is GenericNode ) { GenericNode node = o as GenericNode; items[ i ] = new MenuItem( node.Name ); items[ i ].MenuItems.AddRange( GetItems( node.Elements ) ); } } return items; }
/// <summary> /// A menu item has been clicked and the default index should be changed /// </summary> private void bmi_Click(object sender, EventArgs e) { BoxMenuItem bmi = sender as BoxMenuItem; if (bmi != null) { m_DefaultIndex = m_Commands.IndexOf(bmi.Command); OnCommandChanged(new CommandChangedEventArgs(DefaultCommand)); OnSendCommand(new SendCommandEventArgs(DefaultCommand.Command, true)); } }
/// <summary> /// Computes the context menu /// </summary> private void DoMenu() { if (m_Menu != null) { m_Menu.Dispose(); } m_Menu = new ContextMenu(); for (int i = 0; i < m_Commands.Count; i++) { // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert BoxMenuItem bmi = (m_Commands[i]).MenuItem; // Issue 10 - End bmi.Checked = (m_DefaultIndex == i); bmi.Click += new EventHandler(bmi_Click); m_Menu.MenuItems.Add(bmi); } m_Menu.Popup += new EventHandler(m_Menu_Popup); }