optimize: use combined diff view as default.

This commit is contained in:
leo 2024-03-20 13:08:01 +08:00
parent 7b0fe3a771
commit f175f5abc1
9 changed files with 1708 additions and 1720 deletions

View file

@ -84,4 +84,5 @@
<StreamGeometry x:Key="Icons.VSCode">M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z</StreamGeometry> <StreamGeometry x:Key="Icons.VSCode">M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z</StreamGeometry>
<StreamGeometry x:Key="Icons.Statistics">M296 912H120c-4.4 0-8-3.6-8-8V520c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v384c0 4.4-3.6 8-8 8zM600 912H424c-4.4 0-8-3.6-8-8V121c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v783c0 4.4-3.6 8-8 8zM904 912H728c-4.4 0-8-3.6-8-8V280c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v624c0 4.4-3.6 8-8 8z</StreamGeometry> <StreamGeometry x:Key="Icons.Statistics">M296 912H120c-4.4 0-8-3.6-8-8V520c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v384c0 4.4-3.6 8-8 8zM600 912H424c-4.4 0-8-3.6-8-8V121c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v783c0 4.4-3.6 8-8 8zM904 912H728c-4.4 0-8-3.6-8-8V280c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v624c0 4.4-3.6 8-8 8z</StreamGeometry>
<StreamGeometry x:Key="Icons.Hotkeys">M512 0C229.216 0 0 229.216 0 512c0 282.752 229.216 512 512 512s512-229.248 512-512c0-282.784-229.216-512-512-512z m0 957.92C266.112 957.92 66.08 757.888 66.08 512S266.112 66.08 512 66.08 957.92 266.112 957.92 512 757.888 957.92 512 957.92zM192 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM384 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM576 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM832 320h-64a32 32 0 0 0-32 32v128h-160a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h256a32 32 0 0 0 32-32v-192a32 32 0 0 0-32-32zM320 544v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h96a32 32 0 0 0 32-32zM384 576h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM800 640H256a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h544a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32z</StreamGeometry> <StreamGeometry x:Key="Icons.Hotkeys">M512 0C229.216 0 0 229.216 0 512c0 282.752 229.216 512 512 512s512-229.248 512-512c0-282.784-229.216-512-512-512z m0 957.92C266.112 957.92 66.08 757.888 66.08 512S266.112 66.08 512 66.08 957.92 266.112 957.92 512 757.888 957.92 512 957.92zM192 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM384 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM576 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM832 320h-64a32 32 0 0 0-32 32v128h-160a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h256a32 32 0 0 0 32-32v-192a32 32 0 0 0-32-32zM320 544v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h96a32 32 0 0 0 32-32zM384 576h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM800 640H256a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h544a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32z</StreamGeometry>
<StreamGeometry x:Key="Icons.SideBySide">M875 117H149C109 117 75 151 75 192v640c0 41 34 75 75 75h725c41 0 75-34 75-75V192c0-41-34-75-75-75zM139 832V192c0-6 4-11 11-11h331v661H149c-6 0-11-4-11-11zm747 0c0 6-4 11-11 11H544v-661H875c6 0 11 4 11 11v640z</StreamGeometry>
</ResourceDictionary> </ResourceDictionary>

View file

@ -1248,15 +1248,6 @@ namespace SourceGit.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Toggle One-Side/Two-Sides.
/// </summary>
public static string Text_Diff_Mode {
get {
return ResourceManager.GetString("Text.Diff.Mode", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Next Difference. /// Looks up a localized string similar to Next Difference.
/// </summary> /// </summary>
@ -1284,6 +1275,15 @@ namespace SourceGit.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Toggle Side-By-Side Diff.
/// </summary>
public static string Text_Diff_SideBySide {
get {
return ResourceManager.GetString("Text.Diff.SideBySide", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Open With Merge Tool. /// Looks up a localized string similar to Open With Merge Tool.
/// </summary> /// </summary>

View file

@ -657,8 +657,8 @@
<data xml:space="preserve" name="Text.Diff.Prev"> <data xml:space="preserve" name="Text.Diff.Prev">
<value>Previous Difference</value> <value>Previous Difference</value>
</data> </data>
<data xml:space="preserve" name="Text.Diff.Mode"> <data xml:space="preserve" name="Text.Diff.SideBySide">
<value>Toggle One-Side/Two-Sides</value> <value>Side-By-Side Diff</value>
</data> </data>
<data xml:space="preserve" name="Text.Diff.UseMerger"> <data xml:space="preserve" name="Text.Diff.UseMerger">
<value>Open With Merge Tool</value> <value>Open With Merge Tool</value>

View file

@ -657,8 +657,8 @@
<data xml:space="preserve" name="Text.Diff.Prev"> <data xml:space="preserve" name="Text.Diff.Prev">
<value>Previous Difference</value> <value>Previous Difference</value>
</data> </data>
<data xml:space="preserve" name="Text.Diff.Mode"> <data xml:space="preserve" name="Text.Diff.SideBySide">
<value>Toggle One-Side/Two-Sides</value> <value>Toggle Side-By-Side Diff</value>
</data> </data>
<data xml:space="preserve" name="Text.Diff.UseMerger"> <data xml:space="preserve" name="Text.Diff.UseMerger">
<value>Open With Merge Tool</value> <value>Open With Merge Tool</value>

View file

@ -657,8 +657,8 @@
<data xml:space="preserve" name="Text.Diff.Prev"> <data xml:space="preserve" name="Text.Diff.Prev">
<value>上一个差异</value> <value>上一个差异</value>
</data> </data>
<data xml:space="preserve" name="Text.Diff.Mode"> <data xml:space="preserve" name="Text.Diff.SideBySide">
<value>切换显示模式</value> <value>分列对比</value>
</data> </data>
<data xml:space="preserve" name="Text.Diff.UseMerger"> <data xml:space="preserve" name="Text.Diff.UseMerger">
<value>使用外部合并工具查看</value> <value>使用外部合并工具查看</value>

View file

@ -955,37 +955,21 @@
<Setter Property="Opacity" Value="1"/> <Setter Property="Opacity" Value="1"/>
</Style> </Style>
<Style Selector="ToggleButton.textdiffviewer_mode"> <Style Selector="ToggleButton.line_path">
<Setter Property="Margin" Value="0"/> <Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/> <Setter Property="Padding" Value="0"/>
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Template">
<ControlTemplate>
<Border Background="Transparent">
<Path Grid.Column="0"
x:Name="PART_IndicatorIcon"
Margin="{TemplateBinding Padding}"
Stretch="Fill"
Data="{StaticResource Icons.Orientation}"
Fill="{DynamicResource Brush.FG1}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Opacity=".8"
RenderTransformOrigin="50%,50%"
RenderTransform="rotate(90deg)"/>
</Border>
</ControlTemplate>
</Setter>
</Style> </Style>
<Style Selector="ToggleButton.textdiffviewer_mode:pressed"> <Style Selector="ToggleButton.line_path:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="RenderTransform" Value="scale(1)"/> <Setter Property="Background" Value="Transparent"/>
</Style> </Style>
<Style Selector="ToggleButton.textdiffviewer_mode:checked /template/ Path#PART_IndicatorIcon"> <Style Selector="ToggleButton.line_path:checked /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="RenderTransform" Value="rotate(0deg)"/> <Setter Property="Background" Value="Transparent"/>
</Style> </Style>
<Style Selector="ToggleButton.textdiffviewer_mode:pointerover /template/ Path#PART_IndicatorIcon"> <Style Selector="ToggleButton.line_path:checked Path">
<Setter Property="Opacity" Value="1"/> <Setter Property="Fill" Value="{DynamicResource Brush.Accent1}"/>
</Style> </Style>
<Style Selector="ToggleButton.toggle_untracked"> <Style Selector="ToggleButton.toggle_untracked">

View file

@ -108,10 +108,10 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _useTwoColumnsLayoutInHistories, value); set => SetProperty(ref _useTwoColumnsLayoutInHistories, value);
} }
public bool UseCombinedTextDiff public bool UseSideBySideDiff
{ {
get => _useCombinedTextDiff; get => _useSideBySideDiff;
set => SetProperty(ref _useCombinedTextDiff, value); set => SetProperty(ref _useSideBySideDiff, value);
} }
public Models.ChangeViewMode UnstagedChangeViewMode public Models.ChangeViewMode UnstagedChangeViewMode
@ -350,7 +350,7 @@ namespace SourceGit.ViewModels
private bool _restoreTabs = false; private bool _restoreTabs = false;
private bool _useFixedTabWidth = true; private bool _useFixedTabWidth = true;
private bool _useTwoColumnsLayoutInHistories = false; private bool _useTwoColumnsLayoutInHistories = false;
private bool _useCombinedTextDiff = true; private bool _useSideBySideDiff = false;
private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List; private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List;
private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List; private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List;

View file

@ -27,14 +27,17 @@
</StackPanel> </StackPanel>
<StackPanel Grid.Column="2" Margin="32,0,0,0" Orientation="Horizontal" IsVisible="{Binding IsTextDiff}" VerticalAlignment="Center"> <StackPanel Grid.Column="2" Margin="32,0,0,0" Orientation="Horizontal" IsVisible="{Binding IsTextDiff}" VerticalAlignment="Center">
<ToggleButton x:Name="toggleDisplayMode" <ToggleButton Classes="line_path"
Classes="textdiffviewer_mode" Width="32" Height="18"
Width="32" Height="26" Background="Transparent"
Padding="9,6" Padding="9,6"
IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseCombinedTextDiff, Mode=TwoWay}" IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}"
ToolTip.Tip="{DynamicResource Text.Diff.Mode}"/> ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}">
<Path Width="12" Height="12" Data="{StaticResource Icons.SideBySide}"/>
</ToggleButton>
<Button Classes="icon_button" Width="32" Command="{Binding OpenExternalMergeTool}" ToolTip.Tip="{DynamicResource Text.Diff.UseMerger}"> <Button Classes="icon_button" Width="32" Command="{Binding OpenExternalMergeTool}" ToolTip.Tip="{DynamicResource Text.Diff.UseMerger}">
<Path Width="14" Height="14" Stretch="Uniform" Data="{StaticResource Icons.OpenWith}"/> <Path Width="12" Height="12" Stretch="Uniform" Data="{StaticResource Icons.OpenWith}"/>
</Button> </Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
@ -111,7 +114,7 @@
<!-- Text Diff --> <!-- Text Diff -->
<DataTemplate DataType="m:TextDiff"> <DataTemplate DataType="m:TextDiff">
<v:TextDiffView TextDiff="{Binding}" UseCombined="{Binding #toggleDisplayMode.IsChecked}"/> <v:TextDiffView TextDiff="{Binding}" UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
</ContentControl> </ContentControl>

View file

@ -790,13 +790,13 @@ namespace SourceGit.Views
set => SetValue(TextDiffProperty, value); set => SetValue(TextDiffProperty, value);
} }
public static readonly StyledProperty<bool> UseCombinedProperty = public static readonly StyledProperty<bool> UseSideBySideDiffProperty =
AvaloniaProperty.Register<TextDiffView, bool>(nameof(UseCombined), false); AvaloniaProperty.Register<TextDiffView, bool>(nameof(UseSideBySideDiff), false);
public bool UseCombined public bool UseSideBySideDiff
{ {
get => GetValue(UseCombinedProperty); get => GetValue(UseSideBySideDiffProperty);
set => SetValue(UseCombinedProperty, value); set => SetValue(UseSideBySideDiffProperty, value);
} }
public TextDiffView() public TextDiffView()
@ -903,7 +903,7 @@ namespace SourceGit.Views
{ {
TextDiff.GenerateNewPatchFromSelection(change, null, selection, false, tmpFile); TextDiff.GenerateNewPatchFromSelection(change, null, selection, false, tmpFile);
} }
else if (UseCombined) else if (!UseSideBySideDiff)
{ {
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result(); var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, false, tmpFile); TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, false, tmpFile);
@ -935,7 +935,7 @@ namespace SourceGit.Views
{ {
TextDiff.GenerateNewPatchFromSelection(change, null, selection, true, tmpFile); TextDiff.GenerateNewPatchFromSelection(change, null, selection, true, tmpFile);
} }
else if (UseCombined) else if (!UseSideBySideDiff)
{ {
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result(); var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile); TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile);
@ -973,7 +973,7 @@ namespace SourceGit.Views
{ {
TextDiff.GenerateNewPatchFromSelection(change, treeGuid, selection, true, tmpFile); TextDiff.GenerateNewPatchFromSelection(change, treeGuid, selection, true, tmpFile);
} }
else if (UseCombined) else if (!UseSideBySideDiff)
{ {
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile); TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile);
} }
@ -1003,7 +1003,7 @@ namespace SourceGit.Views
{ {
TextDiff.GenerateNewPatchFromSelection(change, null, selection, true, tmpFile); TextDiff.GenerateNewPatchFromSelection(change, null, selection, true, tmpFile);
} }
else if (UseCombined) else if (!UseSideBySideDiff)
{ {
var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result(); var treeGuid = new Commands.QueryStagedFileBlobGuid(ctx.RepositoryPath, change.Path).Result();
TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile); TextDiff.GeneratePatchFromSelection(change, treeGuid, selection, true, tmpFile);
@ -1034,19 +1034,19 @@ namespace SourceGit.Views
{ {
base.OnPropertyChanged(change); base.OnPropertyChanged(change);
if (change.Property == TextDiffProperty || change.Property == UseCombinedProperty) if (change.Property == TextDiffProperty || change.Property == UseSideBySideDiffProperty)
{ {
if (TextDiff == null) if (TextDiff == null)
{ {
Content = null; Content = null;
} }
else if (UseCombined) else if (UseSideBySideDiff)
{ {
Content = TextDiff; Content = new ViewModels.TwoSideTextDiff(TextDiff);
} }
else else
{ {
Content = new ViewModels.TwoSideTextDiff(TextDiff); Content = TextDiff;
} }
} }
} }
@ -1115,7 +1115,7 @@ namespace SourceGit.Views
var line = diff.Lines[i]; var line = diff.Lines[i];
if (line.Type == Models.TextDiffLineType.Added) if (line.Type == Models.TextDiffLineType.Added)
{ {
if (UseCombined) if (!UseSideBySideDiff)
{ {
rs.HasChanges = true; rs.HasChanges = true;
break; break;
@ -1131,7 +1131,7 @@ namespace SourceGit.Views
} }
else if (line.Type == Models.TextDiffLineType.Deleted) else if (line.Type == Models.TextDiffLineType.Deleted)
{ {
if (UseCombined) if (!UseSideBySideDiff)
{ {
rs.HasChanges = true; rs.HasChanges = true;
break; break;