// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Globalization; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CmdPal.Ext.TimeDate.Helpers; internal static class ResultHelper { /// /// Get the string based on the requested type /// /// Does the user search for system date/time? /// Id of the string. (Example: `MyString` for `MyString` and `MyStringNow`) /// Optional string id for now case /// The string from the resource file, or otherwise. internal static string SelectStringFromResources(bool isSystemTimeDate, string stringId, string stringIdNow = default) { return !isSystemTimeDate ? Resources.ResourceManager.GetString(stringId, CultureInfo.CurrentUICulture) ?? string.Empty : !string.IsNullOrEmpty(stringIdNow) ? Resources.ResourceManager.GetString(stringIdNow, CultureInfo.CurrentUICulture) ?? string.Empty : Resources.ResourceManager.GetString(stringId + "Now", CultureInfo.CurrentUICulture) ?? string.Empty; } public static IconInfo TimeIcon { get; } = new IconInfo("\uE823"); public static IconInfo CalendarIcon { get; } = new IconInfo("\uE787"); public static IconInfo TimeDateIcon { get; } = new IconInfo("\uEC92"); public static IconInfo ErrorIcon { get; } = IconHelpers.FromRelativePaths("Microsoft.CmdPal.Ext.TimeDate\\Assets\\Warning.light.png", "Microsoft.CmdPal.Ext.TimeDate\\Assets\\Warning.dark.png"); /// /// Gets a result with an error message that input can't be parsed /// /// Element of type . #pragma warning disable CA1863 // Use 'CompositeFormat' internal static ListItem CreateInvalidInputErrorResult() => new ListItem(new NoOpCommand()) { Title = Resources.Microsoft_plugin_timedate_InvalidInput_ErrorMessageTitle, Icon = ErrorIcon, Details = new Details() { Title = Resources.Microsoft_plugin_timedate_InvalidInput_DetailsHeader, // Because of translation we can't use 'CompositeFormat'. Body = string.Format(CultureInfo.CurrentCulture, Resources.Microsoft_plugin_timedate_InvalidInput_SupportedInput, "**", "\n\n", "\n\n* "), }, }; #pragma warning restore CA1863 // Use 'CompositeFormat' }