2022-03-17 20:33:05 +01:00
|
|
|
// 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.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
2023-12-28 13:37:13 +03:00
|
|
|
using System.Text;
|
2022-03-17 20:33:05 +01:00
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
2024-09-16 16:09:43 -04:00
|
|
|
|
2022-03-17 20:33:05 +01:00
|
|
|
using ManagedCommon;
|
|
|
|
|
using Microsoft.PowerToys.Run.Plugin.TimeDate.Components;
|
|
|
|
|
using Microsoft.PowerToys.Run.Plugin.TimeDate.Properties;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Run.Plugin.TimeDate
|
|
|
|
|
{
|
|
|
|
|
public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu
|
|
|
|
|
{
|
|
|
|
|
private PluginInitContext _context;
|
|
|
|
|
|
|
|
|
|
public string IconTheme { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Name => Resources.Microsoft_plugin_timedate_plugin_name;
|
|
|
|
|
|
|
|
|
|
public string Description => GetTranslatedPluginDescription();
|
|
|
|
|
|
2023-10-11 16:37:15 +02:00
|
|
|
public static string PluginID => "5D69806A5A474115821C3E4C56B9C793";
|
|
|
|
|
|
2023-12-28 13:37:13 +03:00
|
|
|
private static readonly CompositeFormat MicrosoftPluginTimedatePluginDescription = System.Text.CompositeFormat.Parse(Properties.Resources.Microsoft_plugin_timedate_plugin_description);
|
|
|
|
|
|
2022-03-17 20:33:05 +01:00
|
|
|
public IEnumerable<PluginAdditionalOption> AdditionalOptions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return TimeDateSettings.GetAdditionalOptions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
|
|
|
|
{
|
|
|
|
|
if (!(selectedResult?.ContextData is AvailableResult data))
|
|
|
|
|
{
|
|
|
|
|
return new List<ContextMenuResult>(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new List<ContextMenuResult>()
|
|
|
|
|
{
|
|
|
|
|
new ContextMenuResult
|
|
|
|
|
{
|
|
|
|
|
AcceleratorKey = Key.C,
|
|
|
|
|
AcceleratorModifiers = ModifierKeys.Control,
|
2023-11-20 11:23:26 +01:00
|
|
|
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
|
2022-03-17 20:33:05 +01:00
|
|
|
Glyph = "\xE8C8", // E8C8 => Symbol: Copy
|
|
|
|
|
Title = Resources.Microsoft_plugin_timedate_CopyToClipboard,
|
|
|
|
|
Action = _ => ResultHelper.CopyToClipBoard(data.Value),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init(PluginInitContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
_context.API.ThemeChanged += OnThemeChanged;
|
|
|
|
|
UpdateIconTheme(_context.API.GetCurrentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Result> Query(Query query)
|
|
|
|
|
{
|
2023-11-22 12:46:59 -05:00
|
|
|
ArgumentNullException.ThrowIfNull(query);
|
2022-03-17 20:33:05 +01:00
|
|
|
|
|
|
|
|
return SearchController.ExecuteSearch(query, IconTheme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateIconTheme(Theme theme)
|
|
|
|
|
{
|
|
|
|
|
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
|
|
|
|
|
{
|
|
|
|
|
IconTheme = "light";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IconTheme = "dark";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
|
|
|
|
|
{
|
|
|
|
|
UpdateIconTheme(newTheme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginDescription()
|
|
|
|
|
{
|
2022-06-28 20:21:08 +02:00
|
|
|
// The extra strings for the examples are required for correct translations.
|
|
|
|
|
string timeExample = Resources.Microsoft_plugin_timedate_plugin_description_example_time + "::" + DateTime.Now.ToString("T", CultureInfo.CurrentCulture);
|
|
|
|
|
string dayExample = Resources.Microsoft_plugin_timedate_plugin_description_example_day + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture);
|
|
|
|
|
string calendarWeekExample = Resources.Microsoft_plugin_timedate_plugin_description_example_calendarWeek + "::" + DateTime.Now.ToString("d", CultureInfo.CurrentCulture);
|
2023-12-28 13:37:13 +03:00
|
|
|
return string.Format(CultureInfo.CurrentCulture, MicrosoftPluginTimedatePluginDescription, Resources.Microsoft_plugin_timedate_plugin_description_example_day, dayExample, timeExample, calendarWeekExample);
|
2022-03-17 20:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginTitle()
|
|
|
|
|
{
|
|
|
|
|
return Resources.Microsoft_plugin_timedate_plugin_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Control CreateSettingPanel()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateSettings(PowerLauncherPluginSettings settings)
|
|
|
|
|
{
|
|
|
|
|
TimeDateSettings.Instance.UpdateSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|