public void Render(MenuItem parent, MRUStringCollection mruFileList, int textWidth, System.EventHandler mruMenuItem_Click) { // Check parameter values if ( parent == null ) throw new ArgumentNullException("parent cannot be null"); if ( mruFileList == null ) throw new ArgumentNullException("mruFileList cannot be null"); if ( textWidth < 0 ) throw new ArgumentOutOfRangeException("textWidth cannot be less than zero"); if ( mruMenuItem_Click == null ) throw new ArgumentNullException("menuItemOnClick cannot be null"); // Clear MenuItems parent.MenuItems.Clear(); parent.Enabled = false; if ( mruFileList.Count > 0 ) { // Fill and resequence submenu foreach( string mruFileName in mruFileList ) { string formattedAccessKey = MenuFormatter.FormatAccessKey(parent.MenuItems.Count + 1); string formattedFilePath = MenuFormatter.FormatFilePath(mruFileName, textWidth); MenuItem miNew = new MRUMenuItem(formattedAccessKey + " " + formattedFilePath, new System.EventHandler(mruMenuItem_Click)); parent.MenuItems.Add(parent.MenuItems.Count, miNew); } parent.Enabled = true; } }
public void Render(MenuItem parent, MRUStringCollection mruFileList, int textWidth, System.EventHandler mruMenuItem_Click) { // Check parameter values if ( parent == null ) throw new ArgumentNullException("parent cannot be null"); if ( mruFileList == null ) throw new ArgumentNullException("mruFileList cannot be null"); if ( textWidth < 0 ) throw new ArgumentOutOfRangeException("textWidth cannot be less than zero"); if ( mruMenuItem_Click == null ) throw new ArgumentNullException("menuItemOnClick cannot be null"); // Clear MenuItems Menu.MenuItemCollection menuItems = parent.Parent.MenuItems; MenuItem miFirst = menuItems[parent.Index + 1]; while ( miFirst is MRUMenuItem ) { menuItems.Remove(miFirst); miFirst = menuItems[parent.Index + 1]; } parent.Enabled = false; parent.Visible = true; // Fill MRU menu if ( mruFileList.Count > 0 ) { int menuPosition = 0; foreach( string mruFileName in mruFileList ) { menuPosition++; string formattedAccessKey = MenuFormatter.FormatAccessKey(menuPosition); string formattedFilePath = MenuFormatter.FormatFilePath(mruFileName, textWidth); MenuItem miNew = new MRUMenuItem(formattedAccessKey + " " + formattedFilePath, new System.EventHandler(mruMenuItem_Click)); parent.Parent.MenuItems.Add(parent.Index + menuPosition, miNew); } parent.Enabled = true; parent.Visible = false; } }