refactor: using x:Int32 and x:String instead of custom types

This commit is contained in:
leo 2024-07-26 15:02:23 +08:00
parent 81331d10c7
commit bab1a57480
No known key found for this signature in database
4 changed files with 24 additions and 30 deletions

View file

@ -197,7 +197,7 @@
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比对工具查看</x:String> <x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比对工具查看</x:String>
<x:String x:Key="Text.Discard" xml:space="preserve">放弃更改确认</x:String> <x:String x:Key="Text.Discard" xml:space="preserve">放弃更改确认</x:String>
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String> <x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">需要放弃的变更 </x:String> <x:String x:Key="Text.Discard.Changes" xml:space="preserve">变更 </x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">总计{0}项选中更改</x:String> <x:String x:Key="Text.Discard.Total" xml:space="preserve">总计{0}项选中更改</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">本操作不支持回退,请确认后继续!!!</x:String> <x:String x:Key="Text.Discard.Warning" xml:space="preserve">本操作不支持回退,请确认后继续!!!</x:String>
<x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">书签 </x:String> <x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">书签 </x:String>

View file

@ -197,7 +197,7 @@
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比對工具檢視</x:String> <x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比對工具檢視</x:String>
<x:String x:Key="Text.Discard" xml:space="preserve">放棄更改確認</x:String> <x:String x:Key="Text.Discard" xml:space="preserve">放棄更改確認</x:String>
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String> <x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">需要放棄的變更 </x:String> <x:String x:Key="Text.Discard.Changes" xml:space="preserve">變更 </x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">總計{0}項選中更改</x:String> <x:String x:Key="Text.Discard.Total" xml:space="preserve">總計{0}項選中更改</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">本操作不支援回退,請確認後繼續!!!</x:String> <x:String x:Key="Text.Discard.Warning" xml:space="preserve">本操作不支援回退,請確認後繼續!!!</x:String>
<x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">書籤 </x:String> <x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">書籤 </x:String>

View file

@ -3,10 +3,6 @@ using System.Threading.Tasks;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
{ {
public class DiscardModeAll { }
public class DiscardModeSingle { public string File { get; set; } }
public class DiscardModeMulti { public int Count { get; set; } }
public class Discard : Popup public class Discard : Popup
{ {
public object Mode public object Mode
@ -19,7 +15,7 @@ namespace SourceGit.ViewModels
{ {
_repo = repo; _repo = repo;
Mode = new DiscardModeAll(); Mode = null;
View = new Views.Discard { DataContext = this }; View = new Views.Discard { DataContext = this };
} }
@ -30,17 +26,11 @@ namespace SourceGit.ViewModels
_isUnstaged = isUnstaged; _isUnstaged = isUnstaged;
if (_changes == null) if (_changes == null)
{ Mode = null;
Mode = new DiscardModeAll();
}
else if (_changes.Count == 1) else if (_changes.Count == 1)
{ Mode = _changes[0].Path;
Mode = new DiscardModeSingle() { File = _changes[0].Path };
}
else else
{ Mode = _changes.Count;
Mode = new DiscardModeMulti() { Count = _changes.Count };
}
View = new Views.Discard() { DataContext = this }; View = new Views.Discard() { DataContext = this };
} }

View file

@ -12,28 +12,32 @@
Classes="bold" Classes="bold"
Text="{DynamicResource Text.Discard}"/> Text="{DynamicResource Text.Discard}"/>
<Grid Margin="0,16,0,8" RowDefinitions="32,32" ColumnDefinitions="150,*"> <Grid Margin="0,16,0,8" RowDefinitions="32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,8,0" HorizontalAlignment="Right" Text="{DynamicResource Text.Discard.Changes}"/> <TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,8,0" HorizontalAlignment="Right" Text="{DynamicResource Text.Discard.Changes}"/>
<ContentControl Grid.Row="0" Grid.Column="1" Content="{Binding Mode}"> <ContentControl Grid.Row="0" Grid.Column="1">
<ContentControl.Content>
<Binding Path="Mode">
<Binding.TargetNullValue>
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Folder.Open}"/>
<TextBlock Text="{DynamicResource Text.Discard.All}" Margin="4,0,0,0"/>
</StackPanel>
</Binding.TargetNullValue>
</Binding>
</ContentControl.Content>
<ContentControl.DataTemplates> <ContentControl.DataTemplates>
<DataTemplate DataType="vm:DiscardModeAll"> <DataTemplate DataType="x:String">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Folder.Open}"/> <Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
<TextBlock Text="{DynamicResource Text.Discard.All}" Margin="4,0,0,0"/> <TextBlock Text="{Binding}" Margin="4,0,0,0"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
<DataTemplate DataType="vm:DiscardModeSingle"> <DataTemplate DataType="x:Int32">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}"/> <Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
<TextBlock Text="{Binding File}" Margin="4,0,0,0"/> <TextBlock Text="{Binding, Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Discard.Total'}" Margin="4,0,0,0"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="vm:DiscardModeMulti">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
<TextBlock Text="{Binding Count, Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Discard.Total'}" Margin="4,0,0,0"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>