/// <summary> /// Populates the current menu with items based on the actions collection /// </summary> /// <param name="actions">List of actions</param> private void PopulateMenu(ObservableCollection <IViewAction> actions) { RemoveAllMenuKeyBindings(); Items.Clear(); if (actions == null) { return; } var rootCategories = ViewActionPolicy != null?ViewActionPolicy.GetTopLevelActionCategories(actions, "File", "File", this) : ViewActionHelper.GetTopLevelActionCategories(actions, "File", "File"); foreach (var category in rootCategories) { var menuItem = new TopLevelViewActionMenuItem { Header = GetMenuTitle(category) }; menuItem.SetBinding(VisibilityProperty, new Binding("Count") { Source = menuItem.Items, Converter = new ItemsCollectionCountToVisibleConverter(menuItem.Items) }); PopulateSubCategories(menuItem, category, actions); Items.Add(menuItem); } CreateAllMenuKeyBindings(); }
/// <summary> /// Gets the top level action categories. /// </summary> /// <param name="actions">The actions.</param> /// <param name="emptyGlobalCategoryTitle">The empty global category title.</param> /// <param name="emptyLocalCategoryTitle">The empty local category title.</param> /// <param name="viewModel">Optional view model object</param> /// <returns>IEnumerable<ViewActionCategory>.</returns> public virtual IEnumerable <ViewActionCategory> GetTopLevelActionCategories(IEnumerable <IViewAction> actions, string emptyGlobalCategoryTitle = "", string emptyLocalCategoryTitle = "", object viewModel = null) => ViewActionHelper.GetTopLevelActionCategories(actions, emptyGlobalCategoryTitle, emptyLocalCategoryTitle);
/// <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(); }