[PTRun]Remove the timezone plugin (#24306)

This commit is contained in:
Jaime Bernardo 2023-02-27 09:47:57 +00:00 committed by GitHub
parent 28144b6375
commit d08fcd85a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1 additions and 12446 deletions

View File

@ -121,7 +121,6 @@
"modules\\launcher\\Plugins\\Service\\Microsoft.PowerToys.Run.Plugin.Service.dll",
"modules\\launcher\\Plugins\\System\\Microsoft.PowerToys.Run.Plugin.System.dll",
"modules\\launcher\\Plugins\\TimeDate\\Microsoft.PowerToys.Run.Plugin.TimeDate.dll",
"modules\\launcher\\Plugins\\TimeZone\\Microsoft.PowerToys.Run.Plugin.TimeZone.dll",
"modules\\launcher\\Plugins\\WebSearch\\Community.PowerToys.Run.Plugin.WebSearch.dll",
"modules\\launcher\\Plugins\\WindowsTerminal\\Microsoft.PowerToys.Run.Plugin.WindowsTerminal.dll",

View File

@ -201,7 +201,6 @@ steps:
**\Wox.Test.dll
**\Microsoft.PowerToys.Run.Plugin.System.UnitTests.dll
**\Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.dll
**\Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests.dll
**\Microsoft.Plugin.WindowsTerminal.UnitTests.dll
**\Microsoft.Plugin.WindowWalker.UnitTests.dll
**\PreviewPaneUnitTests.dll

View File

@ -139,7 +139,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerLauncher", "src\module
{A2D583F0-B70C-4462-B1F0-8E81AFB7BA85} = {A2D583F0-B70C-4462-B1F0-8E81AFB7BA85}
{BB23A474-5058-4F75-8FA3-5FE3DE53CDF4} = {BB23A474-5058-4F75-8FA3-5FE3DE53CDF4}
{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}
{F44934A8-36F3-49B0-9465-3831BE041CDE} = {F44934A8-36F3-49B0-9465-3831BE041CDE}
{F8B870EB-D5F5-45BA-9CF7-A5C459818820} = {F8B870EB-D5F5-45BA-9CF7-A5C459818820}
{FD8EB419-FF9C-4D88-BB6F-BF6CED37747B} = {FD8EB419-FF9C-4D88-BB6F-BF6CED37747B}
{FDB3555B-58EF-4AE6-B5F1-904719637AB4} = {FDB3555B-58EF-4AE6-B5F1-904719637AB4}
@ -396,8 +395,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests-StlThumbnailProvi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonacoPreviewHandler", "src\modules\previewpane\MonacoPreviewHandler\MonacoPreviewHandler.csproj", "{04B193D7-3E21-46B8-A958-89B63A8A69DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Run.Plugin.TimeZone", "src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.TimeZone\Microsoft.PowerToys.Run.Plugin.TimeZone.csproj", "{F44934A8-36F3-49B0-9465-3831BE041CDE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Run.Plugin.TimeDate", "src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.TimeDate\Microsoft.PowerToys.Run.Plugin.TimeDate.csproj", "{5BDBD6C9-A31F-4CEB-871A-5E9E709197EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests", "src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests\Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.csproj", "{FD464B4C-2F68-4D06-91E7-4208146C41F5}"
@ -410,8 +407,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRenameUI", "src\module
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRenameContextMenu", "src\modules\powerrename\PowerRenameContextMenu\PowerRenameContextMenu.vcxproj", "{1DBBB112-4BB1-444B-8EBB-E66555C76BA6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests", "src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests\Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests.csproj", "{C5D46169-5334-48C3-8C28-644C72832E54}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Run.Plugin.OneNote", "src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.OneNote\Microsoft.PowerToys.Run.Plugin.OneNote.csproj", "{5A1DB2F0-0715-4B3B-98E6-79BC41540045}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageResizerContextMenu", "src\modules\imageresizer\ImageResizerContextMenu\ImageResizerContextMenu.vcxproj", "{93B72A06-C8BD-484F-A6F7-C9F280B150BF}"
@ -1586,17 +1581,6 @@ Global
{04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x64.Build.0 = Release|x64
{04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x86.ActiveCfg = Release|x64
{04B193D7-3E21-46B8-A958-89B63A8A69DE}.Release|x86.Build.0 = Release|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|ARM64.ActiveCfg = Debug|ARM64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|ARM64.Build.0 = Debug|ARM64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|x64.ActiveCfg = Debug|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|x64.Build.0 = Debug|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Debug|x86.ActiveCfg = Debug|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Release|ARM64.ActiveCfg = Release|ARM64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Release|ARM64.Build.0 = Release|ARM64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Release|x64.ActiveCfg = Release|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Release|x64.Build.0 = Release|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Release|x86.ActiveCfg = Release|x64
{F44934A8-36F3-49B0-9465-3831BE041CDE}.Release|x86.Build.0 = Release|x64
{5BDBD6C9-A31F-4CEB-871A-5E9E709197EF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{5BDBD6C9-A31F-4CEB-871A-5E9E709197EF}.Debug|ARM64.Build.0 = Debug|ARM64
{5BDBD6C9-A31F-4CEB-871A-5E9E709197EF}.Debug|x64.ActiveCfg = Debug|x64
@ -1668,18 +1652,6 @@ Global
{1DBBB112-4BB1-444B-8EBB-E66555C76BA6}.Release|x64.Build.0 = Release|x64
{1DBBB112-4BB1-444B-8EBB-E66555C76BA6}.Release|x86.ActiveCfg = Release|x64
{1DBBB112-4BB1-444B-8EBB-E66555C76BA6}.Release|x86.Build.0 = Release|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Debug|ARM64.ActiveCfg = Debug|ARM64
{C5D46169-5334-48C3-8C28-644C72832E54}.Debug|ARM64.Build.0 = Debug|ARM64
{C5D46169-5334-48C3-8C28-644C72832E54}.Debug|x64.ActiveCfg = Debug|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Debug|x64.Build.0 = Debug|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Debug|x86.ActiveCfg = Debug|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Debug|x86.Build.0 = Debug|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Release|ARM64.ActiveCfg = Release|ARM64
{C5D46169-5334-48C3-8C28-644C72832E54}.Release|ARM64.Build.0 = Release|ARM64
{C5D46169-5334-48C3-8C28-644C72832E54}.Release|x64.ActiveCfg = Release|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Release|x64.Build.0 = Release|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Release|x86.ActiveCfg = Release|x64
{C5D46169-5334-48C3-8C28-644C72832E54}.Release|x86.Build.0 = Release|x64
{5A1DB2F0-0715-4B3B-98E6-79BC41540045}.Debug|ARM64.ActiveCfg = Debug|ARM64
{5A1DB2F0-0715-4B3B-98E6-79BC41540045}.Debug|ARM64.Build.0 = Debug|ARM64
{5A1DB2F0-0715-4B3B-98E6-79BC41540045}.Debug|x64.ActiveCfg = Debug|x64
@ -2221,14 +2193,12 @@ Global
{F7C8C0F1-5431-4347-89D0-8E5354F93CF2} = {2F305555-C296-497E-AC20-5FA1B237996A}
{F1F6B6B6-9F18-4A17-8B5C-97DF552C53DC} = {2F305555-C296-497E-AC20-5FA1B237996A}
{04B193D7-3E21-46B8-A958-89B63A8A69DE} = {2F305555-C296-497E-AC20-5FA1B237996A}
{F44934A8-36F3-49B0-9465-3831BE041CDE} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{5BDBD6C9-A31F-4CEB-871A-5E9E709197EF} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{FD464B4C-2F68-4D06-91E7-4208146C41F5} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{8FE5A5EE-1B59-401C-9FB3-B04ECD3E29C1} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{020A7474-3601-4160-A159-D7B70B77B15F} = {C3081D9A-1586-441A-B5F4-ED815B3719C1}
{27718999-C175-450A-861C-89F911E16A88} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
{1DBBB112-4BB1-444B-8EBB-E66555C76BA6} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
{C5D46169-5334-48C3-8C28-644C72832E54} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{5A1DB2F0-0715-4B3B-98E6-79BC41540045} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{93B72A06-C8BD-484F-A6F7-C9F280B150BF} = {6C7F47CC-2151-44A3-A546-41C70025132C}
{18B3DB45-4FFE-4D01-97D6-5223FEEE1853} = {6C7F47CC-2151-44A3-A546-41C70025132C}

View File

@ -1,141 +0,0 @@
# Time Zone Plugin
The Time Zone plugin allows users to search a time zone.
## Special functions (differ from the regular functions)
* Search for a country, like Kamchatka, Prince Edward Island, France
* Search for a shortcuts, like WEST, UTC, PST
* Search for a offset, like -12:00, -7, 5, 9:30
* Search for a military time zone name (must activate in plugin settings)
## How to add a new time zone or change one
All time zones are located in `TimeZone.json` in root folder of the project.
The `TimeZone.json` use a JSON schema file that make it easier to edit it.
| Key | Optional | Value type |
| ------------------- | -------- | ----------------- |
| `Offset` | **No** | String |
| `Name` | Yes | String |
| `MilitaryName` | Yes | String |
| `Shortcut` | Yes | String |
| `TimeNamesStandard` | Yes | List with strings |
| `TimeNamesDaylight` | Yes | List with strings |
| `ShortcutsStandard` | Yes | List with strings |
| `ShortcutsDaylight` | Yes | List with strings |
| `CountriesStandard` | Yes | List with strings |
| `CountriesDaylight` | Yes | List with strings |
A minimum entry for the `TimeZone.json` looks like:
```json
{
"Offset": "11:55",
"Name": "My unique time zone",
}
```
A full entry for the `TimeZone.json` looks like:
```json
{
"Offset": "11:55",
"Name": "My unique time zone",
"Shortcut" : "MYTZ",
"MilitaryName" : "Order Time Zone",
"TimeNamesStandard": [
"My unique standard time"
],
"ShortcutsStandard": [
"MCST"
],
"TimeNamesDaylight": [
"My unique daylight time"
],
"ShortcutsDaylight": [
"MCDT"
],
"CountriesStandard": [
"unique Land East"
],
"CountriesDaylight": [
"Unique Land West"
]
}
```
### Remarks
* At minimum one of the optional value should be filled.
## Scores
* Scores are not used
## Important for developers
### General
* The assembly name is cached into `_assemblyName` (to avoid to many calls of `Assembly.GetExecutingAssembly()`)
## Microsoft.PowerToys.Run.Plugin.TimeZone project
### Important plugin values (meta-data)
| Name | Value |
| --------------- | ---------------------------------------------------- |
| ActionKeyword | `&` |
| ExecuteFileName | `Microsoft.PowerToys.Run.Plugin.TimeZone.dll` |
| ID | `BADD1B06EF0A4B61AD95395F24241D69` |
### Interfaces used by this plugin
The plugin use only these interfaces (all inside the `Main.cs`):
* `Wox.Plugin.IPlugin`
* `Wox.Plugin.IContextMenu`
* `Wox.Plugin.IPluginI18n`
* `Wox.Plugin.ISettingProvider`
* `IDisposable`
### Program files
| File | Content |
| -------------------------------------- | ----------------------------------------------------------------------- |
| `Classes\TimeZoneProperties.cs` | A class that represent one time zone |
| `Classes\TimeZones.cs` | A wrapper class that only contains a list with time zones (see 1) |
| `Classes\TimeZoneSettings.cs` | A class that contains all settings for the Time Zone plugin |
| `Extensions\StringBuilderExtension.cs` | Extension methods for `StringBuilder` Objects |
| `Helper\ContextMenuHelper.cs` | All functions to build the context menu (for each result entry) |
| `Helper\JsonHelper.cs` | All functions to load the time zones from a JSON file |
| `Helper\ResultHelper.cs` | All functions to convert internal results into WOX results |
| `Helper\TranslationHelper.cs` | All functions to translate the result in the surface language |
| `Images\timeZone.dark.png` | Symbol for the results for the dark theme |
| `Images\timeZone.light.png` | Symbol for the results for the light theme |
| `Properties\Resources.Designer.resx` | File that contain all translatable keys |
| `Properties\Resources.resx` | File that contain all translatable strings in the neutral language |
| `Main.cs` | Main class, the only place that implement the WOX interfaces |
| `plugin.json` | All meta-data for this plugin |
| `timezones.json` | File that contains all time zone information |
| `timeZones.schema.json` | JSON schema for `timezones.json` |
1. We need this extra wrapper class to make it possible that the JSON file can have and use a JSON schema file.
Because the JSON file must have a object as root type, instead of a array.
### Important project values (*.csproj)
| Name | Value |
| --------------- | ------------------------------------------------------------- |
| TargetFramework | `net6.0-windows` |
| Platforms | `x64` |
| Output | `..\..\..\..\..\x64\Debug\modules\launcher\Plugins\TimeZone\` |
| RootNamespace | `Microsoft.PowerToys.Run.Plugin.TimeZone` |
| AssemblyName | `Microsoft.PowerToys.Run.Plugin.TimeZone` |
### Project dependencies
#### Projects
* `Wox.Infrastructure`
* `Wox.Plugin`

View File

@ -576,10 +576,6 @@
<Directory Id="TimeDateImagesFolder" Name="Images" />
<Directory Id="TimeDateLanguagesFolder" Name="Languages" />
</Directory>
<Directory Id="TimeZonePluginFolder" Name="TimeZone">
<Directory Id="TimeZoneImagesFolder" Name="Images" />
<Directory Id="TimeZoneLanguagesFolder" Name="Languages" />
</Directory>
<Directory Id="WindowsSettingsPluginFolder" Name="WindowsSettings">
<Directory Id="WindowsSettingsImagesFolder" Name="Images" />
<Directory Id="WindowsSettingsLanguagesFolder" Name="Languages" />

View File

@ -11,7 +11,7 @@
<Fragment>
<!-- Resource directories should be added only if the installer is built on the build farm -->
<?ifdef env.IsPipeline?>
<?foreach ParentDirectory in LauncherInstallFolder;FancyZonesInstallFolder;ImageResizerInstallFolder;ColorPickerInstallFolder;FileExplorerPreviewInstallFolder;HistoryPluginFolder;CalculatorPluginFolder;FolderPluginFolder;ProgramPluginFolder;ShellPluginFolder;IndexerPluginFolder;UnitConverterPluginFolder;UriPluginFolder;WindowWalkerPluginFolder;OneNotePluginFolder;RegistryPluginFolder;VSCodeWorkspacesPluginFolder;ServicePluginFolder;SystemPluginFolder;TimeDatePluginFolder;TimeZonePluginFolder;WindowsSettingsPluginFolder;WindowsTerminalPluginFolder;WebSearchPluginFolder?>
<?foreach ParentDirectory in LauncherInstallFolder;FancyZonesInstallFolder;ImageResizerInstallFolder;ColorPickerInstallFolder;FileExplorerPreviewInstallFolder;HistoryPluginFolder;CalculatorPluginFolder;FolderPluginFolder;ProgramPluginFolder;ShellPluginFolder;IndexerPluginFolder;UnitConverterPluginFolder;UriPluginFolder;WindowWalkerPluginFolder;OneNotePluginFolder;RegistryPluginFolder;VSCodeWorkspacesPluginFolder;ServicePluginFolder;SystemPluginFolder;TimeDatePluginFolder;WindowsSettingsPluginFolder;WindowsTerminalPluginFolder;WebSearchPluginFolder?>
<DirectoryRef Id="$(var.ParentDirectory)">
<!-- Resource file directories -->
<?foreach Language in $(var.LocLanguageList)?>
@ -261,12 +261,6 @@
Directory="Resource$(var.IdSafeLanguage)WindowsSettingsPluginFolder">
<File Id="Launcher_WindowsSettings_$(var.IdSafeLanguage)_File" Source="$(var.BinDir)modules\launcher\Plugins\WindowsSettings\$(var.Language)\Microsoft.PowerToys.Run.Plugin.WindowsSettings.resources.dll" />
</Component>
<Component
Id="Launcher_TimeZone_$(var.IdSafeLanguage)_Component"
Guid="$(var.CompGUIDPrefix)14"
Directory="Resource$(var.IdSafeLanguage)TimeZonePluginFolder">
<File Id="Launcher_TimeZone_$(var.IdSafeLanguage)_File" Source="$(var.BinDir)modules\launcher\Plugins\TimeZone\$(var.Language)\Microsoft.PowerToys.Run.Plugin.TimeZone.resources.dll" />
</Component>
<Component
Id="Launcher_WindowsTerminal_$(var.IdSafeLanguage)_Component"
Guid="$(var.CompGUIDPrefix)15"

View File

@ -28,7 +28,6 @@
<?define SystemImagesComponentFiles=lock.dark.png;lock.light.png;logoff.dark.png;logoff.light.png;recyclebin.dark.png;recyclebin.light.png;restart.dark.png;restart.light.png;shutdown.dark.png;shutdown.light.png;sleep.dark.png;sleep.light.png;firmwareSettings.dark.png;firmwareSettings.light.png;networkAdapter.dark.png;networkAdapter.light.png?>
<?define TimeDateComponentFiles=Microsoft.PowerToys.Run.Plugin.TimeDate.deps.json;Microsoft.PowerToys.Run.Plugin.TimeDate.dll;plugin.json;PowerToys.ManagedTelemetry.dll?>
<?define TimeDateImagesComponentFiles=calendar.dark.png;calendar.light.png;time.dark.png;time.light.png;timeDate.dark.png;timeDate.light.png;Warning.dark.png;Warning.light.png?>
<?define TimeZoneComponentFiles=plugin.json;Microsoft.PowerToys.Run.Plugin.TimeZone.deps.json;Microsoft.PowerToys.Run.Plugin.TimeZone.dll;PowerToys.ManagedTelemetry.dll?>
<?define WinSetCmpFiles=plugin.json;Microsoft.PowerToys.Run.Plugin.WindowsSettings.deps.json;Microsoft.PowerToys.Run.Plugin.WindowsSettings.dll;PowerToys.ManagedTelemetry.dll?>
<?define WinTermCmpFiles=plugin.json;Microsoft.PowerToys.Run.Plugin.WindowsTerminal.deps.json;Microsoft.PowerToys.Run.Plugin.WindowsTerminal.dll;PowerToys.ManagedTelemetry.dll?>
@ -267,19 +266,6 @@
</Component>
<?endforeach?>
<!-- TimeZone Plugin -->
<?foreach File in $(var.TimeZoneComponentFiles)?>
<Component Id="TimeZoneComponent_$(var.File)" Win64="yes" Directory="TimeZonePluginFolder">
<File Id="TimeZoneComponentFile_$(var.File)" Source="$(var.BinDir)modules\launcher\Plugins\TimeZone\$(var.File)" />
</Component>
<?endforeach?>
<Component Id="TimeZoneImagesComponentLight" Directory="TimeZoneImagesFolder" >
<File Id="TimeZoneLightIcon" Source="$(var.BinDir)modules\launcher\Plugins\TimeZone\Images\timeZone.light.png" />
</Component>
<Component Id="TimeZoneImagesComponentDark" Directory="TimeZoneImagesFolder" >
<File Id="TimeZoneDarkIcon" Source="$(var.BinDir)modules\launcher\Plugins\TimeZone\Images\timeZone.dark.png" />
</Component>
<!-- WindowsSettings Plugin -->
<?foreach File in $(var.WinSetCmpFiles)?>
<Component Id="WinSetCmp_$(var.File)" Win64="yes" Directory="WindowsSettingsPluginFolder">

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerToys.Run.Plugin.TimeZone\Microsoft.PowerToys.Run.Plugin.TimeZone.csproj" />
</ItemGroup>
</Project>

View File

@ -1,53 +0,0 @@
// 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.Linq;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Classes;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests
{
[TestClass]
public class ResultHelperTest
{
private TimeZoneList _timeZoneList;
private TimeZoneSettings _timeZoneSettings;
private string _actionKeyword;
[TestInitialize]
public void SetUp()
{
_actionKeyword = "&";
_timeZoneList = JsonHelper.ReadAllPossibleTimeZones();
_timeZoneSettings = new TimeZoneSettings
{
ShowTimeNames = true,
ShowTimeZoneNames = true,
};
}
[DataTestMethod]
[DataRow("&MEST", 1)]
[DataRow("&GMT", 1)]
[DataRow("&Germany", 1)] // https://github.com/microsoft/PowerToys/issues/17349
[DataRow("&AWST", 1)] // https://github.com/microsoft/PowerToys/issues/16695
[DataRow("&AEDT", 1)] // https://github.com/microsoft/PowerToys/issues/16695
[DataRow("&AEST", 1)] // https://github.com/microsoft/PowerToys/issues/16695
public void GetResultsTest(string search, int expectedResultCount)
{
var query = new Query(search, _actionKeyword);
var results = ResultHelper.GetResults(_timeZoneList.TimeZones, _timeZoneSettings, query, string.Empty);
Assert.AreEqual(expectedResultCount, results.Count());
foreach (var result in results)
{
Assert.AreEqual(!result.Title.Contains("UTC"), _timeZoneSettings.ShowTimeZoneNames);
Assert.IsFalse(string.IsNullOrWhiteSpace(result.SubTitle));
}
}
}
}

View File

@ -1,32 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text.Json;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Classes
{
/// <summary>
/// A class that contains all time zones.
/// </summary>
public sealed class TimeZoneList
{
/// <summary>
/// Initializes a new instance of the <see cref="TimeZoneList"/> class with empty properties.
/// </summary>
/// <remarks>
/// The standard constructor is need by the <see cref="JsonSerializer.Deserialize{TValue}(string, JsonSerializerOptions?)"/>-Method.
/// </remarks>
public TimeZoneList()
{
TimeZones = Enumerable.Empty<TimeZoneProperties>();
}
/// <summary>
/// Gets or sets a list with all time zones.
/// </summary>
public IEnumerable<TimeZoneProperties> TimeZones { get; set; }
}
}

View File

@ -1,96 +0,0 @@
// 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.Linq;
using System.Text.Json;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Classes
{
/// <summary>
/// A time zone
/// </summary>
public sealed class TimeZoneProperties
{
/// <summary>
/// Initializes a new instance of the <see cref="TimeZoneProperties"/> class with empty properties.
/// </summary>
/// <remarks>
/// The standard constructor is need by the <see cref="JsonSerializer.Deserialize{TValue}(string, JsonSerializerOptions?)"/>-Method.
/// </remarks>
public TimeZoneProperties()
{
Offset = "00:00";
Name = string.Empty;
MilitaryName = string.Empty;
Shortcut = string.Empty;
TimeNamesStandard = Enumerable.Empty<string>();
TimeNamesDaylight = Enumerable.Empty<string>();
CountriesStandard = Enumerable.Empty<string>();
CountriesDaylight = Enumerable.Empty<string>();
ShortcutsStandard = Enumerable.Empty<string>();
ShortcutsDaylight = Enumerable.Empty<string>();
}
/// <summary>
/// Gets or sets the time offset of this time zone (the gap from the UTC time zone)
/// </summary>
public string Offset { get; set; }
/// <summary>
/// Gets or sets the name of this time zone.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the military name of this time zone.
/// </summary>
public string MilitaryName { get; set; }
/// <summary>
/// Gets or sets the shortcuts of the name this time zone.
/// </summary>
public string Shortcut { get; set; }
/// <summary>
/// Gets or sets a list with names for the standard time.
/// </summary>
public IEnumerable<string> TimeNamesStandard { get; set; }
/// <summary>
/// Gets or sets a list with names for the daylight saving time.
/// </summary>
public IEnumerable<string> TimeNamesDaylight { get; set; }
/// <summary>
/// Gets or sets a list with all countries in this time zone that don't use a daylight saving time.
/// </summary>
public IEnumerable<string> CountriesStandard { get; set; }
/// <summary>
/// Gets or sets a list with all countries in this time zone that use a daylight saving time.
/// </summary>
public IEnumerable<string> CountriesDaylight { get; set; }
/// <summary>
/// Gets or sets a list with shortcuts for the names for the standard time.
/// </summary>
public IEnumerable<string> ShortcutsStandard { get; set; }
/// <summary>
/// Gets or sets a list with shortcuts for the names for the daylight saving time.
/// </summary>
public IEnumerable<string> ShortcutsDaylight { get; set; }
/// <summary>
/// Gets a compatible <see cref="TimeSpan"/> of the <see cref="Offset"/>.
/// </summary>
internal TimeSpan OffsetAsTimeSpan
{
get { return TimeSpan.TryParse(Offset, out var result) ? result : new TimeSpan(0, 0, 0); }
}
}
}

View File

@ -1,97 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Properties;
using Microsoft.PowerToys.Settings.UI.Library;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Classes
{
/// <summary>
/// Additional settings for the time zone plugin.
/// </summary>
internal sealed class TimeZoneSettings
{
/// <summary>
/// Gets or sets a value indicating whether the time zone name of a time zone is shown in the results.
/// </summary>
internal bool ShowTimeZoneNames { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the time name of a time zone is shown in the results.
/// </summary>
internal bool ShowTimeNames { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the military name of a time zone is shown in the results.
/// </summary>
internal bool ShowMilitaryTimeZoneNames { get; set; }
/// <summary>
/// Return a list with all settings. Additional
/// </summary>
/// <returns>A list with all settings.</returns>
internal static List<PluginAdditionalOption> GetAdditionalOptions()
{
var optionList = new List<PluginAdditionalOption>
{
new PluginAdditionalOption
{
Key = "ShowTimeZoneNames",
DisplayLabel = Resources.ShowTimeZoneNames,
Value = true,
},
new PluginAdditionalOption
{
Key = "ShowTimeNames",
DisplayLabel = Resources.ShowTimeNames,
Value = true,
},
new PluginAdditionalOption
{
Key = "ShowMilitaryTimeZoneNames",
DisplayLabel = Resources.ShowMilitaryTimeZoneNames,
Value = false,
},
};
return optionList;
}
/// <summary>
/// Update this settings.
/// </summary>
/// <param name="settings">The settings for all power launcher plugin.</param>
internal void UpdateSettings(PowerLauncherPluginSettings settings)
{
if (settings is null || settings.AdditionalOptions is null)
{
return;
}
ShowTimeZoneNames = GetSettingOrDefault(settings, "ShowTimeZoneNames");
ShowTimeNames = GetSettingOrDefault(settings, "ShowTimeNames");
ShowMilitaryTimeZoneNames = GetSettingOrDefault(settings, "ShowMilitaryTimeZoneNames");
}
/// <summary>
/// Return one <see cref="bool"/> setting of the given settings list with the given name.
/// </summary>
/// <param name="settings">The object that contain all settings.</param>
/// <param name="name">The name of the setting.</param>
/// <returns>A settings value.</returns>
private static bool GetSettingOrDefault(PowerLauncherPluginSettings settings, string name)
{
var option = settings.AdditionalOptions.FirstOrDefault(x => x.Key == name);
// As a fall-back if a setting isn't available, we use the value defined in the method GetAdditionalOptions()
var settingsValue = option?.Value
?? GetAdditionalOptions().FirstOrDefault(x => x.Key == name)?.Value
?? default;
return settingsValue;
}
}
}

View File

@ -1,50 +0,0 @@
// 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.Text;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Extensions
{
/// <summary>
/// Extensions for <see cref="StringBuilder"/>-Objects
/// </summary>
internal static class StringBuilderExtensions
{
/// <summary>
/// Save append the given <see cref="string"/> value with the given maximum length to the <see cref="StringBuilder"/>
/// </summary>
/// <param name="stringBuilder">The <see cref="StringBuilder"/> to append the string.</param>
/// <param name="value">The value that should be append.</param>
/// <param name="maxLength">The max length of the <see cref="string"/> value that should append.</param>
internal static void SaveAppend(this StringBuilder stringBuilder, string value, int maxLength)
{
if (value.Length > maxLength)
{
stringBuilder.Append(value, 0, maxLength);
}
else
{
stringBuilder.Append(value);
}
}
/// <summary>
/// Cut too long texts to the given length and add three dots at the end of the text.
/// </summary>
/// <param name="stringBuilder">The <see cref="StringBuilder"/> that contain the text.</param>
/// <param name="maxLength">The maximum length for the text, inclusive the three dots.</param>
internal static void CutTooLong(this StringBuilder stringBuilder, int maxLength)
{
if (stringBuilder.Length <= maxLength)
{
return;
}
stringBuilder.Length = maxLength - 3;
stringBuilder.Append('.');
stringBuilder.Append('.');
stringBuilder.Append('.');
}
}
}

View File

@ -1,71 +0,0 @@
// 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.Windows;
using System.Windows.Input;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Properties;
using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Helper
{
/// <summary>
/// Helper class to easier work with context menu entries
/// </summary>
internal static class ContextMenuHelper
{
/// <summary>
/// Return a list with all context menu entries for the given <see cref="Result"/>
/// <para>Symbols taken from <see href="https://learn.microsoft.com/windows/uwp/design/style/segoe-ui-symbol-font"/></para>
/// </summary>
/// <param name="result">The result for the context menu entires</param>
/// <param name="assemblyName">The name of the this assembly</param>
/// <returns>A list with context menu entries</returns>
internal static List<ContextMenuResult> GetContextMenu(in Result result, in string assemblyName)
{
if (!(result?.ContextData is DateTime dateTime))
{
return new List<ContextMenuResult>(0);
}
var list = new List<ContextMenuResult>
{
new ContextMenuResult
{
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control,
Action = _ => TryToCopyToClipBoard($"{dateTime:HH:mm:ss}"),
FontFamily = "Segoe MDL2 Assets",
Glyph = "\xE8C8", // E8C8 => Symbol: Copy
PluginName = assemblyName,
Title = $"{Resources.CopyTime} (Ctrl+C)",
},
};
return list;
}
/// <summary>
/// Copy the given text to the clipboard
/// </summary>
/// <param name="text">The text to copy to the clipboard</param>
/// <returns><see langword="true"/>The text successful copy to the clipboard, otherwise <see langword="false"/></returns>
private static bool TryToCopyToClipBoard(in string text)
{
try
{
Clipboard.Clear();
Clipboard.SetText(text);
return true;
}
catch (Exception exception)
{
Log.Exception("Can't copy to clipboard", exception, typeof(Main));
return false;
}
}
}
}

View File

@ -1,63 +0,0 @@
// 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.IO;
using System.Reflection;
using System.Text.Json;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Classes;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Helper
{
/// <summary>
/// Helper class to easier work with the JSON files.
/// </summary>
internal static class JsonHelper
{
/// <summary>
/// The name of the file that contains all time zones.
/// </summary>
private const string _settingsFile = "timeZones.json";
/// <summary>
/// Read all possible time zones.
/// </summary>
/// <returns>A object that contain a list with time zones.</returns>
internal static TimeZoneList ReadAllPossibleTimeZones()
{
var assembly = Assembly.GetExecutingAssembly();
var type = Array.Find(assembly.GetTypes(), x => x.Name == nameof(Main));
TimeZoneList? settings = null;
try
{
var resourceName = $"{type?.Namespace}.{_settingsFile}";
using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream is null)
{
Log.Error("Stream is null", typeof(JsonHelper));
return new TimeZoneList();
}
using var reader = new StreamReader(stream);
var text = reader.ReadToEnd();
settings = JsonSerializer.Deserialize<TimeZoneList>(text);
}
catch (JsonException exception)
{
Log.Exception("Error loading settings JSON file", exception, typeof(JsonHelper));
}
catch (Exception exception)
{
Log.Exception("Error loading settings JSON file", exception, typeof(JsonHelper));
throw;
}
return settings ?? new TimeZoneList();
}
}
}

View File

@ -1,925 +0,0 @@
// 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.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Classes;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Extensions;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Properties;
using Wox.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Helper
{
/// <summary>
/// Helper class to easier work with results
/// </summary>
internal static class ResultHelper
{
/// <summary>
/// Return a list of <see cref="Result"/>s based on the given <see cref="Query"/>.
/// </summary>
/// <param name="timeZones">A list with all possible time zones.</param>
/// <param name="options">Additional options to limit the results.</param>
/// <param name="query">The <see cref="Query"/> to filter the <see cref="Results"/>.</param>
/// <param name="iconPath">The path to the icon that is used for each result.</param>
/// <returns>A list with <see cref="Result"/>s.</returns>
internal static IEnumerable<Result> GetResults(in IEnumerable<TimeZoneProperties> timeZones, in TimeZoneSettings options, in Query query, in string iconPath)
{
var results = new List<Result>();
var dateTime = DateTime.UtcNow;
foreach (var timeZone in timeZones)
{
if (MatchTimeZoneShortcut(timeZone, query)
|| MatchStandardTimeShortcuts(timeZone, query)
|| MatchDaylightTimeShortcuts(timeZone, query)
|| MatchTimeZoneNames(timeZone, query)
|| MatchStandardTimeNames(timeZone, query)
|| MatchDaylightTimeNames(timeZone, query)
|| MatchStandardCountries(timeZone, query)
|| MatchDaylightCountries(timeZone, query)
|| MatchOffset(timeZone, query))
{
results.AddRange(GetResults(timeZone, options, query, iconPath, dateTime));
}
}
var orderResults = results.OrderBy(result => result.Title);
return orderResults;
}
/// <summary>
/// Return a list with <see cref="Result"/> based on the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain the information for the <see cref="Result"/>.</param>
/// <param name="options">Additional options to limit the results.</param>
/// <param name="query">The <see cref="Query"/> that should match.</param>
/// <param name="iconPath">The path to the icon that is used for each result.</param>
/// <param name="dateTime">The current time in UTC for the <see cref="Result"/>.</param>
/// <returns>A list with <see cref="Result"/>.</returns>
internal static IEnumerable<Result> GetResults(in TimeZoneProperties timeZoneProperties, in TimeZoneSettings options, in Query query, in string iconPath, in DateTime dateTime)
{
var results = new Collection<Result>();
var standardTitleResult = GetTitle(timeZoneProperties, options, query, dateTime, false);
var daylightTitleResult = GetTitle(timeZoneProperties, options, query, dateTime, true);
if (standardTitleResult.Equals(daylightTitleResult))
{
results.Add(new Result
{
ContextData = GetTimeInTimeZone(timeZoneProperties, dateTime, false),
IcoPath = iconPath,
Title = standardTitleResult.ToString(),
SubTitle = GetAllCountries(timeZoneProperties, query, maxLength: 100).ToString(),
ToolTipData = new ToolTipData(standardTitleResult.ToString(), GetAllToolTip(timeZoneProperties, options).ToString()),
});
return results;
}
if (MatchStandardTimeShortcuts(timeZoneProperties, query)
|| MatchStandardTimeNames(timeZoneProperties, query)
|| MatchStandardCountries(timeZoneProperties, query))
{
var hasCountries = GetStandardCountries(timeZoneProperties, null, int.MaxValue).Length > 0;
if (!hasCountries)
{
return results;
}
results.Add(new Result
{
ContextData = GetTimeInTimeZone(timeZoneProperties, dateTime, false),
IcoPath = iconPath,
SubTitle = GetStandardCountries(timeZoneProperties, query, maxLength: 100).ToString(),
Title = standardTitleResult.ToString(),
ToolTipData = new ToolTipData(standardTitleResult.ToString(), GetStandardToolTip(timeZoneProperties, options).ToString()),
});
}
if (MatchDaylightTimeShortcuts(timeZoneProperties, query)
|| MatchDaylightTimeNames(timeZoneProperties, query)
|| MatchDaylightCountries(timeZoneProperties, query))
{
var hasCountries = GetDaylightCountries(timeZoneProperties, null, int.MaxValue).Length > 0;
if (!hasCountries)
{
return results;
}
results.Add(new Result
{
ContextData = GetTimeInTimeZone(timeZoneProperties, dateTime, true),
IcoPath = iconPath,
SubTitle = GetDaylightCountries(timeZoneProperties, query, maxLength: 100).ToString(),
Title = daylightTitleResult.ToString(),
ToolTipData = new ToolTipData(daylightTitleResult.ToString(), GetDaylightToolTip(timeZoneProperties, options).ToString()),
});
}
return results;
}
/// <summary>
/// Return the current local time of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain all information.</param>
/// <param name="dateTime">The current time in UTC.</param>
/// <param name="daylightSavingTime">indicate that the result is for a time zone that use a daylight saving time.</param>
/// <returns>The current local time in a time zone.</returns>
internal static DateTime GetTimeInTimeZone(in TimeZoneProperties timeZoneProperties, in DateTime dateTime, in bool daylightSavingTime)
{
foreach (var timeZoneInfo in TimeZoneInfo.GetSystemTimeZones())
{
if (timeZoneInfo.BaseUtcOffset == timeZoneProperties.OffsetAsTimeSpan
&& timeZoneInfo.SupportsDaylightSavingTime == daylightSavingTime)
{
return TimeZoneInfo.ConvertTime(dateTime, timeZoneInfo);
}
}
// Fall-back
var result = dateTime + timeZoneProperties.OffsetAsTimeSpan;
return result;
}
/// <summary>
/// Return the title for the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain all information.</param>
/// <param name="timeZoneSettings">Additional options to limit the results.</param>
/// <param name="query">The <see cref="Query"/> that should match.</param>
/// <param name="dateTime">The current time in UTC.</param>
/// <param name="daylightSavingTime">indicate that the result is for a time zone that use a daylight saving time.</param>
/// <returns>A title for a time zone.</returns>
internal static StringBuilder GetTitle(in TimeZoneProperties timeZoneProperties, in TimeZoneSettings timeZoneSettings, in Query query, in DateTime dateTime, in bool daylightSavingTime)
{
var stringBuilder = new StringBuilder();
var timeInZoneTime = GetTimeInTimeZone(timeZoneProperties, dateTime, daylightSavingTime);
var timeZoneNames = GetNames(timeZoneProperties, timeZoneSettings, query, maxLength: 50);
stringBuilder.AppendFormat(CultureInfo.CurrentCulture, "{0:HH:mm:ss}", timeInZoneTime);
stringBuilder.Append(' ');
stringBuilder.Append('-');
stringBuilder.Append(' ');
stringBuilder.Append(timeZoneNames);
return stringBuilder;
}
/// <summary>
/// Return a tool-tip for the given time zone with countries that use the standard time.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain all information.</param>
/// <param name="timeZoneSettings">Additional options to limit the results.</param>
/// <returns>A tool-tip with countries that use the standard time.</returns>
internal static StringBuilder GetStandardToolTip(in TimeZoneProperties timeZoneProperties, in TimeZoneSettings timeZoneSettings)
{
var countries = GetStandardCountries(timeZoneProperties, null, maxLength: int.MaxValue);
var names = GetNames(timeZoneProperties, timeZoneSettings, null, maxLength: int.MaxValue);
var shortcuts = GetStandardShortcuts(timeZoneProperties);
if (!string.IsNullOrWhiteSpace(timeZoneProperties.Shortcut))
{
shortcuts.Append(',');
shortcuts.Append(' ');
shortcuts.Append(timeZoneProperties.Shortcut);
}
var stringBuilder = new StringBuilder();
stringBuilder.Append(Resources.Offset).Append(':').Append(' ').AppendLine(timeZoneProperties.Offset);
stringBuilder.Append(Resources.UseDst).Append(':').Append(' ').AppendLine(Resources.No);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Names).Append(':').Append(' ').Append(names);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Shortcuts).Append(':').Append(' ').Append(shortcuts);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Countries).Append(':').Append(' ').Append(countries);
return stringBuilder;
}
/// <summary>
/// Return a tool-tip for the given time zone with countries that use the daylight saving time.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain all information.</param>
/// <param name="timeZoneSettings">Additional options to limit the type of the names.</param>
/// <returns>A tool-tip with countries that use the daylight saving time.</returns>
internal static StringBuilder GetDaylightToolTip(in TimeZoneProperties timeZoneProperties, in TimeZoneSettings timeZoneSettings)
{
var dstCountries = GetDaylightCountries(timeZoneProperties, null, maxLength: int.MaxValue);
var names = GetNames(timeZoneProperties, timeZoneSettings, null, maxLength: int.MaxValue);
var shortcuts = GetDaylightShortcuts(timeZoneProperties);
if (!string.IsNullOrWhiteSpace(timeZoneProperties.Shortcut))
{
shortcuts.Append(',');
shortcuts.Append(' ');
shortcuts.Append(timeZoneProperties.Shortcut);
}
var stringBuilder = new StringBuilder();
stringBuilder.Append(Resources.Offset).Append(':').Append(' ').AppendLine(timeZoneProperties.Offset);
stringBuilder.Append(Resources.UseDst).Append(':').Append(' ').AppendLine(Resources.Yes);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Names).Append(':').Append(' ').Append(names);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Shortcuts).Append(':').Append(' ').Append(shortcuts);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.CountriesWithDst).Append(':').Append(' ').Append(dstCountries);
return stringBuilder;
}
/// <summary>
/// Return a tool-tip for the given time zone with countries.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain all information.</param>
/// <param name="timeZoneSettings">Additional options to limit the type of the names.</param>
/// <returns>A tool-tip with countries.</returns>
internal static StringBuilder GetAllToolTip(in TimeZoneProperties timeZoneProperties, in TimeZoneSettings timeZoneSettings)
{
var countries = GetStandardCountries(timeZoneProperties, null, maxLength: int.MaxValue);
var dstCountries = GetDaylightCountries(timeZoneProperties, null, maxLength: int.MaxValue);
var names = GetNames(timeZoneProperties, timeZoneSettings, null, maxLength: int.MaxValue);
var shortcuts = GetStandardShortcuts(timeZoneProperties);
var dstShortcuts = GetDaylightShortcuts(timeZoneProperties);
if (dstShortcuts.Length > 0)
{
shortcuts.Append(',');
shortcuts.Append(' ');
shortcuts.Append(dstShortcuts);
}
if (!string.IsNullOrWhiteSpace(timeZoneProperties.Shortcut))
{
shortcuts.Append(',');
shortcuts.Append(' ');
shortcuts.Append(timeZoneProperties.Shortcut);
}
var stringBuilder = new StringBuilder();
stringBuilder.Append(Resources.Offset).Append(':').Append(' ').AppendLine(timeZoneProperties.Offset);
stringBuilder.Append(Resources.UseDst).Append(':').Append(' ').AppendLine(Resources.Yes);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Names).Append(':').Append(' ').Append(names);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Shortcuts).Append(':').Append(' ').Append(shortcuts);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.Countries).Append(':').Append(' ').Append(countries);
stringBuilder.AppendLine(string.Empty);
stringBuilder.AppendLine(string.Empty);
stringBuilder.Append(Resources.CountriesWithDst).Append(':').Append(' ').Append(dstCountries);
return stringBuilder;
}
/// <summary>
/// Return all names of the given time zone that match the given query.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain a hand of names.</param>
/// <param name="timeZoneSettings">Additional options to limit the type of the names.</param>
/// <param name="query">The query that should match.</param>
/// <param name="maxLength">The maximum length of the result.</param>
/// <returns>All know names of the given time zone.</returns>
internal static StringBuilder GetNames(in TimeZoneProperties timeZoneProperties, in TimeZoneSettings timeZoneSettings, Query? query, in int maxLength)
{
var allNames = new List<string>();
if (!string.IsNullOrWhiteSpace(timeZoneProperties.Name) && timeZoneSettings.ShowTimeZoneNames)
{
allNames.Add(timeZoneProperties.Name);
}
if (!string.IsNullOrWhiteSpace(timeZoneProperties.MilitaryName) && timeZoneSettings.ShowMilitaryTimeZoneNames)
{
allNames.Add(timeZoneProperties.MilitaryName);
}
if (timeZoneProperties.TimeNamesStandard != null && timeZoneSettings.ShowTimeZoneNames)
{
allNames.AddRange(timeZoneProperties.TimeNamesStandard);
}
if (timeZoneProperties.TimeNamesDaylight != null && timeZoneSettings.ShowTimeZoneNames)
{
allNames.AddRange(timeZoneProperties.TimeNamesDaylight);
}
IEnumerable<string> names;
if (query is null || string.IsNullOrWhiteSpace(query.Search))
{
names = allNames;
}
else if (MatchStandardCountries(timeZoneProperties, query) || MatchDaylightCountries(timeZoneProperties, query))
{
names = allNames;
}
else if (MatchStandardTimeShortcuts(timeZoneProperties, query) || MatchDaylightTimeShortcuts(timeZoneProperties, query))
{
var matches = new Collection<string>();
foreach (var name in allNames)
{
var matchAll = query.Search.All(x => name.Contains(x, StringComparison.CurrentCultureIgnoreCase));
if (matchAll)
{
matches.Add(name);
}
}
names = matches;
}
else
{
names = allNames.Where(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
}
var stringBuilder = new StringBuilder();
if (names.Any())
{
var lastEntry = names.LastOrDefault();
foreach (var name in names)
{
stringBuilder.Append(name);
if (name != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
// To many names (first pass) => use shortcuts
if (stringBuilder.Length > maxLength)
{
stringBuilder.Replace(Resources.TimeZone, Resources.TimeZoneShortcut);
stringBuilder.Replace(Resources.StandardTime, Resources.StandardTimeShortcut);
stringBuilder.Replace(Resources.DaylightTime, Resources.DaylightTimeShortcut);
stringBuilder.Replace(Resources.Time, Resources.TimeShortcut);
}
// To many names (second pass) => cut name length
if (stringBuilder.Length > maxLength)
{
foreach (var country in names)
{
stringBuilder.SaveAppend(country, maxLength: 5);
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
stringBuilder.CutTooLong(maxLength);
}
else
{
// only when we don't have found any names so we
stringBuilder.Append("UTC");
var totalMinutes = timeZoneProperties.OffsetAsTimeSpan.TotalMinutes;
if (totalMinutes < 0)
{
stringBuilder.Append(timeZoneProperties.Offset);
}
else if (totalMinutes > 0)
{
stringBuilder.Append('+');
stringBuilder.Append(timeZoneProperties.Offset);
}
else
{
stringBuilder.Append("±00:00");
}
}
return stringBuilder;
}
/// <summary>
/// Return all standard time name shortcuts of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain a hand of names.</param>
/// <returns>All standard time name shortcuts of the given time zone.</returns>
internal static StringBuilder GetStandardShortcuts(in TimeZoneProperties timeZoneProperties)
{
var stringBuilder = new StringBuilder();
var lastEntry = timeZoneProperties.ShortcutsStandard.LastOrDefault();
foreach (var name in timeZoneProperties.ShortcutsStandard)
{
stringBuilder.Append(name);
if (name != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
return stringBuilder;
}
/// <summary>
/// Return all know daylight time name shortcuts of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain a hand of names.</param>
/// <returns>All know daylight time name shortcuts of the given time zone.</returns>
internal static StringBuilder GetDaylightShortcuts(in TimeZoneProperties timeZoneProperties)
{
var stringBuilder = new StringBuilder();
var lastEntry = timeZoneProperties.ShortcutsDaylight.LastOrDefault();
foreach (var name in timeZoneProperties.ShortcutsDaylight)
{
stringBuilder.Append(name);
if (name != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
return stringBuilder;
}
/// <summary>
/// Return all countries that use the standard time of the given time zone that match the given query.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain the countries.</param>
/// <param name="query">The <see cref="Query"/> that should match a country that use standard time.</param>
/// <param name="maxLength">The maximum length of the result.</param>
/// <returns>All countries that use the standard time of the given time zone.</returns>
internal static StringBuilder GetStandardCountries(in TimeZoneProperties timeZoneProperties, Query? query, in int maxLength)
{
IEnumerable<string> countries;
if (query is null || string.IsNullOrWhiteSpace(query.Search))
{
countries = timeZoneProperties.CountriesStandard;
}
else if (MatchStandardTimeShortcuts(timeZoneProperties, query))
{
var matches = new Collection<string>();
foreach (var name in timeZoneProperties.CountriesStandard)
{
var matchAll = query.Search.All(x => name.Contains(x, StringComparison.CurrentCultureIgnoreCase));
if (matchAll)
{
matches.Add(name);
}
}
countries = matches;
}
else
{
countries = timeZoneProperties.CountriesStandard.Where(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
}
// When the search query don't match a country, show all countries
if (countries is null || !countries.Any())
{
countries = timeZoneProperties.CountriesStandard;
}
var stringBuilder = new StringBuilder();
var lastEntry = countries.LastOrDefault();
foreach (var country in countries.Distinct())
{
stringBuilder.Append(country);
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
// To many countries (first pass) => remove extra info
if (stringBuilder.Length > maxLength)
{
stringBuilder.Clear();
foreach (var country in countries)
{
var extraInfoStart = country.IndexOf('(', StringComparison.InvariantCultureIgnoreCase);
if (extraInfoStart > 0)
{
stringBuilder.Append(country[..extraInfoStart]);
}
else
{
stringBuilder.Append(country);
}
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
// To many countries (second pass) => remove extra info and cut country length
if (stringBuilder.Length > maxLength)
{
foreach (var country in countries)
{
var extraInfoStart = country.IndexOf('(', StringComparison.InvariantCultureIgnoreCase);
if (extraInfoStart > 0)
{
stringBuilder.SaveAppend(country[..extraInfoStart], maxLength: 5);
}
else
{
stringBuilder.SaveAppend(country, maxLength: 5);
}
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
stringBuilder.CutTooLong(maxLength);
return stringBuilder;
}
/// <summary>
/// Return all countries that use the daylight saving time of the given time zone that match the given query
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain the countries.</param>
/// <param name="query">The <see cref="Query"/> that should match a country that use daylight time.</param>
/// <param name="maxLength">The maximum length of the result.</param>
/// <returns>All countries that use the daylight saving time of the given time zone.</returns>
internal static StringBuilder GetDaylightCountries(in TimeZoneProperties timeZoneProperties, Query? query, in int maxLength)
{
IEnumerable<string> countries;
if (query is null || string.IsNullOrWhiteSpace(query.Search))
{
countries = timeZoneProperties.CountriesDaylight;
}
else if (MatchDaylightTimeShortcuts(timeZoneProperties, query))
{
var matches = new Collection<string>();
foreach (var name in timeZoneProperties.CountriesDaylight)
{
var matchAll = query.Search.All(x => name.Contains(x, StringComparison.CurrentCultureIgnoreCase));
if (matchAll)
{
matches.Add(name);
}
}
countries = matches;
}
else
{
countries = timeZoneProperties.CountriesDaylight.Where(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
}
// When the search query don't match a country, show all countries
if (countries is null || !countries.Any())
{
countries = timeZoneProperties.CountriesDaylight;
}
var stringBuilder = new StringBuilder();
var lastEntry = countries.LastOrDefault();
foreach (var country in countries.Distinct())
{
stringBuilder.Append(country);
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
// To many countries (first pass) => remove extra info
if (stringBuilder.Length > maxLength)
{
stringBuilder.Clear();
foreach (var country in countries)
{
var extraInfoStart = country.IndexOf('(', StringComparison.InvariantCultureIgnoreCase);
if (extraInfoStart > 0)
{
stringBuilder.Append(country[..extraInfoStart]);
}
else
{
stringBuilder.Append(country);
}
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
// To many countries (second pass) => remove extra info and cut country length
if (stringBuilder.Length > maxLength)
{
foreach (var country in countries)
{
var extraInfoStart = country.IndexOf('(', StringComparison.InvariantCultureIgnoreCase);
if (extraInfoStart > 0)
{
stringBuilder.SaveAppend(country[..extraInfoStart], maxLength: 5);
}
else
{
stringBuilder.SaveAppend(country, maxLength: 5);
}
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
stringBuilder.CutTooLong(maxLength);
return stringBuilder;
}
/// <summary>
/// Return all countries of the given time zone that match the given query.
/// </summary>
/// <param name="timeZoneProperties">The time zone that contain the countries.</param>
/// <param name="query">The <see cref="Query"/> that should match a country that use standard or daylight time.</param>
/// <param name="maxLength">The maximum length of the result.</param>
/// <returns>All countries of the given time zone.</returns>
internal static StringBuilder GetAllCountries(in TimeZoneProperties timeZoneProperties, Query? query, in int maxLength)
{
IEnumerable<string> countries;
if (query is null || string.IsNullOrWhiteSpace(query.Search))
{
countries = timeZoneProperties.CountriesDaylight
.Concat(timeZoneProperties.CountriesStandard);
}
else if (MatchDaylightTimeShortcuts(timeZoneProperties, query) || MatchStandardTimeShortcuts(timeZoneProperties, query))
{
var matches = new Collection<string>();
foreach (var name in timeZoneProperties.CountriesDaylight.Concat(timeZoneProperties.CountriesStandard))
{
var matchAll = query.Search.All(x => name.Contains(x, StringComparison.CurrentCultureIgnoreCase));
if (matchAll)
{
matches.Add(name);
}
}
countries = matches;
}
else
{
countries = timeZoneProperties.CountriesDaylight.Where(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase))
.Concat(timeZoneProperties.CountriesStandard.Where(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase)));
}
// When the search query don't match a country, show all countries
if (countries is null || !countries.Any())
{
countries = timeZoneProperties.CountriesDaylight
.Concat(timeZoneProperties.CountriesStandard);
}
var stringBuilder = new StringBuilder();
var lastEntry = countries.LastOrDefault();
foreach (var country in countries.Distinct())
{
stringBuilder.Append(country);
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
// To many countries (first pass) => remove extra info
if (stringBuilder.Length > maxLength)
{
stringBuilder.Clear();
foreach (var country in countries)
{
var extraInfoStart = country.IndexOf('(', StringComparison.InvariantCultureIgnoreCase);
if (extraInfoStart > 0)
{
stringBuilder.Append(country[..extraInfoStart]);
}
else
{
stringBuilder.Append(country);
}
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
// To many countries (second pass) => remove extra info and cut country length
if (stringBuilder.Length > maxLength)
{
foreach (var country in countries)
{
var extraInfoStart = country.IndexOf('(', StringComparison.InvariantCultureIgnoreCase);
if (extraInfoStart > 0)
{
stringBuilder.SaveAppend(country[..extraInfoStart], maxLength: 5);
}
else
{
stringBuilder.SaveAppend(country, maxLength: 5);
}
if (country != lastEntry)
{
stringBuilder.Append(',');
stringBuilder.Append(' ');
}
}
}
stringBuilder.CutTooLong(maxLength);
return stringBuilder;
}
/// <summary>
/// Indicate that the given query match the time zone shortcut of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchTimeZoneShortcut(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.Shortcut.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase);
return result;
}
/// <summary>
/// Indicate that the given query match one of the time zone names of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchTimeZoneNames(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.Name.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase)
|| timeZoneProperties.MilitaryName.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase);
return result;
}
/// <summary>
/// Indicate that the given query match the offset of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchOffset(in TimeZoneProperties timeZoneProperties, Query query)
{
// allow search for "-xx:xx"
if (timeZoneProperties.Offset.StartsWith('-') && query.Search.StartsWith('-'))
{
if (timeZoneProperties.Offset[1..].Contains(query.Search[1..], StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
}
// allow search for "+xx:xx"
if (!timeZoneProperties.Offset.StartsWith('-') && query.Search.StartsWith('+'))
{
if (timeZoneProperties.Offset.Contains(query.Search[1..], StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
}
return false;
}
/// <summary>
/// Indicate that the given query match one of the standard time names of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchStandardTimeNames(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.TimeNamesStandard.Any(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
return result;
}
/// <summary>
/// Indicate that the given query match one of the daylight time names of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchDaylightTimeNames(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.TimeNamesDaylight.Any(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
return result;
}
/// <summary>
/// Indicate that the given query match one of the countries that use the standard time of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchStandardCountries(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.CountriesStandard.Any(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
return result;
}
/// <summary>
/// Indicate that the given query match one of the countries that use the daylight time of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchDaylightCountries(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.CountriesDaylight.Any(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
return result;
}
/// <summary>
/// Indicate that the given query match the time zone shortcut of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchStandardTimeShortcuts(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.ShortcutsStandard.Any(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
return result;
}
/// <summary>
/// Indicate that the given query match the time zone shortcut of the given time zone.
/// </summary>
/// <param name="timeZoneProperties">The time zone to check.</param>
/// <param name="query">The query that should match.</param>
/// <returns><see langword="true"/>if the query match, otherwise <see langword="false"/>.</returns>
internal static bool MatchDaylightTimeShortcuts(in TimeZoneProperties timeZoneProperties, Query query)
{
var result = timeZoneProperties.ShortcutsDaylight.Any(x => x.Contains(query.Search, StringComparison.CurrentCultureIgnoreCase));
return result;
}
}
}

View File

@ -1,133 +0,0 @@
// 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.Collections.Generic;
using System.Globalization;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Classes;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Properties;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Helper
{
/// <summary>
/// Helper class to easier work with translations.
/// </summary>
internal static class TranslationHelper
{
/// <summary>
/// Translate all names and countries of the <see cref="TimeZoneList"/> class.
/// </summary>
/// <param name="timeZoneList">A class that contain all possible time zones.</param>
internal static void TranslateAllSettings(in TimeZoneList timeZoneList)
{
if (timeZoneList?.TimeZones is null)
{
return;
}
foreach (var timeZone in timeZoneList.TimeZones)
{
// Translate Name
if (!string.IsNullOrWhiteSpace(timeZone.Name))
{
var name = Resources.ResourceManager.GetString(timeZone.Name, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(name))
{
Log.Warn($"Resource string for [{timeZone.Name}] not found", typeof(TranslationHelper));
}
timeZone.Name = name ?? timeZone.Name ?? string.Empty;
}
// Translate MilitaryName
if (!string.IsNullOrWhiteSpace(timeZone.MilitaryName))
{
var militaryName = Resources.ResourceManager.GetString(timeZone.MilitaryName, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(militaryName))
{
Log.Warn($"Resource string for [{timeZone.MilitaryName}] not found", typeof(TranslationHelper));
}
timeZone.MilitaryName = militaryName ?? timeZone.MilitaryName ?? string.Empty;
}
// Translate TimeNamesDaylight
if (!(timeZone.TimeNamesDaylight is null))
{
var timeNamesDaylight = new List<string>();
foreach (var nameDaylight in timeZone.TimeNamesDaylight)
{
var nameDaylightT = Resources.ResourceManager.GetString(nameDaylight, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(nameDaylightT))
{
Log.Warn($"Resource string for [{nameDaylight}] not found", typeof(TranslationHelper));
}
timeNamesDaylight.Add(nameDaylightT ?? nameDaylight ?? string.Empty);
}
timeZone.TimeNamesDaylight = timeNamesDaylight;
}
// Translate TimeNamesStandard
if (!(timeZone.TimeNamesStandard is null))
{
var timeNamesStandard = new List<string>();
foreach (var nameStandard in timeZone.TimeNamesStandard)
{
var nameStandardT = Resources.ResourceManager.GetString(nameStandard, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(nameStandardT))
{
Log.Warn($"Resource string for [{nameStandard}] not found", typeof(TranslationHelper));
}
timeNamesStandard.Add(nameStandardT ?? nameStandard ?? string.Empty);
}
timeZone.TimeNamesStandard = timeNamesStandard;
}
// Translate CountriesDaylight
if (!(timeZone.CountriesDaylight is null))
{
var countriesDaylight = new List<string>();
foreach (var countryDaylight in timeZone.CountriesDaylight)
{
var countryDaylightT = Resources.ResourceManager.GetString(countryDaylight, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(countryDaylightT))
{
Log.Warn($"Resource string for [{countryDaylight}] not found", typeof(TranslationHelper));
}
countriesDaylight.Add(countryDaylightT ?? countryDaylight ?? string.Empty);
}
timeZone.CountriesDaylight = countriesDaylight;
}
// Translate CountriesStandard
if (!(timeZone.CountriesStandard is null))
{
var countriesStandard = new List<string>();
foreach (var countryStandard in timeZone.CountriesStandard)
{
var countryStandardT = Resources.ResourceManager.GetString(countryStandard, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(countryStandardT))
{
Log.Warn($"Resource string for [{countryStandard}] not found", typeof(TranslationHelper));
}
countriesStandard.Add(countryStandardT ?? countryStandard ?? string.Empty);
}
timeZone.CountriesStandard = countriesStandard;
}
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 666 B

View File

@ -1,220 +0,0 @@
// 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.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Controls;
using ManagedCommon;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Classes;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Helper;
using Microsoft.PowerToys.Run.Plugin.TimeZone.Properties;
using Microsoft.PowerToys.Settings.UI.Library;
using Wox.Plugin;
[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests")]
namespace Microsoft.PowerToys.Run.Plugin.TimeZone
{
/// <summary>
/// A power launcher plugin to search across time zones.
/// </summary>
public class Main : IPlugin, IContextMenu, IPluginI18n, ISettingProvider, IDisposable
{
/// <summary>
/// The name of this assembly
/// </summary>
private readonly string _assemblyName;
/// <summary>
/// The settings for this plugin.
/// </summary>
private readonly TimeZoneSettings _timeZoneSettings;
/// <summary>
/// The initial context for this plugin (contains API and meta-data)
/// </summary>
private PluginInitContext? _context;
/// <summary>
/// The path to the icon for each result
/// </summary>
private string _defaultIconPath;
/// <summary>
/// Indicate that the plugin is disposed
/// </summary>
private bool _disposed;
/// <summary>
/// A class that contain all possible time zones.
/// </summary>
private TimeZoneList? _timeZoneList;
/// <summary>
/// Initializes a new instance of the <see cref="Main"/> class.
/// </summary>
public Main()
{
_assemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? GetTranslatedPluginTitle();
_defaultIconPath = "Images/timeZone.light.png";
_timeZoneSettings = new TimeZoneSettings();
}
/// <summary>
/// Gets the localized name.
/// </summary>
public string Name
{
get { return Resources.PluginTitle; }
}
/// <summary>
/// Gets the localized description.
/// </summary>
public string Description
{
get { return Resources.PluginDescription; }
}
/// <summary>
/// Gets the additional options for this plugin.
/// </summary>
public IEnumerable<PluginAdditionalOption> AdditionalOptions
{
get { return TimeZoneSettings.GetAdditionalOptions(); }
}
/// <summary>
/// Initialize the plugin with the given <see cref="PluginInitContext"/>
/// </summary>
/// <param name="context">The <see cref="PluginInitContext"/> for this plugin</param>
public void Init(PluginInitContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
_timeZoneList = JsonHelper.ReadAllPossibleTimeZones();
TranslationHelper.TranslateAllSettings(_timeZoneList);
}
/// <summary>
/// Return a filtered list, based on the given query
/// </summary>
/// <param name="query">The query to filter the list</param>
/// <returns>A filtered list, can be empty when nothing was found</returns>
public List<Result> Query(Query query)
{
if (_timeZoneList?.TimeZones is null)
{
return new List<Result>(0);
}
if (query is null)
{
return new List<Result>(0);
}
var results = ResultHelper.GetResults(_timeZoneList.TimeZones, _timeZoneSettings, query, _defaultIconPath);
return results.ToList();
}
/// <summary>
/// Return a list context menu entries for a given <see cref="Result"/> (shown at the right side of the result)
/// </summary>
/// <param name="selectedResult">The <see cref="Result"/> for the list with context menu entries</param>
/// <returns>A list context menu entries</returns>
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
return ContextMenuHelper.GetContextMenu(selectedResult, _assemblyName);
}
/// <summary>
/// Change all theme-based elements (typical called when the plugin theme has changed)
/// </summary>
/// <param name="oldtheme">The old <see cref="Theme"/></param>
/// <param name="newTheme">The new <see cref="Theme"/></param>
private void OnThemeChanged(Theme oldtheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
/// <summary>
/// Update all icons (typical called when the plugin theme has changed)
/// </summary>
/// <param name="theme">The new <see cref="Theme"/> for the icons</param>
private void UpdateIconPath(Theme theme)
{
_defaultIconPath = theme == Theme.Light || theme == Theme.HighContrastWhite
? "Images/timeZone.light.png"
: "Images/timeZone.dark.png";
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Wrapper method for <see cref="Dispose"/> that dispose additional objects and events form the plugin itself
/// </summary>
/// <param name="disposing">Indicate that the plugin is disposed</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed || !disposing)
{
return;
}
if (!(_context is null))
{
_context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
/// <summary>
/// Return the translated plugin title.
/// </summary>
/// <returns>A translated plugin title.</returns>
public string GetTranslatedPluginTitle()
{
return Resources.PluginTitle;
}
/// <summary>
/// Return the translated plugin description.
/// </summary>
/// <returns>A translated plugin description.</returns>
public string GetTranslatedPluginDescription()
{
return Resources.PluginDescription;
}
/// <summary>
/// Return a additional setting panel for this plugin.
/// </summary>
/// <returns>A additional setting panel.</returns>
public Control CreateSettingPanel()
{
throw new NotImplementedException();
}
/// <summary>
/// Update the plugin settings
/// </summary>
/// <param name="settings">The settings for all power launcher plugin.</param>
public void UpdateSettings(PowerLauncherPluginSettings settings)
{
_timeZoneSettings.UpdateSettings(settings);
}
}
}

View File

@ -1,81 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\Version.props" />
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<RootNamespace>Microsoft.PowerToys.Run.Plugin.TimeZone</RootNamespace>
<AssemblyName>Microsoft.PowerToys.Run.Plugin.TimeZone</AssemblyName>
<Version>$(Version).0</Version>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Nullable>enable</Nullable>
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
<OutputPath>..\..\..\..\..\$(Platform)\$(Configuration)\modules\launcher\Plugins\TimeZone\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="timeZones.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Images\timeZone.light.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Images\timeZone.dark.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,13 +0,0 @@
{
"ID": "BADD1B06EF0A4B61AD95395F24241D69",
"ActionKeyword": "&",
"IsGlobal": false,
"Name": "Time zone",
"Author": "TobiasSekan",
"Version": "1.0.0",
"Language": "csharp",
"Website": "https://aka.ms/powertoys",
"ExecuteFileName": "Microsoft.PowerToys.Run.Plugin.TimeZone.dll",
"IcoPathDark": "Images\\timeZone.dark.png",
"IcoPathLight": "Images\\timeZone.light.png"
}

View File

@ -1,80 +0,0 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"TimeZones": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [ "Offset" ],
"properties": {
"Offset": {
"type": "string",
"description": "The time offset of this time zone (the gap from the UTC time zone, must convertible to a C# TimeSpan)"
},
"Name": {
"type": "string",
"description": "The name of this time zone."
},
"MilitaryName": {
"type": "string",
"description": "The military name of this time zone."
},
"Shortcut": {
"type": "string",
"description": "A shortcut for the names this time zone."
},
"TimeNamesStandard": {
"type": "array",
"description": "A list with names for the standard time.",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"TimeNamesDaylight": {
"type": "array",
"description": "A list with names for the daylight saving time.",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"ShortcutsStandard": {
"type": "array",
"description": "A list with shortcuts for the names for the standard time.",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"ShortcutsDaylight": {
"type": "array",
"description": "A list with shortcuts for the names for the daylight saving time.",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"CountriesStandard": {
"type": "array",
"description": "A list with all countries in this time zone that use a standard time.",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"CountriesDaylight": {
"type": "array",
"description": "A list with all countries in this time zone that use a daylight saving time.",
"uniqueItems": true,
"items": {
"type": "string"
}
}
}
}
}
}
}