SourceWriter.ViewController.AssembleMenu C# (CSharp) Method

AssembleMenu() private method

Recursively build a menu from the set of Language Format Commands.
private AssembleMenu ( NSMenu menu, List commands ) : void
menu NSMenu The NSMenu to grow.
commands List The list of s.
return void
		private void AssembleMenu(NSMenu menu, List<LanguageFormatCommand> commands) {
			NSMenuItem menuItem;

			// Add any formatting commands to the Formatting menu
			foreach (LanguageFormatCommand command in commands) {
				// Add separator or item?
				if (command.Title == "") {
					menuItem = NSMenuItem.SeparatorItem;
				} else {
					menuItem = new NSMenuItem (command.Title);

					// Submenu?
					if (command.SubCommands.Count > 0) {
						// Yes, populate submenu
						menuItem.Submenu = new NSMenu (command.Title);
						AssembleMenu (menuItem.Submenu, command.SubCommands);
					} else {
						// No, add normal menu item
						menuItem.Activated += (sender, e) => {
							// Apply the command on the selected text
							TextEditor.PerformFormattingCommand (command);
						};
					}
				}
				menu.AddItem (menuItem);
			}
		}
		#endregion