refactor(ui): merge the one-expression converters into SimpleConverters.cs
Six files of three lines each. NotNullToBool is gone entirely — Avalonia ships ObjectConverters.IsNotNull, so TaskRowView binds that directly.
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<!-- Converters -->
|
<!-- Converters -->
|
||||||
<converters:NotNullToBoolConverter x:Key="NotNullToBool"/>
|
|
||||||
<converters:StrikeIfTrueConverter x:Key="StrikeIfTrue"/>
|
<converters:StrikeIfTrueConverter x:Key="StrikeIfTrue"/>
|
||||||
<converters:EqStatusConverter x:Key="EqStatus"/>
|
<converters:EqStatusConverter x:Key="EqStatus"/>
|
||||||
<converters:UpperCaseConverter x:Key="UpperCase"/>
|
<converters:UpperCaseConverter x:Key="UpperCase"/>
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
public sealed class BoolToDraftOpacityConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> value is true ? 0.7 : 1.0;
|
|
||||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
public sealed class BoolToItalicConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> value is true ? FontStyle.Italic : FontStyle.Normal;
|
|
||||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
using ClaudeDo.Ui.ViewModels.Islands;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
// Drives ListBoxItem.Focusable for TasksIslandView's flat Rows list: a HeaderRow container must
|
|
||||||
// not be a tab stop, a TaskRowViewModel container must behave like any other row.
|
|
||||||
public class NotHeaderRowConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public static NotHeaderRowConverter Instance { get; } = new();
|
|
||||||
|
|
||||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> value is not HeaderRow;
|
|
||||||
|
|
||||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
public class NotNullToBoolConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public static NotNullToBoolConverter Instance { get; } = new();
|
|
||||||
|
|
||||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> value is not null;
|
|
||||||
|
|
||||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using ClaudeDo.Ui.ViewModels.Islands;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.Converters;
|
||||||
|
|
||||||
|
// One-expression converters. Each is only worth a class because Avalonia XAML can't
|
||||||
|
// instantiate a generic FuncValueConverter as a resource; they stay one per type so the
|
||||||
|
// x:Key names in App.axaml keep resolving. Anything with real logic gets its own file.
|
||||||
|
|
||||||
|
public sealed class UpperCaseConverter : OneWayConverter
|
||||||
|
{
|
||||||
|
public static UpperCaseConverter Instance { get; } = new();
|
||||||
|
public override object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value?.ToString()?.ToUpperInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class StrikeIfTrueConverter : OneWayConverter
|
||||||
|
{
|
||||||
|
public static StrikeIfTrueConverter Instance { get; } = new();
|
||||||
|
public override object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value is true ? TextDecorations.Strikethrough : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class BoolToItalicConverter : OneWayConverter
|
||||||
|
{
|
||||||
|
public override object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value is true ? FontStyle.Italic : FontStyle.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class BoolToDraftOpacityConverter : OneWayConverter
|
||||||
|
{
|
||||||
|
public override object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value is true ? 0.7 : 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drives ListBoxItem.Focusable for TasksIslandView's flat Rows list: a HeaderRow container must
|
||||||
|
// not be a tab stop, a TaskRowViewModel container must behave like any other row.
|
||||||
|
public sealed class NotHeaderRowConverter : OneWayConverter
|
||||||
|
{
|
||||||
|
public static NotHeaderRowConverter Instance { get; } = new();
|
||||||
|
public override object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> value is not HeaderRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class OneWayConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public abstract object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture);
|
||||||
|
|
||||||
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
=> throw new NotSupportedException();
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
using Avalonia.Media;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
public class StrikeIfTrueConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public static StrikeIfTrueConverter Instance { get; } = new();
|
|
||||||
|
|
||||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> value is true ? TextDecorations.Strikethrough : null;
|
|
||||||
|
|
||||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
public class UpperCaseConverter : IValueConverter
|
|
||||||
{
|
|
||||||
public static UpperCaseConverter Instance { get; } = new();
|
|
||||||
|
|
||||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> value?.ToString()?.ToUpperInvariant();
|
|
||||||
|
|
||||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
|
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Islands"
|
||||||
xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
|
xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
|
||||||
|
xmlns:conv="using:Avalonia.Data.Converters"
|
||||||
xmlns:loc="using:ClaudeDo.Ui.Localization"
|
xmlns:loc="using:ClaudeDo.Ui.Localization"
|
||||||
x:Class="ClaudeDo.Ui.Views.Islands.TaskRowView"
|
x:Class="ClaudeDo.Ui.Views.Islands.TaskRowView"
|
||||||
x:DataType="vm:TaskRowViewModel">
|
x:DataType="vm:TaskRowViewModel">
|
||||||
@@ -187,7 +188,7 @@
|
|||||||
<!-- Chain-after chip: the head-relative fallback when this row isn't rendered as a
|
<!-- Chain-after chip: the head-relative fallback when this row isn't rendered as a
|
||||||
rail member (planning child, or the head is filtered out of this view). -->
|
rail member (planning child, or the head is filtered out of this view). -->
|
||||||
<Border Classes="chip chip-tag"
|
<Border Classes="chip chip-tag"
|
||||||
IsVisible="{Binding ChainAfterLabel, Converter={StaticResource NotNullToBool}}">
|
IsVisible="{Binding ChainAfterLabel, Converter={x:Static conv:ObjectConverters.IsNotNull}}">
|
||||||
<TextBlock>
|
<TextBlock>
|
||||||
<Run Text="{loc:Tr tasks.chainAfterPrefix}"/>
|
<Run Text="{loc:Tr tasks.chainAfterPrefix}"/>
|
||||||
<Run Text=" "/>
|
<Run Text=" "/>
|
||||||
|
|||||||
Reference in New Issue
Block a user