// 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; using System.Globalization; using System.Text; using Microsoft.CmdPal.Ext.TimeDate.Helpers; using Microsoft.CmdPal.Ext.TimeDate.Pages; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CmdPal.Ext.TimeDate; public sealed partial class TimeDateCommandsProvider : CommandProvider { private readonly CommandItem _command; private static readonly SettingsManager _settingsManager = new SettingsManager(); private static readonly CompositeFormat MicrosoftPluginTimedatePluginDescription = System.Text.CompositeFormat.Parse(Resources.Microsoft_plugin_timedate_plugin_description); private static readonly TimeDateExtensionPage _timeDateExtensionPage = new(_settingsManager); private readonly FallbackTimeDateItem _fallbackTimeDateItem = new(_settingsManager); public TimeDateCommandsProvider() { DisplayName = Resources.Microsoft_plugin_timedate_plugin_name; Id = "com.microsoft.cmdpal.builtin.datetime"; _command = new CommandItem(_timeDateExtensionPage) { Icon = _timeDateExtensionPage.Icon, Title = Resources.Microsoft_plugin_timedate_plugin_name, Subtitle = GetTranslatedPluginDescription(), MoreCommands = [new CommandContextItem(_settingsManager.Settings.SettingsPage)], }; Icon = _timeDateExtensionPage.Icon; Settings = _settingsManager.Settings; } private string GetTranslatedPluginDescription() { // The extra strings for the examples are required for correct translations. var timeExample = Resources.Microsoft_plugin_timedate_plugin_description_example_time + "::" + DateTime.Now.ToString("T", CultureInfo.CurrentCulture); var dayExample = Resources.Microsoft_plugin_timedate_plugin_description_example_day + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture); var calendarWeekExample = Resources.Microsoft_plugin_timedate_plugin_description_example_calendarWeek + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture); return string.Format(CultureInfo.CurrentCulture, MicrosoftPluginTimedatePluginDescription, Resources.Microsoft_plugin_timedate_plugin_description_example_day, dayExample, timeExample, calendarWeekExample); } public override ICommandItem[] TopLevelCommands() => [_command]; public override IFallbackCommandItem[] FallbackCommands() => [_fallbackTimeDateItem]; }