// 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.Runtime.CompilerServices;
using System.Windows;
using Microsoft.PowerToys.Run.Plugin.TimeDate.Properties;
using Wox.Plugin;
using Wox.Plugin.Logger;
[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests")]
namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components
{
internal static class ResultHelper
{
///
/// Get the string based on the requested type
///
/// Does the user search for system date/time?
/// Id of the string. (Example: `MyString` for `MyString` and `MyStringNow`)
/// Optional string id for now case
/// The string from the resource file, or otherwise.
internal static string SelectStringFromResources(bool isSystemTimeDate, string stringId, string stringIdNow = default)
{
if (!isSystemTimeDate)
{
return Resources.ResourceManager.GetString(stringId, CultureInfo.CurrentUICulture) ?? string.Empty;
}
else if (!string.IsNullOrEmpty(stringIdNow))
{
return Resources.ResourceManager.GetString(stringIdNow, CultureInfo.CurrentUICulture) ?? string.Empty;
}
else
{
return Resources.ResourceManager.GetString(stringId + "Now", CultureInfo.CurrentUICulture) ?? string.Empty;
}
}
///
/// Copy the given text to the clipboard
///
/// The text to copy to the clipboard
/// The text successful copy to the clipboard; otherwise,
/// Code copied from TimeZone plugin
internal static bool CopyToClipBoard(in string text)
{
try
{
Clipboard.SetText(text);
return true;
}
catch (Exception exception)
{
Log.Exception("Can't copy to clipboard", exception, typeof(ResultHelper));
MessageBox.Show(exception.Message, Resources.Microsoft_plugin_timedate_copy_failed);
return false;
}
}
///
/// Create a tool tip for the alternative search tags
///
/// The .
/// New object or null if is empty.
internal static ToolTipData GetSearchTagToolTip(AvailableResult result, out Visibility visibility)
{
switch (string.IsNullOrEmpty(result.AlternativeSearchTag))
{
case true:
visibility = Visibility.Hidden;
return null;
default:
visibility = Visibility.Visible;
return new ToolTipData(Resources.Microsoft_plugin_timedate_ToolTipAlternativeSearchTag, result.AlternativeSearchTag);
}
}
///
/// Gets a result with an error message that only numbers can't be parsed
///
/// Element of type .
internal static Result CreateNumberErrorResult(string theme, string title, string subtitle) => new Result()
{
Title = title,
SubTitle = subtitle,
ToolTipData = new ToolTipData(Resources.Microsoft_plugin_timedate_ErrorResultTitle, Resources.Microsoft_plugin_timedate_ErrorResultSubTitle),
IcoPath = $"Images\\Warning.{theme}.png",
};
}
}