Skip to content

Commit 950b4c9

Browse files
committed
Code cleanup: Flow.Launcher/{Converters,Helper}
1 parent da63003 commit 950b4c9

23 files changed

+971
-989
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dotnet_style_prefer_conditional_expression_over_return = true:silent
5858
###############################
5959
# Style Definitions
6060
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
61-
# Use PascalCase for constant fields
61+
# Use PascalCase for constant fields
6262
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
6363
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
6464
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
@@ -134,7 +134,7 @@ csharp_preserve_single_line_statements = true
134134
csharp_preserve_single_line_blocks = true
135135
csharp_using_directive_placement = outside_namespace:silent
136136
csharp_prefer_simple_using_statement = true:suggestion
137-
csharp_style_namespace_declarations = block_scoped:silent
137+
csharp_style_namespace_declarations = file_scoped:silent
138138
csharp_style_prefer_method_group_conversion = true:silent
139139
csharp_style_expression_bodied_lambdas = true:silent
140140
csharp_style_expression_bodied_local_functions = false:silent

Flow.Launcher/Converters/BoolToIMEConversionModeConverter.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,38 @@
33
using System.Windows.Data;
44
using System.Windows.Input;
55

6-
namespace Flow.Launcher.Converters
6+
namespace Flow.Launcher.Converters;
7+
8+
internal class BoolToIMEConversionModeConverter : IValueConverter
79
{
8-
internal class BoolToIMEConversionModeConverter : IValueConverter
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
911
{
10-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
return value switch
1113
{
12-
return value switch
13-
{
14-
true => ImeConversionModeValues.Alphanumeric,
15-
_ => ImeConversionModeValues.DoNotCare
16-
};
17-
}
14+
true => ImeConversionModeValues.Alphanumeric,
15+
_ => ImeConversionModeValues.DoNotCare
16+
};
17+
}
1818

19-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20-
{
21-
throw new NotImplementedException();
22-
}
19+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20+
{
21+
throw new NotImplementedException();
2322
}
23+
}
2424

25-
internal class BoolToIMEStateConverter : IValueConverter
25+
internal class BoolToIMEStateConverter : IValueConverter
26+
{
27+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
2628
{
27-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
29+
return value switch
2830
{
29-
return value switch
30-
{
31-
true => InputMethodState.Off,
32-
_ => InputMethodState.DoNotCare
33-
};
34-
}
31+
true => InputMethodState.Off,
32+
_ => InputMethodState.DoNotCare
33+
};
34+
}
3535

36-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
37-
{
38-
throw new NotImplementedException();
39-
}
36+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
37+
{
38+
throw new NotImplementedException();
4039
}
4140
}

Flow.Launcher/Converters/BoolToVisibilityConverter.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,39 @@
22
using System.Windows;
33
using System.Windows.Data;
44

5-
namespace Flow.Launcher.Converters
5+
namespace Flow.Launcher.Converters;
6+
7+
public class BoolToVisibilityConverter : IValueConverter
68
{
7-
public class BoolToVisibilityConverter : IValueConverter
9+
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
810
{
9-
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
11+
return (value, parameter) switch
1012
{
11-
return (value, parameter) switch
12-
{
13-
(true, not null) => Visibility.Collapsed,
14-
(_, not null) => Visibility.Visible,
15-
16-
(true, null) => Visibility.Visible,
17-
(_, null) => Visibility.Collapsed
18-
};
19-
}
13+
(true, not null) => Visibility.Collapsed,
14+
(_, not null) => Visibility.Visible,
2015

21-
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
16+
(true, null) => Visibility.Visible,
17+
(_, null) => Visibility.Collapsed
18+
};
2219
}
2320

24-
public class SplitterConverter : IValueConverter
25-
/* Prevents the dragging part of the preview area from working when preview is turned off. */
21+
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
22+
}
23+
24+
public class SplitterConverter : IValueConverter
25+
/* Prevents the dragging part of the preview area from working when preview is turned off. */
26+
{
27+
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
2628
{
27-
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
29+
return (value, parameter) switch
2830
{
29-
return (value, parameter) switch
30-
{
31-
(true, not null) => 0,
32-
(_, not null) => 5,
33-
34-
(true, null) => 5,
35-
(_, null) => 0
36-
};
37-
}
31+
(true, not null) => 0,
32+
(_, not null) => 5,
3833

39-
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
34+
(true, null) => 5,
35+
(_, null) => 0
36+
};
4037
}
38+
39+
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
4140
}

Flow.Launcher/Converters/BorderClipConverter.cs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,41 @@
77

88
// For Clipping inside listbox item
99

10-
namespace Flow.Launcher.Converters
10+
namespace Flow.Launcher.Converters;
11+
12+
public class BorderClipConverter : IMultiValueConverter
1113
{
12-
public class BorderClipConverter : IMultiValueConverter
14+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
1315
{
14-
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
16+
if (values is not [double width, double height, CornerRadius radius])
1517
{
16-
if (values is not [double width, double height, CornerRadius radius])
17-
{
18-
return DependencyProperty.UnsetValue;
19-
}
20-
21-
Path myPath = new Path();
22-
if (width < Double.Epsilon || height < Double.Epsilon)
23-
{
24-
return Geometry.Empty;
25-
}
26-
var radiusHeight = radius.TopLeft;
27-
28-
// Drawing Round box for bottom round, and rect for top area of listbox.
29-
var corner = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
30-
var box = new RectangleGeometry(new Rect(0, 0, width, radiusHeight), 0, 0);
31-
32-
GeometryGroup myGeometryGroup = new GeometryGroup();
33-
myGeometryGroup.Children.Add(corner);
34-
myGeometryGroup.Children.Add(box);
35-
36-
CombinedGeometry c1 = new CombinedGeometry(GeometryCombineMode.Union, corner, box);
37-
myPath.Data = c1;
38-
39-
myPath.Data.Freeze();
40-
return myPath.Data;
18+
return DependencyProperty.UnsetValue;
4119
}
4220

43-
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
21+
Path myPath = new Path();
22+
if (width < Double.Epsilon || height < Double.Epsilon)
4423
{
45-
throw new NotSupportedException();
24+
return Geometry.Empty;
4625
}
26+
var radiusHeight = radius.TopLeft;
27+
28+
// Drawing Round box for bottom round, and rect for top area of listbox.
29+
var corner = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
30+
var box = new RectangleGeometry(new Rect(0, 0, width, radiusHeight), 0, 0);
31+
32+
GeometryGroup myGeometryGroup = new GeometryGroup();
33+
myGeometryGroup.Children.Add(corner);
34+
myGeometryGroup.Children.Add(box);
35+
36+
CombinedGeometry c1 = new CombinedGeometry(GeometryCombineMode.Union, corner, box);
37+
myPath.Data = c1;
38+
39+
myPath.Data.Freeze();
40+
return myPath.Data;
4741
}
4842

43+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
44+
{
45+
throw new NotSupportedException();
46+
}
4947
}

Flow.Launcher/Converters/DateTimeFormatToNowConverter.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
using System.Globalization;
33
using System.Windows.Data;
44

5-
namespace Flow.Launcher.Converters
5+
namespace Flow.Launcher.Converters;
6+
7+
public class DateTimeFormatToNowConverter : IValueConverter
68
{
7-
public class DateTimeFormatToNowConverter : IValueConverter
8-
{
99

10-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11-
{
12-
return value is not string format ? null : DateTime.Now.ToString(format);
13-
}
14-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
15-
{
16-
throw new NotImplementedException();
17-
}
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
return value is not string format ? null : DateTime.Now.ToString(format);
13+
}
14+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
throw new NotImplementedException();
1817
}
1918
}

Flow.Launcher/Converters/DiameterToCenterPointConverter.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
using System.Windows;
44
using System.Windows.Data;
55

6-
namespace Flow.Launcher.Converters
6+
namespace Flow.Launcher.Converters;
7+
8+
public class DiameterToCenterPointConverter : IValueConverter
79
{
8-
public class DiameterToCenterPointConverter : IValueConverter
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
911
{
10-
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
if (value is double d)
1113
{
12-
if (value is double d)
13-
{
14-
return new Point(d / 2, d / 2);
15-
}
16-
17-
return new Point(0, 0);
14+
return new Point(d / 2, d / 2);
1815
}
1916

20-
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
21-
{
22-
throw new NotSupportedException();
23-
}
17+
return new Point(0, 0);
18+
}
19+
20+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
21+
{
22+
throw new NotSupportedException();
2423
}
2524
}

Flow.Launcher/Converters/HighlightTextConverter.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,44 @@
55
using System.Windows.Data;
66
using System.Windows.Documents;
77

8-
namespace Flow.Launcher.Converters
8+
namespace Flow.Launcher.Converters;
9+
10+
public class HighlightTextConverter : IMultiValueConverter
911
{
10-
public class HighlightTextConverter : IMultiValueConverter
12+
public object Convert(object[] value, Type targetType, object parameter, CultureInfo cultureInfo)
1113
{
12-
public object Convert(object[] value, Type targetType, object parameter, CultureInfo cultureInfo)
14+
if (value.Length < 2)
15+
return new Run(string.Empty);
16+
17+
if (value[0] is not string text)
18+
return new Run(string.Empty);
19+
20+
if (value[1] is not List<int> { Count: > 0 } highlightData)
21+
// No highlight data, just return the text
22+
return new Run(text);
23+
24+
var highlightStyle = (Style)Application.Current.FindResource("HighlightStyle");
25+
var textBlock = new Span();
26+
27+
for (var i = 0; i < text.Length; i++)
1328
{
14-
if (value.Length < 2)
15-
return new Run(string.Empty);
16-
17-
if (value[0] is not string text)
18-
return new Run(string.Empty);
19-
20-
if (value[1] is not List<int> { Count: > 0 } highlightData)
21-
// No highlight data, just return the text
22-
return new Run(text);
23-
24-
var highlightStyle = (Style)Application.Current.FindResource("HighlightStyle");
25-
var textBlock = new Span();
26-
27-
for (var i = 0; i < text.Length; i++)
29+
var currentCharacter = text.Substring(i, 1);
30+
var run = new Run(currentCharacter)
2831
{
29-
var currentCharacter = text.Substring(i, 1);
30-
var run = new Run(currentCharacter)
31-
{
32-
Style = ShouldHighlight(highlightData, i) ? highlightStyle : null
33-
};
34-
textBlock.Inlines.Add(run);
35-
}
36-
return textBlock;
32+
Style = ShouldHighlight(highlightData, i) ? highlightStyle : null
33+
};
34+
textBlock.Inlines.Add(run);
3735
}
36+
return textBlock;
37+
}
3838

39-
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
40-
{
41-
return new[] { DependencyProperty.UnsetValue, DependencyProperty.UnsetValue };
42-
}
39+
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
40+
{
41+
return new[] { DependencyProperty.UnsetValue, DependencyProperty.UnsetValue };
42+
}
4343

44-
private bool ShouldHighlight(List<int> highlightData, int index)
45-
{
46-
return highlightData.Contains(index);
47-
}
44+
private bool ShouldHighlight(List<int> highlightData, int index)
45+
{
46+
return highlightData.Contains(index);
4847
}
4948
}

Flow.Launcher/Converters/IconRadiusConverter.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
using System.Globalization;
33
using System.Windows.Data;
44

5-
namespace Flow.Launcher.Converters
5+
namespace Flow.Launcher.Converters;
6+
7+
public class IconRadiusConverter : IMultiValueConverter
68
{
7-
public class IconRadiusConverter : IMultiValueConverter
9+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
810
{
9-
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
10-
{
11-
if (values is not [double size, bool isIconCircular])
12-
throw new ArgumentException("IconRadiusConverter must have 2 parameters: [double, bool]");
11+
if (values is not [double size, bool isIconCircular])
12+
throw new ArgumentException("IconRadiusConverter must have 2 parameters: [double, bool]");
1313

14-
return isIconCircular ? size / 2 : size;
15-
}
16-
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
17-
{
18-
throw new NotSupportedException();
19-
}
14+
return isIconCircular ? size / 2 : size;
15+
}
16+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
17+
{
18+
throw new NotSupportedException();
2019
}
2120
}

0 commit comments

Comments
 (0)