mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
[PT Run] TimeDate plugin (#16662)
* create plugin * Update plugin code * fix deps * last changes * unix * new results and small changes * Update settings name * make spellcheck happy * new time/date formats * add comment * code cleanup, installer, signing pipeline * fix unix result * UnitTests * spell fix * Update tests, Timestamp query feature * new formats * last changes * last changes * unit tests and fixes * cjhanges and fixes * fix installer * fix settings class init * context menu * fix tests * add settings tests * update/fix DateTimeResult tests * small improvements * update pipeline * enable analyzer * fixes and improvements * spell fix * dev docs * doc fixes * spell fix * last changes * changes and fixes * fixes and test updates * improvements * last changes * try to fix tests * remove obsolete code * add info to test log * fix search * tag fix * tests * change tests * update dev docs * fix spelling * fix culture for ui strings * improvements based on feedback * improve global search * improve text * docs improvement * add settings note * fix and update tests * fix spelling
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
// 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.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
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();
|
||||
|
||||
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,
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
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)
|
||||
{
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName: nameof(query));
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
string timeExample = DateTime.Now.ToString("T", CultureInfo.CurrentCulture);
|
||||
string dateExample = DateTime.Now.ToString("d", CultureInfo.CurrentCulture);
|
||||
return string.Format(CultureInfo.CurrentCulture, Resources.Microsoft_plugin_timedate_plugin_description, dateExample, timeExample);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user