Skip to content

Commit 455b221

Browse files
committed
Code cleanup: Flow.Launcher/Converters — requested changes
1 parent 185695b commit 455b221

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

Flow.Launcher/Converters/BoolToVisibilityConverter.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public class BoolToVisibilityConverter : IValueConverter
88
{
99
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
1010
{
11-
return value switch
11+
return (value, parameter) switch
1212
{
13-
true when parameter is not null => Visibility.Collapsed,
14-
_ when parameter is not null => Visibility.Visible,
15-
16-
true => Visibility.Visible,
17-
_ => Visibility.Collapsed
13+
(true, not null) => Visibility.Collapsed,
14+
(_, not null) => Visibility.Visible,
15+
16+
(true, null) => Visibility.Visible,
17+
(_, null) => Visibility.Collapsed
1818
};
1919
}
2020

@@ -26,13 +26,13 @@ public class SplitterConverter : IValueConverter
2626
{
2727
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
2828
{
29-
return value switch
29+
return (value, parameter) switch
3030
{
31-
true when parameter is not null => 0,
32-
_ when parameter is not null => 5,
33-
34-
true => 5,
35-
_ => 0,
31+
(true, not null) => 0,
32+
(_, not null) => 5,
33+
34+
(true, null) => 5,
35+
(_, null) => 0
3636
};
3737
}
3838

Flow.Launcher/Converters/IconRadiusConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public class IconRadiusConverter : IMultiValueConverter
88
{
99
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
1010
{
11-
if (values is not [double size, bool half])
11+
if (values is not [double size, bool isIconCircular])
1212
throw new ArgumentException("IconRadiusConverter must have 2 parameters: [double, bool]");
1313

14-
return half ? size / 2 : size;
14+
return isIconCircular ? size / 2 : size;
1515
}
1616
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
1717
{

Flow.Launcher/Converters/QuerySuggestionBoxConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter
1212
{
1313
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
1414
{
15+
// values[0] is TextBox: The textbox displaying the autocomplete suggestion
16+
// values[1] is ResultViewModel: Currently selected item in the list
17+
// values[2] is string: Query text
1518
if (
1619
values.Length != 3 ||
1720
values[0] is not TextBox queryTextBox ||
@@ -26,7 +29,6 @@ values[2] is not string queryText ||
2629

2730
try
2831
{
29-
3032
var selectedResult = selectedItem.Result;
3133
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
3234
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;

Flow.Launcher/Converters/TextConverter.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ public class TextConverter : IValueConverter
1111
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1212
{
1313
var id = value?.ToString();
14-
return id switch
14+
var translationKey = id switch
1515
{
16-
PluginStoreItemViewModel.NewRelease => InternationalizationManager.Instance.GetTranslation("pluginStore_NewRelease"),
17-
PluginStoreItemViewModel.RecentlyUpdated => InternationalizationManager.Instance.GetTranslation("pluginStore_RecentlyUpdated"),
18-
PluginStoreItemViewModel.None => InternationalizationManager.Instance.GetTranslation("pluginStore_None"),
19-
PluginStoreItemViewModel.Installed => InternationalizationManager.Instance.GetTranslation("pluginStore_Installed"),
20-
_ => id
16+
PluginStoreItemViewModel.NewRelease => "pluginStore_NewRelease",
17+
PluginStoreItemViewModel.RecentlyUpdated => "pluginStore_RecentlyUpdated",
18+
PluginStoreItemViewModel.None => "pluginStore_None",
19+
PluginStoreItemViewModel.Installed => "pluginStore_Installed",
20+
_ => null
2121
};
22+
23+
if (translationKey is null)
24+
return id;
25+
26+
return InternationalizationManager.Instance.GetTranslation(translationKey);
2227
}
2328

2429
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new InvalidOperationException();

0 commit comments

Comments
 (0)