/// <summary> /// Populates the current menu with items based on the actions collection /// </summary> /// <param name="actions">List of primary actions</param> /// <param name="actions2">List of view specific actions</param> protected virtual void PopulateToolbar(IHaveActions actions, IHaveActions actions2 = null) { Children.Clear(); if (actions == null) { return; } var actionList = ViewActionHelper.GetConsolidatedActions(actions, actions2, actionsDisplayFilter: RootViewActionDisplayMode, actions2DisplayFilter: LocalViewActionDisplayMode, flagFirstSecondaryActionAsNewGroup: true); var actionCounter = 0; foreach (var action in actionList) { if (!IncludeAction(action)) { continue; } if (actionCounter > 0 && action.BeginGroup) { Children.Add(new ViewActionToolbarSeparator()); } Children.Add(new ViewActionToolbarButton(action)); actionCounter++; } Visibility = Children.Count > 0 ? Visibility.Visible : Visibility.Collapsed; }
/// <summary> /// Populates the current ribbon with items based on the actions collection /// </summary> protected virtual void PopulateStack() { var actions = Model as IHaveActions; var viewResult = SelectedView as ViewResult; IHaveActions actions2 = null; if (viewResult != null) { actions2 = viewResult.Model as IHaveActions; } Children.Clear(); if (actions == null) { Visibility = Visibility.Collapsed; return; } Visibility = Visibility.Visible; var actionList = ViewActionHelper.GetConsolidatedActions(actions, actions2); foreach (var action in actionList) { var button = new ViewActionStackPanelButton { Command = action, ToolTip = action.Caption, DataContext = action }; if (ActionFilter == ViewActionStackPanelActionFilter.ShowPinned) { button.SetBinding(VisibilityProperty, new MultiBinding { Bindings = { new Binding("Visibility"), new Binding("IsPinned") }, Converter = new VisibilityAndPinnedConverter() }); } else { button.SetBinding(VisibilityProperty, new Binding("Visibility")); } var action2 = action as ViewAction; if (action2 != null) { var rectangle = new Rectangle { Fill = action2.PopulatedBrush }; button.Content = rectangle; } Children.Add(button); } }
/// <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> /// Returns a list of consolidated actions from two different action lists. /// </summary> /// <param name="actions">The first set of actions.</param> /// <param name="actions2">The second set of actions.</param> /// <param name="defaultEmptyCategory">The default empty category.</param> /// <param name="actionsDisplayFilter">The actions display filter.</param> /// <param name="flagFirstSecondaryActionAsNewGroup">Defines whether the first secondary action is to be flagged as a new group.</param> /// <param name="actions2DisplayFilter">Display filter for the secondary set of actions</param> /// <param name="viewModel">Optional view model object</param> /// <returns>ObservableCollection<IViewAction>.</returns> public virtual ObservableCollection <IViewAction> GetConsolidatedActions(IHaveActions actions, IHaveActions actions2 = null, string defaultEmptyCategory = "", ViewActionDisplayMode actionsDisplayFilter = ViewActionDisplayMode.All, bool flagFirstSecondaryActionAsNewGroup = false, ViewActionDisplayMode actions2DisplayFilter = ViewActionDisplayMode.All, object viewModel = null) => ViewActionHelper.GetConsolidatedActions(actions, actions2, defaultEmptyCategory, actionsDisplayFilter, flagFirstSecondaryActionAsNewGroup, actions2DisplayFilter);
/// <summary> /// Gets all actions for the specified category. /// </summary> /// <param name="actions">The actions.</param> /// <param name="category">The category.</param> /// <param name="indentLevel">The indent level.</param> /// <param name="emptyCategory">The empty category.</param> /// <param name="orderByGroupTitle">if set to <c>true</c> [order by group title].</param> /// <param name="viewModel">Optional view model object</param> /// <returns>IEnumerable<IViewAction>.</returns> public virtual IEnumerable <IViewAction> GetAllActionsForCategory(IEnumerable <IViewAction> actions, ViewActionCategory category, int indentLevel = 0, string emptyCategory = "File", bool orderByGroupTitle = true, object viewModel = null) => ViewActionHelper.GetAllActionsForCategory(actions, category, indentLevel, emptyCategory, orderByGroupTitle);
/// <summary> /// Adds sub-items for the specified menu item and category /// </summary> /// <param name="menuItem">Parent menu item</param> /// <param name="category">Category we are interested in</param> /// <param name="actions">Actions to consider</param> /// <param name="indentLevel">Current hierarchical indentation level</param> private void PopulateSubCategories(MenuItem menuItem, ViewActionCategory category, IEnumerable <IViewAction> actions, int indentLevel = 0) { var populatedCategories = new List <string>(); if (actions == null) { return; } var viewActions = actions as IViewAction[] ?? actions.ToArray(); var matchingActions = ViewActionPolicy != null?ViewActionPolicy.GetAllActionsForCategory(viewActions, category, indentLevel, orderByGroupTitle : false, viewModel : this) : ViewActionHelper.GetAllActionsForCategory(viewActions, category, indentLevel, orderByGroupTitle: false); var addedMenuItems = 0; foreach (var matchingAction in matchingActions) { if (addedMenuItems > 0 && matchingAction.BeginGroup) { menuItem.Items.Add(new Separator()); } if (matchingAction.Categories != null && matchingAction.Categories.Count > indentLevel + 1 && !populatedCategories.Contains(matchingAction.Categories[indentLevel].Id)) // This is further down in a sub-category even { populatedCategories.Add(matchingAction.Categories[indentLevel].Id); var newMenuItem = new ViewActionMenuItem { Header = matchingAction.Categories[indentLevel + 1].Caption }; var icon = new ThemeIcon { UseFallbackIcon = false }; icon.SetBinding(ThemeIcon.IconResourceKeyProperty, new Binding("BrushResourceKey")); newMenuItem.Icon = icon; CreateMenuItemBinding(matchingAction, newMenuItem); PopulateSubCategories(newMenuItem, matchingAction.Categories[indentLevel + 1], viewActions, indentLevel + 1); menuItem.Items.Add(newMenuItem); addedMenuItems++; } else { var newMenuItem1 = new ViewActionMenuItem { Header = GetMenuTitle(matchingAction), Command = matchingAction, DataContext = matchingAction }; HandleMenuShortcutKey(newMenuItem1, matchingAction); if (matchingAction.ViewActionType == ViewActionTypes.Toggle) { newMenuItem1.IsCheckable = true; newMenuItem1.SetBinding(MenuItem.IsCheckedProperty, new Binding("IsChecked") { Source = matchingAction, Mode = BindingMode.OneWay }); } var realMatchingAction = matchingAction as ViewAction; if (realMatchingAction != null && !string.IsNullOrEmpty(realMatchingAction.ToolTipText)) { newMenuItem1.ToolTip = realMatchingAction.ToolTipText; } var icon = new ThemeIcon { FallbackIconResourceKey = string.Empty }; icon.SetBinding(ThemeIcon.IconResourceKeyProperty, new Binding("BrushResourceKey")); newMenuItem1.Icon = icon; CreateMenuItemBinding(matchingAction, newMenuItem1); menuItem.Items.Add(newMenuItem1); addedMenuItems++; } } }
/// <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> /// 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(); }