/// <summary> /// Converts from a <see cref="ICommand"/> to a menu header string. /// </summary> /// <param name="command">The <see cref="ICommand"/> object to convert.</param> /// <returns> /// If <paramref name="command"/> is an instance of one of the types that have an associated key to obtain a menu header, it returns this string. /// Otherwise, if the command is a <see cref="RoutedUICommand"/> it returns its text (already localized by the system). /// Otherwise, this method returns null. /// </returns> private static string GetItemText(ICommand command) { string ItemHeader; switch (command) { case ActiveDocumentRoutedCommand AsActiveDocumentCommand: ItemHeader = AsActiveDocumentCommand.InactiveMenuHeader; break; case LocalizedRoutedCommand AsLocalizedRoutedCommand: ItemHeader = AsLocalizedRoutedCommand.MenuHeader; if (ItemHeader.Contains(LocalizedRoutedCommand.ApplicationNamePattern)) { ItemHeader = ItemHeader.Replace(LocalizedRoutedCommand.ApplicationNamePattern, string.Empty); } break; case ExtendedRoutedCommand AsExtendedRoutedCommand: ItemHeader = AsExtendedRoutedCommand.MenuHeader; break; case RoutedUICommand AsUICommand: ItemHeader = AsUICommand.Text; break; default: throw new ArgumentOutOfRangeException(nameof(command)); } return(ItemHeader); }
/// <summary> /// Gets the menu header of a command for a source element. /// </summary> /// <param name="command">The command.</param> /// <param name="activeDocument">The active document.</param> /// <param name="applicationName">The application name.</param> /// <returns>The header.</returns> protected virtual string GetItemHeader(ICommand command, IDocument?activeDocument, string?applicationName) { string ItemHeader; switch (command) { case ActiveDocumentRoutedCommand AsActiveDocumentCommand: if (activeDocument == null) { ItemHeader = AsActiveDocumentCommand.InactiveMenuHeader; } else { string CommandTextFormat = AsActiveDocumentCommand.MenuHeader; ItemHeader = string.Format(CultureInfo.CurrentCulture, CommandTextFormat, activeDocument.Path.HeaderName); } break; case LocalizedRoutedCommand AsLocalizedRoutedCommand: ItemHeader = AsLocalizedRoutedCommand.MenuHeader; if (ItemHeader.Contains(LocalizedRoutedCommand.ApplicationNamePattern) && applicationName != null) { ItemHeader = ItemHeader.Replace(LocalizedRoutedCommand.ApplicationNamePattern, applicationName); } break; case ExtendedRoutedCommand AsExtendedRoutedCommand: ItemHeader = AsExtendedRoutedCommand.MenuHeader; break; case RoutedUICommand AsUICommand: ItemHeader = AsUICommand.Text; break; default: throw new ArgumentOutOfRangeException(nameof(command)); } return(ItemHeader); }