/// <summary> /// Adds a new ribbon item to the main ribbon. /// </summary> /// <param name="ribbonControl">The ribbon item.</param> /// <exception cref="ArgumentNullException">The <paramref name="ribbonControl"/> is <c>null</c>.</exception> private void AddRibbonItem(IRibbonControl ribbonControl) { Argument.IsNotNull("ribbonControl", ribbonControl); Log.Debug("Adding ribbon item '{0}'", ribbonControl); var ribbon = GetService <Ribbon>(); RibbonTabItem tab; if (ribbonControl.Context == RibbonContext.View) { tab = ribbon.EnsureContextualTabItem(ribbonControl.TabItemHeader, ribbonControl.ContextualTabItemGroupName); } else { tab = ribbon.EnsureTabItem(ribbonControl.TabItemHeader); } var group = tab.EnsureGroupBox(ribbonControl.GroupBoxHeader); group.AddRibbonItem(ribbonControl); Log.Debug("Added ribbon item '{0}'", ribbonControl); }
/// <summary> /// Registers the specified ribbon item to the main ribbon. /// </summary> /// <param name="ribbonControl">The ribbon item.</param> /// <exception cref="ArgumentNullException">The <paramref name="ribbonControl" /> is <c>null</c>.</exception> /// <exception cref="NotSupportedException">The <c>Command</c> property of the <paramref name="ribbonControl" /> is <c>null</c>.</exception> /// <exception cref="NotSupportedException">The <c>Command</c> property of the <paramref name="ribbonControl" /> is <c>null</c>.</exception> public void RegisterRibbonItem(IRibbonControl ribbonControl) { Argument.IsNotNull("ribbonControl", ribbonControl); Argument.IsOfType(() => ribbonControl, typeof(IRibbonButton)); // TODO: consider using IRibbonButton parameter instead of IRibbonControl Argument.IsSupported(((IRibbonButton)ribbonControl).Command != null, "When registering a non-view-specific ribbon item, the Command property cannot be null"); AddRibbonItem(ribbonControl); }
/// <summary> /// Removes the specified ribbon item to the main ribbon. /// <para /> /// This method will ignore calls when the item is not available in the ribbon. /// </summary> /// <param name="ribbonControl">The ribbon item.</param> /// <exception cref="ArgumentNullException">The <paramref name="ribbonControl"/> is <c>null</c>.</exception> private void RemoveRibbonItem(IRibbonControl ribbonControl) { Argument.IsNotNull("ribbonControl", ribbonControl); Log.Debug("Removing ribbon '{0}'", ribbonControl); var ribbon = GetService <Ribbon>(); ribbon.RemoveItem(ribbonControl); Log.Debug("Removed ribbon '{0}'", ribbonControl); }
/// <summary> /// Registers the ribbon item bound to a specific view type. /// </summary> /// <param name="viewType">Type of the view.</param> /// <param name="ribbonControl">The ribbon item.</param> /// <param name="contextualTabGroupName">The contextual tab group name.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="ribbonControl"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="contextualTabGroupName"/> is <c>null</c> or whitespace.</exception> public void RegisterContextualRibbonItem(Type viewType, IRibbonControl ribbonControl, string contextualTabGroupName) { Argument.IsNotNull("viewType", viewType); Argument.IsNotNull("ribbonControl", ribbonControl); ribbonControl.ContextualTabItemGroupName = contextualTabGroupName; if (!_viewSpecificRibbonItems.ContainsKey(viewType)) { _viewSpecificRibbonItems[viewType] = new List <IRibbonControl>(); } _viewSpecificRibbonItems[viewType].Add(ribbonControl); AddRibbonItem(ribbonControl); }
/// <summary> /// Removes the specified <see cref="IRibbonControl"/> from the ribbon. /// </summary> /// <param name="ribbon">The ribbon.</param> /// <param name="ribbonControl">The ribbon item.</param> /// <exception cref="ArgumentNullException">The <paramref name="ribbon"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="ribbonControl"/> is <c>null</c>.</exception> public static void RemoveItem(this Ribbon ribbon, IRibbonControl ribbonControl) { Argument.IsNotNull("ribbon", ribbon); Argument.IsNotNull("ribbonControl", ribbonControl); var ribbonTab = (from tab in ribbon.Tabs where string.Equals(tab.Header.ToString(), ribbonControl.TabItemHeader) select tab).FirstOrDefault(); if (ribbonTab == null) { Log.Warning("Cannot find tab '{0}' on the ribbon, cannot remove item '{1}'", ribbonControl.TabItemHeader, ribbonControl.ItemHeader); return; } var ribbonGroupBox = (from groupBox in ribbonTab.Groups where string.Equals(groupBox.Header, ribbonControl.GroupBoxHeader) select groupBox).FirstOrDefault(); if (ribbonGroupBox == null) { Log.Warning("Cannot find group '{0}' on the ribbon, cannot remove item '{1}'", ribbonControl.GroupBoxHeader, ribbonControl.ItemHeader); return; } var ribbonButton = (from button in ribbonGroupBox.Items.Cast <Button>() where string.Equals(button.Header.ToString(), ribbonControl.ItemHeader) select button).FirstOrDefault(); if (ribbonButton == null) { Log.Warning("Cannot find group '{0}' on the ribbon, cannot remove item '{1}'", ribbonControl.GroupBoxHeader, ribbonControl.ItemHeader); return; } ribbonGroupBox.Items.Remove(ribbonButton); }
/// <summary> /// Registers the ribbon item bound to a specific view type. /// </summary> /// <typeparam name="TView">The type of the T view.</typeparam> /// <param name="ribbonControl">The ribbon item.</param> /// <param name="contextualTabGroupName">The contextual tab group name.</param> /// <exception cref="ArgumentNullException">The <paramref name="ribbonControl"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="contextualTabGroupName"/> is <c>null</c> or whitespace.</exception> public void RegisterContextualRibbonItem <TView>(IRibbonControl ribbonControl, string contextualTabGroupName) where TView : DocumentView { RegisterContextualRibbonItem(typeof(TView), ribbonControl, contextualTabGroupName); }