// Enumerate all submenus. public IEnumerable <SubMenu> SubMenus(bool refresh) { if (refresh) { Refresh(); } if (menuItems != null) { foreach (MenuItem item in menuItems) { if (item != null) { SubMenu subMenu = item as SubMenu; if (subMenu != null) { yield return(subMenu); } } } } }
protected void Reload() { // Common.Trace("Reload menu info: " + Caption); // Build a new menu menuItems = new List<MenuItem>(1); subMenuCount = 0; foreach (Task task in tasks) { ITaskMenuItem[] taskMenuItems = (task == null ? null : task.GetMenuItems(this.taskMenuItem)); // add to the context menu item list if (taskMenuItems != null) { for (int i = 0; i < taskMenuItems.Length; i++) { ITaskMenuItem taskMenuItem = taskMenuItems[i]; if (taskMenuItem != null) { // update an existing menu or add a new one int index = menuItems.FindIndex(delegate(MenuItem inf) { return (inf == null ? false : inf.TaskMenuItem == taskMenuItem); }); MenuItem item; if (index >= 0) { item = menuItems[index]; } else { if (taskMenuItem.Kind == TaskMenuKind.Submenu) { List<int> path = new List<int>(indices); path.Add(subMenuCount); subMenuCount++; item = new SubMenu(taskMenuItem, path); } else { item = new MenuItem(taskMenuItem); } menuItems.Add(item); } item.AddTask(task); } } } } // finally, set the status of each command: // - disable those menus that are not supported by all selected tasks // - set checkable menus // - disable those checkable menus that disagree on the checked state for (int item = 0; item < menuItems.Count; item++) { MenuItem menuItem = menuItems[item]; if (menuItem != null) menuItem.SetStatus(tasks.Count); } }
protected void Reload() { // Common.Trace("Reload menu info: " + Caption); // Build a new menu menuItems = new List <MenuItem>(1); subMenuCount = 0; foreach (Task task in tasks) { ITaskMenuItem[] taskMenuItems = (task == null ? null : task.GetMenuItems(this.taskMenuItem)); // add to the context menu item list if (taskMenuItems != null) { for (int i = 0; i < taskMenuItems.Length; i++) { ITaskMenuItem taskMenuItem = taskMenuItems[i]; if (taskMenuItem != null) { // update an existing menu or add a new one int index = menuItems.FindIndex(delegate(MenuItem inf) { return(inf == null ? false : inf.TaskMenuItem == taskMenuItem); }); MenuItem item; if (index >= 0) { item = menuItems[index]; } else { if (taskMenuItem.Kind == TaskMenuKind.Submenu) { List <int> path = new List <int>(indices); path.Add(subMenuCount); subMenuCount++; item = new SubMenu(taskMenuItem, path); } else { item = new MenuItem(taskMenuItem); } menuItems.Add(item); } item.AddTask(task); } } } } // finally, set the status of each command: // - disable those menus that are not supported by all selected tasks // - set checkable menus // - disable those checkable menus that disagree on the checked state for (int item = 0; item < menuItems.Count; item++) { MenuItem menuItem = menuItems[item]; if (menuItem != null) { menuItem.SetStatus(tasks.Count); } } }