Code cleanup: Flow.Launcher/Converters — requested changes

This commit is contained in:
Yusyuriv 2024-02-25 00:36:20 +06:00
parent 185695b9ae
commit 455b221163
4 changed files with 28 additions and 21 deletions

View file

@ -8,13 +8,13 @@ namespace Flow.Launcher.Converters
{
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
{
return value switch
return (value, parameter) switch
{
true when parameter is not null => Visibility.Collapsed,
_ when parameter is not null => Visibility.Visible,
true => Visibility.Visible,
_ => Visibility.Collapsed
(true, not null) => Visibility.Collapsed,
(_, not null) => Visibility.Visible,
(true, null) => Visibility.Visible,
(_, null) => Visibility.Collapsed
};
}
@ -26,13 +26,13 @@ namespace Flow.Launcher.Converters
{
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
{
return value switch
return (value, parameter) switch
{
true when parameter is not null => 0,
_ when parameter is not null => 5,
true => 5,
_ => 0,
(true, not null) => 0,
(_, not null) => 5,
(true, null) => 5,
(_, null) => 0
};
}

View file

@ -8,10 +8,10 @@ namespace Flow.Launcher.Converters
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values is not [double size, bool half])
if (values is not [double size, bool isIconCircular])
throw new ArgumentException("IconRadiusConverter must have 2 parameters: [double, bool]");
return half ? size / 2 : size;
return isIconCircular ? size / 2 : size;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{

View file

@ -12,6 +12,9 @@ namespace Flow.Launcher.Converters
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
// values[0] is TextBox: The textbox displaying the autocomplete suggestion
// values[1] is ResultViewModel: Currently selected item in the list
// values[2] is string: Query text
if (
values.Length != 3 ||
values[0] is not TextBox queryTextBox ||
@ -26,7 +29,6 @@ namespace Flow.Launcher.Converters
try
{
var selectedResult = selectedItem.Result;
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;

View file

@ -11,14 +11,19 @@ namespace Flow.Launcher.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var id = value?.ToString();
return id switch
var translationKey = id switch
{
PluginStoreItemViewModel.NewRelease => InternationalizationManager.Instance.GetTranslation("pluginStore_NewRelease"),
PluginStoreItemViewModel.RecentlyUpdated => InternationalizationManager.Instance.GetTranslation("pluginStore_RecentlyUpdated"),
PluginStoreItemViewModel.None => InternationalizationManager.Instance.GetTranslation("pluginStore_None"),
PluginStoreItemViewModel.Installed => InternationalizationManager.Instance.GetTranslation("pluginStore_Installed"),
_ => id
PluginStoreItemViewModel.NewRelease => "pluginStore_NewRelease",
PluginStoreItemViewModel.RecentlyUpdated => "pluginStore_RecentlyUpdated",
PluginStoreItemViewModel.None => "pluginStore_None",
PluginStoreItemViewModel.Installed => "pluginStore_Installed",
_ => null
};
if (translationKey is null)
return id;
return InternationalizationManager.Instance.GetTranslation(translationKey);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException();