fix: 扫描时界面会因为文件名不同而抖动的问题

This commit is contained in:
2026-06-08 13:40:27 +08:00
parent d72193a693
commit 40b8524ffd
5 changed files with 59 additions and 16 deletions
+39
View File
@@ -100,6 +100,43 @@ public class InverseBoolConverter : IValueConverter
}
}
public class HalfDoubleConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is double d && !double.IsNaN(d) && !double.IsInfinity(d))
return d / 2.0;
return 400.0;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
public class MiddleTruncateConverter : IValueConverter
{
private const int KeepTail = 10;
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not string text || string.IsNullOrEmpty(text)) return value;
int maxLength = 60;
if (parameter != null && int.TryParse(parameter.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsed))
maxLength = parsed;
if (text.Length <= maxLength) return text;
int head = maxLength - KeepTail - 3;
if (head <= 0) return text[..maxLength];
return string.Concat(text.AsSpan(0, head), "...", text.AsSpan(text.Length - KeepTail, KeepTail));
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}
public static class ValueConverters
{
public static readonly IValueConverter DurationFormat = new DurationFormatConverter();
@@ -109,4 +146,6 @@ public static class ValueConverters
public static readonly IValueConverter DurationToSliderMax = new DurationToSliderMaxConverter();
public static readonly IValueConverter PositionFormat = new PositionFormatConverter();
public static readonly IValueConverter InverseBool = new InverseBoolConverter();
public static readonly IValueConverter HalfDouble = new HalfDoubleConverter();
public static readonly IValueConverter MiddleTruncate = new MiddleTruncateConverter();
}
+3 -3
View File
@@ -16,15 +16,15 @@
<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>
<Grid RowDefinitions="Auto,*,Auto">
<!-- 工具栏 -->
<Border Grid.Row="0" Padding="6,4" BorderBrush="{DynamicResource SystemBaseLowColorBrush}"
BorderThickness="0,0,0,1" Background="{DynamicResource SystemAltMediumColorBrush}">
<StackPanel Orientation="Horizontal" Spacing="4">
<Button Content="📁 扫描目录" x:Name="ScanButton" Height="28" Padding="8,0"/>
<Button Content="偏好设置" Height="28" Padding="8,0" IsEnabled="False"/>
<Button Content="扫描目录" x:Name="ScanButton" Height="28" Padding="8,0"/>
<Button Content="偏好设置" Height="28" Padding="8,0" IsEnabled="False"/>
</StackPanel>
</Border>
+9 -3
View File
@@ -1,6 +1,7 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:GUI.ViewModels"
xmlns:converters="using:GUI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
@@ -10,8 +11,13 @@
<vm:ScanProgressViewModel/>
</Design.DataContext>
<UserControl.Resources>
<converters:HalfDoubleConverter x:Key="HalfDouble"/>
<converters:MiddleTruncateConverter x:Key="MiddleTruncate"/>
</UserControl.Resources>
<Border Padding="16" Background="{DynamicResource SystemBaseLowColorBrush}" CornerRadius="8"
MaxWidth="400">
Width="{Binding $parent[Window].Width, Converter={StaticResource HalfDouble}}">
<StackPanel Spacing="8">
<TextBlock Text="{Binding StatusText}" FontWeight="SemiBold" FontSize="13" TextWrapping="Wrap"/>
<ProgressBar Minimum="0" Maximum="100" Value="{Binding Progress}" Height="8"/>
@@ -27,8 +33,8 @@
<TextBlock Text="{Binding SkippedFiles, StringFormat='跳过: {0}'}" FontSize="11"
Foreground="{DynamicResource SystemBaseMediumColorBrush}"/>
</StackPanel>
<TextBlock Text="{Binding CurrentFile}" FontSize="11"
TextTrimming="CharacterEllipsis" MaxWidth="368"/>
<TextBlock Text="{Binding CurrentFile, Converter={StaticResource MiddleTruncate}, ConverterParameter=60}"
FontSize="11"/>
<Button Content="关闭" Command="{Binding DismissCommand}"
IsVisible="{Binding HasError}" HorizontalAlignment="Right"/>
</StackPanel>
+2
View File
@@ -2,6 +2,8 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFormat_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fe2d95a1d7b987bbb7785b2ad7e2e3e29075ba79cdf7619dd26c10d266c5_003FFormat_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGUI_002EViewModels_002EScanProgressViewModel_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fbb74b3c6eaaeb5d783f31310eae5345eba75596a_003FGUI_002EViewModels_002EScanProgressViewModel_002Eg_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F1a6f588df342309187674fcc524512a9a4a46540_003FGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fvar_003Ffolders_003F5b_003F4wt_005Fpwy11fz5nkdv7s47r3780000gn_003FT_003FSourceGeneratedDocuments_003F8E641B210524A46B7DCD4502_003FCommunityToolkit_002EMvvm_002ESourceGenerators_003FCommunityToolkit_002EMvvm_002ESourceGenerators_002ERelayCommandGenerator_003FGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F1a6f588df342309187674fcc524512a9a4a46540_003FGUI_002EViewModels_002EScanProgressViewModel_002EStartScan_002Eg_002Ecs_002Fz_003A2_002D0/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIDbConnection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F01c4805efedf4381865d701be69b5ce5314910_003F77_003Ffb273e4d_003FIDbConnection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIRelayCommand_007BT_007D_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F49f2a292ecb417be1f61c426de242e503b4371a346bf5b68a843b462337e62_003FIRelayCommand_007BT_007D_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AOSPlatform_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003F9e988c941e6515999ebab7336243c87df16e340b8faeb57b5f562d2b8a7c2c_003FOSPlatform_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>