/// <summary> /// Populates the current items control with items based on the actions collection /// </summary> /// <param name="actions">List of actions</param> protected virtual void PopulateItems(IHaveActions actions) { RemoveAllMenuKeyBindings(); Items.Clear(); if (actions == null || actions.Actions == null) { return; } var actionList = actions.Actions.ToList(); var rootCategories = ViewActionPolicy != null?ViewActionPolicy.GetTopLevelActionCategories(actionList, EmptyGlobalCategoryTitle) : ViewActionHelper.GetTopLevelActionCategories(actionList, EmptyGlobalCategoryTitle); var viewActionCategories = rootCategories as ViewActionCategory[] ?? rootCategories.ToArray(); foreach (var category in viewActionCategories) { var matchingActions = ViewActionPolicy != null?ViewActionPolicy.GetAllActionsForCategory(actionList, category, orderByGroupTitle : OrderByGroupTitle) : ViewActionHelper.GetAllActionsForCategory(actionList, category, orderByGroupTitle: OrderByGroupTitle); foreach (var action in matchingActions) { var wrapper = new DependencyViewActionWrapper(action); if (action.Categories.Count > 0) { MetroTiles.SetGroupName(wrapper, action.Categories[0].Id); MetroTiles.SetGroupTitle(wrapper, action.Categories[0].Caption); } else { MetroTiles.SetGroupName(wrapper, string.Empty); MetroTiles.SetGroupTitle(wrapper, string.Empty); } if (action.Availability != ViewActionAvailabilities.Unavailable) { MetroTiles.SetTileVisibility(wrapper, action.Visibility); } else { MetroTiles.SetTileVisibility(wrapper, Visibility.Collapsed); } Items.Add(wrapper); if (action.ShortcutKey == Key.None) { continue; } MenuKeyBindings.Add(new ViewActionMenuKeyBinding(action)); } } CreateAllMenuKeyBindings(); }
/// <summary> /// Populates the current items control with items based on the actions collection /// </summary> /// <param name="actions">List of actions</param> protected virtual void PopulateItems(IHaveActions actions) { RemoveAllMenuKeyBindings(); Items.Clear(); if (actions == null || actions.Actions == null) return; var actionList = actions.Actions.ToList(); var rootCategories = ViewActionHelper.GetTopLevelActionCategories(actionList, EmptyGlobalCategoryTitle); var viewActionCategories = rootCategories as ViewActionCategory[] ?? rootCategories.ToArray(); foreach (var category in viewActionCategories) { var matchingActions = ViewActionHelper.GetAllActionsForCategory(actionList, category, orderByGroupTitle: OrderByGroupTitle); foreach (var action in matchingActions) { var wrapper = new DependencyViewActionWrapper(action); if (action.Categories.Count > 0) { MetroTiles.SetGroupName(wrapper, action.Categories[0].Id); MetroTiles.SetGroupTitle(wrapper, action.Categories[0].Caption); } else { MetroTiles.SetGroupName(wrapper, string.Empty); MetroTiles.SetGroupTitle(wrapper, string.Empty); } if (action.Availability != ViewActionAvailabilities.Unavailable) MetroTiles.SetTileVisibility(wrapper, action.Visibility); else MetroTiles.SetTileVisibility(wrapper, Visibility.Collapsed); Items.Add(wrapper); if (action.ShortcutKey == Key.None) continue; MenuKeyBindings.Add(new ViewActionMenuKeyBinding(action)); } } CreateAllMenuKeyBindings(); }