TimeDateCommandsProvider.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Globalization; 7 using System.Text; 8 using Microsoft.CmdPal.Ext.TimeDate.Helpers; 9 using Microsoft.CmdPal.Ext.TimeDate.Pages; 10 using Microsoft.CommandPalette.Extensions; 11 using Microsoft.CommandPalette.Extensions.Toolkit; 12 13 namespace Microsoft.CmdPal.Ext.TimeDate; 14 15 public sealed partial class TimeDateCommandsProvider : CommandProvider 16 { 17 private readonly CommandItem _command; 18 private static readonly SettingsManager _settingsManager = new SettingsManager(); 19 private static readonly CompositeFormat MicrosoftPluginTimedatePluginDescription = System.Text.CompositeFormat.Parse(Resources.Microsoft_plugin_timedate_plugin_description); 20 private static readonly TimeDateExtensionPage _timeDateExtensionPage = new(_settingsManager); 21 private readonly FallbackTimeDateItem _fallbackTimeDateItem = new(_settingsManager); 22 23 public TimeDateCommandsProvider() 24 { 25 DisplayName = Resources.Microsoft_plugin_timedate_plugin_name; 26 Id = "com.microsoft.cmdpal.builtin.datetime"; 27 _command = new CommandItem(_timeDateExtensionPage) 28 { 29 Icon = _timeDateExtensionPage.Icon, 30 Title = Resources.Microsoft_plugin_timedate_plugin_name, 31 MoreCommands = [new CommandContextItem(_settingsManager.Settings.SettingsPage)], 32 }; 33 34 Icon = _timeDateExtensionPage.Icon; 35 Settings = _settingsManager.Settings; 36 } 37 38 private string GetTranslatedPluginDescription() 39 { 40 // The extra strings for the examples are required for correct translations. 41 var timeExample = Resources.Microsoft_plugin_timedate_plugin_description_example_time + "::" + DateTime.Now.ToString("T", CultureInfo.CurrentCulture); 42 var dayExample = Resources.Microsoft_plugin_timedate_plugin_description_example_day + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture); 43 var calendarWeekExample = Resources.Microsoft_plugin_timedate_plugin_description_example_calendarWeek + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture); 44 return string.Format(CultureInfo.CurrentCulture, MicrosoftPluginTimedatePluginDescription, Resources.Microsoft_plugin_timedate_plugin_description_example_day, dayExample, timeExample, calendarWeekExample); 45 } 46 47 public override ICommandItem[] TopLevelCommands() => [_command]; 48 49 public override IFallbackCommandItem[] FallbackCommands() => [_fallbackTimeDateItem]; 50 }